public class BoundedSortedMultiMap<K,V> extends TreeMultiMap<K,V>
MultiMap
implementation that grows to a fixed size and then retains only
a fixed number of either keys or mappings. All keys used in this class
must implements Comparable
. If an instance is bound by the total number of mappings, a user may configure whether the map arbitrarily removes tied mapping (those with the same key), or whether the tied mappings are removed fairly. While both result in the same size, an arbitrary mapping have a bias in the order of removal based on the element hash distribution. However, a fair removal policy incurs a slightly higher cost based on the number of elements sharing the same key.
BoundedSortedMap
,
Serialized FormConstructor and Description |
---|
BoundedSortedMultiMap(int bound)
Creates an instance that will retain the specified number of mappings
that are associated with the highest keys, using an arbitrary removal
policy.
|
BoundedSortedMultiMap(int bound,
boolean keyBound)
Creates an instance with the specified bound that will retain either the
specified number of highest keys if
keyBound is true , or
the total number of mappings with the highest keys if keyBound is
false . |
BoundedSortedMultiMap(int bound,
boolean keyBound,
boolean retainHighest,
boolean isFair)
Creates an instance with the specified bound that will retain either the
specified number of keys if
keyBound is true , or the
total number of mappings if keyBound is false . |
Modifier and Type | Method and Description |
---|---|
boolean |
put(K key,
V value)
Adds the key-value mapping to this map, and if the total number of
mappings exceeds the bounds, removes either the currently lowest element,
or if reversed, the currently highest element.
|
void |
putAll(Map<? extends K,? extends V> m)
Adds all of the key-value mapping to this map, and if the total number of
mappings exceeds the bounds, removes either the currently lowest element,
or if reversed, the currently highest element.
|
boolean |
putMulti(K key,
Collection<V> values)
Adds all of the key-value mapping to this map, and if the total number of
mappings exceeds the bounds, removes either the currently lowest element,
or if reversed, the currently highest element.
|
asMap, clear, comparator, containsKey, containsMapping, containsValue, entrySet, firstKey, get, headMap, isEmpty, keySet, lastKey, putAll, putMany, range, remove, remove, size, subMap, tailMap, toString, values, valueSets
public BoundedSortedMultiMap(int bound)
bound
- the maximum number of key-value mappings to retainpublic BoundedSortedMultiMap(int bound, boolean keyBound)
keyBound
is true
, or
the total number of mappings with the highest keys if keyBound
is
false
. If keyBound
is false, an arbitrary mapping for
the lowest key will be removed.bound
- the number to retainkeyBound
- true
if the bound should apply to the number of
keys, regardless of the number of values to which those keys map,
or false
if the bound should apply to the total number of
key-value mappings in this mappublic BoundedSortedMultiMap(int bound, boolean keyBound, boolean retainHighest, boolean isFair)
keyBound
is true
, or the
total number of mappings if keyBound
is false
. If retainHighest
is true
, the higest keys will be retained; else
the lowest keys will be be retained. If keyBound
is false, an
the that will be removed will depend on the whether this map fairly
removes tied mappings or arbitrarily removes mappings.bound
- the number to retainkeyBound
- true
if the bound should apply to the number of
keys, regardless of the number of values to which those keys map,
or false
if the bound should apply to the total number of
key-value mappings in this mapretainHighest
- true
if the higest keys should be kept,
false
if the lowest keys should be keptisFair
- if the map is value bound, true
if the map should
pick a random mapping to remove, which ensures fairness, rather
than an arbitrary mapping.public boolean put(K key, V value)
put
operation may result in the range
decreasing, even though the number of keys stays constant.put
in interface MultiMap<K,V>
put
in class TreeMultiMap<K,V>
key
- key with which the specified value is to be associatedvalue
- a value to be associated with the specified keytrue
if the provided value was not already in the set of
value mapped to the specified keypublic boolean putMulti(K key, Collection<V> values)
put
operation may result in the range
decreasing, even though the number of keys stays constant.key
- values
- public void putAll(Map<? extends K,? extends V> m)
put
operation may result in the range
decreasing, even though the number of keys stays constant.Copyright © 2012. All Rights Reserved.