java - Does this Map-like structure exist as part of some standard Collection? -
i'm looking map construction behave this
public mapbiggest<k,v implements comparable> extends map<k,v implements comparable>{ @override public v put(k key, v value){ t currentvalue = null; // insert in 1 of 2 cases if((currentvalue = this.get(key)) == null || // case1: key isn't in map value.compareto(currentvalue)>0){ // case2: new value > currentvalue homecoming super.put(key,value); } homecoming currentvalue; } } that is, maintain inserting items , there logic (comparator) decides elements kept.
thanks.
(note, none of code has been compiled)
edit #1: set returns v
in java 8, be
map.merge(key, value, (left, right) -> left.compare(right) > 0 ? left : right); java collections map
No comments:
Post a Comment