Reputation:
I am working with mule esb to store data to salesforce cloud. so in that in need to convert following format Latitude,Longitude,Proximity
23.2241356,72.629232,0,
23.2241357,72.629233,5,
23.2241358,72.629234,0,
23.2241359,72.629235,5,
into following format,
{proximity__c=23.2241361, longitude__c=72.629237, latitude__c=5.0},
{proximity__c=23.2241362, longitude__c=72.629238, latitude__c=0.0},
{proximity__c=23.2241363, longitude__c=72.629239, latitude__c=5.0},
{proximity__c=23.2241364, longitude__c=72.62924, latitude__c=0.0},
How to achieve this through java ?
Upvotes: 1
Views: 107
Reputation:
Following is the possible solution.
FileWriter writer = new FileWriter(outPutFile);
br = new BufferedReader(new FileReader(csvFileToRead));
writer.append("[");
while ((line = br.readLine()) != null)
{
String[] products = line.split(splitBy);
writer.append(" {proximity__c= " + products[0] + " , longitude__c="+products[1] +" , latitude__c=" + products[2] + "},");
writer.append("\n");
}
writer.append("]");
writer.flush();
writer.close();
Upvotes: 1
Reputation: 3095
Just keep latitude,longitude and proximity in a collection such as HashMap or ArrayList or in some other thing as Collection of Objects
Just iterate this using for loop while doing iteration just perform basic string concatenation that's enough.
-- Update
public class Geo {
private String lat;
private String long;
private String proximity;
void setLat(String Lat){
lat = Lat;
}
void setLong(String Long){
long = Long;
}
void setProximity(String Proximity){
proximity = Proximity;
}
String getLat(){
return lat;
}
String getLong(){
return long;
}
String getProxmity(){
return proximity;
}
}
HashMap<String, Geo> map = new HashMap<String, Geo>();
Geo g1=new Geo();
//set lat,long,proximity
map.put(“Geo”,g1);
Geo g2=new Geo();
//set lat,long,proximity
map.put(“Geo”,g2);
Create as many objects as you want and add to the Hash
Iterator it = map.entrySet().iterator();
String CSV=“”;
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
Geo g= pair.getValue();
if(CSV.length!=0)
CSV=CSV+”,”
CSV=CSV+“{proximity__c=”+g.getProxmity()+”, longitude__c=”+g.getLong()+”, latitude__c=”+g.getLat());
}
// if(CSV.length!=0)
// CSV = CSV.substring(0, CSV.length()-1);
Upvotes: 0