K
- key typeV
- value typepublic class TraversableHashMap<K,V> extends Object implements Map<K,V>
LinkedHashMap
, with the additional
accessor methods for successor and predecessor keys.
To get the keys following and preceding k
in the map, use
getSuccessorOf(Object)
and getPredecessorOf(Object)
, respectively.
In order to access the first and last keys in the traversal orders, use getFirstKey()
and getLastKey()
.
Constructor and Description |
---|
TraversableHashMap()
Constructs a new empty map.
|
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<K,V>> |
entrySet() |
V |
get(Object key) |
K |
getFirstKey()
Returns the first key in the traversal order.
|
K |
getLastKey()
Returns the last key in the traversal order.
|
K |
getPredecessorOf(K key)
Returns the key preceding
key in the traversal order, or null if
key is the first key in the traversal order. |
K |
getSuccessorOf(K key)
Returns the key following
key in the traversal order, or null if
key is the last key in the traversal order. |
boolean |
isEmpty() |
Set<K> |
keySet() |
V |
put(K key,
V value) |
void |
putAll(Map<? extends K,? extends V> m) |
V |
remove(Object key) |
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 boolean containsKey(Object key)
containsKey
in interface Map<K,V>
public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
public K getFirstKey()
null
if the map is emptypublic K getLastKey()
null
if the map is emptypublic K getSuccessorOf(K key)
key
in the traversal order, or null
if
key
is the last key in the traversal order.key
- the key to find the successor of, must not be null
key
, or null
if key
is the last keyNullPointerException
- if key
is null
NoSuchElementException
- if the map does not associate any value to key
public K getPredecessorOf(K key)
key
in the traversal order, or null
if
key
is the first key in the traversal order.key
- the key to find the predecessor of, must not be null
key
, or null
if key
is the last keyNullPointerException
- if key
is null
NoSuchElementException
- if the map does not associate any value to key
Copyright © 2016. All rights reserved.