I know that this topic can be well covered, but they only use a Treemap which use only one value and in case of same value does not return what I would like.
Here is my object:
public classe myObjectToMap
{
long id;
double price;
String name;
long date;
public static void GetMyObject(long id, double price, String name)
{
myObjectToMap newObject = new myObjectToMap;
newObject.id = id;
newObject.price = price;
newObject.name = name;
newObject.date = new Date().getTime();
PlaceOfMyMap.myMap.put(id, newObject);
}
Here is where my map is located, I put a LinkedHashMap, and I do not which is the best between Hashmap, TreeMap and LinkedHashMap, I did see that TreeMap give a comparator of Value, but I do not arrive to Compare with more than one value.
public class PlaceOfMyMap
{
public static LinkedHashmap<Long, myObjectToMap> myMap = new LinkedHashmap<~>;
}
And finally, here is my main program:
public class MainClass
{
public static void main(String args[]) throws Exception
{
MyObjectToHashmap.GetMyObject(1, 26, "Mat")
MyObjectToHashmap.GetMyObject(4, 25, "Tommy")
MyObjectToHashmap.GetMyObject(16, 24, "Kate")
MyObjectToHashmap.GetMyObject(63, 26, "Mary")
MyObjectToHashmap.GetMyObject(99, 24, "Ronny")
}
}
First: I would like to sort them from the highest price to the lowest with a time priority, which means that I would like to Mat being the first and Kate the second.
Second: I would like to sort them from the Lowest price to the the Highest with a time priority which means that I would like to Kate being the first and Ronny the second.
Any tips to sort them correctly ?