K
- key typeV
- value typepublic class MapWithOrdinal<K,V> extends Object implements Map<K,V>
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.コンストラクタと説明 |
---|
MapWithOrdinal() |
修飾子とタイプ | メソッドと説明 |
---|---|
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<K,V>> |
entrySet() |
V |
get(Object 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() |
List<K> |
keyList() |
Set<K> |
keySet() |
V |
put(K key,
V value)
Inserts the tuple (key, value) into the map extending the semantics of
Map.put(K, V) with automatic ordinal
assignment. |
void |
putAll(Map<? extends K,? extends V> m) |
V |
remove(Object key)
Removes the element corresponding to the key if exists extending the semantics of
Map.remove(java.lang.Object)
with ordinal re-cycling. |
int |
size() |
Collection<V> |
values() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
public V getByOrdinal(int id)
id
- ordinal value for lookuppublic int getOrdinal(K key)
key
- key for ordinal lookuppublic V put(K key, V value)
Map.put(K, V)
with automatic ordinal
assignment. A new ordinal is assigned if key does not exists. Otherwise the same ordinal is re-used but the value
is replaced.put
インタフェース内 Map<K,V>
Map.put(K, V)
public boolean containsKey(Object key)
containsKey
インタフェース内 Map<K,V>
public boolean containsValue(Object value)
containsValue
インタフェース内 Map<K,V>
public V remove(Object key)
Map.remove(java.lang.Object)
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.remove
インタフェース内 Map<K,V>
Map.remove(java.lang.Object)
Copyright © 2018 The Apache Software Foundation. All rights reserved.