I need preserve order by value. I wrote some piece of code, but it is not really optimal.
I have a class like this,
class MyClass extends SomeOtherClass {
private Map<Object, Object> resMap= new HashMap<>();
Object getRes(Object key) {
return resMap.get(key);
}
void putRes(Object key, Object value) {
resMap.put(key, value);
}
I want EACH time when I am invoking putRes(Object value) preserve order by value. Something like if value (that I received as an input) > all other values in map then put it first, if the value is equals to some value in map, so put it after it.
Appreciate any help.
upd: I need sort by Value and not by key. upd: I need sort by calling some method getPriority() of value.