I have a Map
of type <String, List<Object>>
where the keys of this Map
are names (String
) associated with an Object
that contains X and Y coordinates.
Example:
Names (String) Coordinates
Cord1 [[0.1,0.1,0.1],[0.2,0.3,0.4]]
Cord1,Cord2 [[0.1,0.1] ,[0.4,0.5]]
Cord1,Cord2,Cord3 [[0.1,0.1] ,[0.6,0.7]]
What I want to achieve is to split the names when there is a comma ,
so I can have only single names, which will also affect the coordinates and avoid repetition.
Example of what I would like to achieve:
Cord1 [[0.1,0.1,0.1,0.1,0.1,0.1],[0.2,0.3,0.4,0.5,0.6,0.7]]
Cord2 [[0.01,0.01,0.01,0.01] ,[0.4,0.5,0.6,0.7]]
Cord3 [[0.01,0.01] ,[0.6,0.7]]
Is there a way to do this?
EDIT:
I am not very familiar with Java 8 which apparently is the most optimal way to do it, but I was experimenting with something along these lines which has not worked so far:
List<String> list = Splitter.on(',').splitToList(value);
for (String element : list) {
//TO-DO
}
Cord Object:
public class Cord {
private double X;
private double Y;
private String name;
public Cord(double x, double y, String name) {
this.X=x;
this.Y=y;
this.name=name;
}
@Override
public String toString() {
return "["+X+","+Y+"]";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getX() {
return X;
}
public void setX(double x) {
X = x;
}
public double getY() {
return Y;
}
public void setY(double y) {
Y = y;
}
}