- Type Parameters:
K- key typeV- value type
- All Implemented Interfaces:
MapWithOrdinal<K,V>
This class extends the functionality a regular Map with ordinal lookup support. Upon
insertion an unused ordinal is assigned to the inserted (key, value) tuple. Upon update the same
ordinal id is re-used while value is replaced. Upon deletion of an existing item, its
corresponding ordinal is recycled and could be used by another item.
For any instance with N items, this implementation guarantees that ordinals are in the range
of [0, N). However, the ordinal assignment is dynamic and may change after an insertion or
deletion. Consumers of this class are responsible for explicitly checking the ordinal
corresponding to a key via getOrdinal(Object) before attempting to
execute a lookup with an ordinal.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleancontainsKey(K key) get set of values for key.get set of values for key.getByOrdinal(int id) Returns the value corresponding to the given ordinal.intgetOrdinal(K key) Returns the ordinal corresponding to the given key.booleanisEmpty()keys()booleanInserts the tuple (key, value) into the multimap with automatic ordinal assignment.booleanRemoves the element corresponding to the key/value if exists with ordinal re-cycling.booleanremove all entries of key.intsize()values()
-
Constructor Details
-
MultiMapWithOrdinal
public MultiMapWithOrdinal()
-
-
Method Details
-
getByOrdinal
Returns the value corresponding to the given ordinal.- Specified by:
getByOrdinalin interfaceMapWithOrdinal<K,V> - Parameters:
id- ordinal value for lookup- Returns:
- an instance of V
-
getOrdinal
Returns the ordinal corresponding to the given key.- Specified by:
getOrdinalin interfaceMapWithOrdinal<K,V> - Parameters:
key- key for ordinal lookup- Returns:
- ordinal value corresponding to key if it exists or -1
-
size
public int size()- Specified by:
sizein interfaceMapWithOrdinal<K,V>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceMapWithOrdinal<K,V>
-
get
get set of values for key.- Specified by:
getin interfaceMapWithOrdinal<K,V>
-
getAll
get set of values for key.- Specified by:
getAllin interfaceMapWithOrdinal<K,V>
-
put
Inserts the tuple (key, value) into the multimap with automatic ordinal assignment.A new ordinal is assigned if key/value pair does not exists.
If overwrite is true the existing key will be overwritten with value else value will be appended to the multimap.
- Specified by:
putin interfaceMapWithOrdinal<K,V>
-
values
- Specified by:
valuesin interfaceMapWithOrdinal<K,V>
-
containsKey
- Specified by:
containsKeyin interfaceMapWithOrdinal<K,V>
-
remove
Removes the element corresponding to the key/value if exists with ordinal re-cycling.The ordinal corresponding to the given key may be re-assigned to another tuple. It is important that consumer checks the ordinal value via
getOrdinal(Object)before attempting to look-up by ordinal.If the multimap is changed return true.
- Specified by:
removein interfaceMapWithOrdinal<K,V>
-
removeAll
remove all entries of key.- Specified by:
removeAllin interfaceMapWithOrdinal<K,V>
-
clear
public void clear()- Specified by:
clearin interfaceMapWithOrdinal<K,V>
-
keys
- Specified by:
keysin interfaceMapWithOrdinal<K,V>
-