K
- key typeV
- value typepublic class MultiMapWithOrdinal<K,V> extends Object implements 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 and Description |
---|
MultiMapWithOrdinal() |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
containsKey(K key) |
V |
get(K key)
get set of values for key.
|
Collection<V> |
getAll(K key)
get set of values for key.
|
V |
getByOrdinal(int id)
Returns the value corresponding to the given ordinal.
|
int |
getOrdinal(K key)
Returns the ordinal corresponding to the given key.
|
boolean |
isEmpty() |
Set<K> |
keys() |
boolean |
put(K key,
V value,
boolean overwrite)
Inserts the tuple (key, value) into the multimap with automatic ordinal assignment.
|
boolean |
remove(K key,
V value)
Removes the element corresponding to the key/value if exists with ordinal re-cycling.
|
boolean |
removeAll(K key)
remove all entries of key.
|
int |
size() |
Collection<V> |
values() |
public V getByOrdinal(int id)
getByOrdinal
in interface MapWithOrdinal<K,V>
id
- ordinal value for lookuppublic int getOrdinal(K key)
getOrdinal
in interface MapWithOrdinal<K,V>
key
- key for ordinal lookuppublic int size()
size
in interface MapWithOrdinal<K,V>
public boolean isEmpty()
isEmpty
in interface MapWithOrdinal<K,V>
public V get(K key)
get
in interface MapWithOrdinal<K,V>
public Collection<V> getAll(K key)
getAll
in interface MapWithOrdinal<K,V>
public boolean put(K key, V value, boolean overwrite)
put
in interface MapWithOrdinal<K,V>
public Collection<V> values()
values
in interface MapWithOrdinal<K,V>
public boolean containsKey(K key)
containsKey
in interface MapWithOrdinal<K,V>
public boolean remove(K key, V value)
getOrdinal(Object)
before attempting to look-up by ordinal.
If the multimap is changed return true.remove
in interface MapWithOrdinal<K,V>
public boolean removeAll(K key)
removeAll
in interface MapWithOrdinal<K,V>
public void clear()
clear
in interface MapWithOrdinal<K,V>
Copyright © 2024 The Apache Software Foundation. All rights reserved.