I need a "Container" for a few objects. Definition:
class DataSet implements Comparable {
public int id;
public String Date;
public double Value
public DataSetFSA (int id, String Date) {
this.id=id;
this.Date=Date;
}
@Override
public int compareTo(Object o) {
return 1;
}
}
The objects have a certain order, which should not be destroyed! As you see my container class already has an "id" itself!
So my question is now should i insert the object as a key or a value into the TreeMap?
DataSet ds1 = new DataSetFSA(1,"Val1");
DataSet ds2 = new DataSetFSA(2,"Val2");
...
TreeMap DataTreeMap = new TreeMap();
DataTreeMap.put(1,ds1); //as value
DataTreeMap.put(2,ds2);
//or as key (then the class has to implement comparable)
DataTreeMap.put(ds1,1); //as key but then the value doesnt has a function anymore
DataTreeMap.put(ds2,2);