Interface ValueSortedMap<K,V>
-
- Type Parameters:
K
- the type of the keysV
- the type of the values
- All Superinterfaces:
java.util.Map<K,V>
- All Known Implementing Classes:
RestrictedValueSortedMap
,TreeValueSortedMap
public interface ValueSortedMap<K,V> extends java.util.Map<K,V>
A map that is sorted by value.This is an extension of
Map
where entries are sorted by value, rather than by key. Such a map may be useful as a priority queue where the cost of an entry may change over time. As such, the collections returned byentrySet()
,keySet()
, andvalues()
all extendDeque
. The order of the entries will be updated on any call toMap.put(Object, Object)
, or a call toCollection.add(Object)
on the entry set. Additionally, if the values are mutable objects, whose order may change, there is anupdate(Object)
method, which notifies the map that the given key may need to be repositioned. The associated collections also extend theList
interface, providing fairly efficient implementations ofList.get(int)
andList.indexOf(Object)
. Sequential access is best performed viaCollection.iterator()
, since this will use a linked list.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
ValueSortedMap.ValueSortedMapEntryList<K,V>
static interface
ValueSortedMap.ValueSortedMapKeyList<K>
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.Map.Entry<K,V>
ceilingEntryByValue(V value)
Returns a key-value mapping associated with the least value greater than or equal to the given value, ornull
if there is no such value.ValueSortedMap.ValueSortedMapEntryList<K,V>
entrySet()
java.util.Map.Entry<K,V>
floorEntryByValue(V value)
Returns a key-value mapping associated with the greatest value less than or equal to the given value, ornull
if there is no such value.ValueSortedMap<K,V>
headMapByValue(V toValue, boolean inclusive)
Returns a view of the portion of this map whose values are less than (or equal to, ifinclusive
is true)toValue
.java.util.Map.Entry<K,V>
higherEntryByValue(V value)
Returns a key-value mapping associated with the least value strictly greater than the given value, ornull
if there is no such value.ValueSortedMap.ValueSortedMapKeyList<K>
keySet()
java.util.Map.Entry<K,V>
lowerEntryByValue(V value)
Returns a key-value mapping associated with the greatest value strictly less than the given value, ornull
if there is no such value.ValueSortedMap<K,V>
subMapByValue(V fromValue, boolean fromInclusive, V toValue, boolean toInclusive)
Returns a view of the portion of this map whose values range fromfromValue
totoValue
.ValueSortedMap<K,V>
tailMapByValue(V fromValue, boolean inclusive)
Returns a view of the portion of this map whose values are greater than (or equal to, ifinclusive
is true)toValue
.boolean
update(K key)
Notify the map of an external change to the cost of a key's associated valueSortedList<V>
values()
-
-
-
Method Detail
-
entrySet
ValueSortedMap.ValueSortedMapEntryList<K,V> entrySet()
-
lowerEntryByValue
java.util.Map.Entry<K,V> lowerEntryByValue(V value)
Returns a key-value mapping associated with the greatest value strictly less than the given value, ornull
if there is no such value.- Parameters:
value
- the value- Returns:
- the found entry, or
null
-
floorEntryByValue
java.util.Map.Entry<K,V> floorEntryByValue(V value)
Returns a key-value mapping associated with the greatest value less than or equal to the given value, ornull
if there is no such value.- Parameters:
value
- the value- Returns:
- the found entry, or
null
-
ceilingEntryByValue
java.util.Map.Entry<K,V> ceilingEntryByValue(V value)
Returns a key-value mapping associated with the least value greater than or equal to the given value, ornull
if there is no such value.- Parameters:
value
- the value- Returns:
- the found entry, or
null
-
higherEntryByValue
java.util.Map.Entry<K,V> higherEntryByValue(V value)
Returns a key-value mapping associated with the least value strictly greater than the given value, ornull
if there is no such value.- Parameters:
value
- the value- Returns:
- the found entry, or
null
-
subMapByValue
ValueSortedMap<K,V> subMapByValue(V fromValue, boolean fromInclusive, V toValue, boolean toInclusive)
Returns a view of the portion of this map whose values range fromfromValue
totoValue
. The returned map is an unmodifiable view.- Parameters:
fromValue
- low endpoint of the values in the returned mapfromInclusive
-true
if the low endpoint is to be included in the returned viewtoValue
- high endpoint of the values in the returned maptoInclusive
-true
if the high endpoint is to be included in the returned view- Returns:
- the view
-
headMapByValue
ValueSortedMap<K,V> headMapByValue(V toValue, boolean inclusive)
Returns a view of the portion of this map whose values are less than (or equal to, ifinclusive
is true)toValue
. The returned map is an unmodifiable view.- Parameters:
toValue
- high endpoint of the values in the returned mapinclusive
-true
if the high endpoint is to be included in the returned view- Returns:
- the view
-
tailMapByValue
ValueSortedMap<K,V> tailMapByValue(V fromValue, boolean inclusive)
Returns a view of the portion of this map whose values are greater than (or equal to, ifinclusive
is true)toValue
. The returned map is an unmodifiable view.- Parameters:
fromValue
- low endpoint of the values in the returned mapinclusive
-true
if the low endpoint is to be included in the returned view- Returns:
- the view
-
keySet
ValueSortedMap.ValueSortedMapKeyList<K> keySet()
-
update
boolean update(K key)
Notify the map of an external change to the cost of a key's associated valueThis is meant to update the entry's position after a change in cost. The position may not necessarily change, however, if the cost did not change significantly.
- Parameters:
key
- the key whose associated value has changed in cost- Returns:
- true if the entry's position changed
-
values
SortedList<V> values()
-
-