Class SynchronizedLinkedMap<K,V>
- Type Parameters:
K- key typeV- value type
"Pseudo" because this class does not implement the map interface, for the primary reason that
iterators on keys/values/items would not abide by the contract requested by Map (mostly,
that modifying the entries while iterating also modifies the backing map). Note that this class
offers a copyOfKeys() method which can safely be used to iterate the keys of the map
at the time that method was executed. Modifying that set does not impact the map itself. Unlike
synchronized maps provided by Collections, there is no
need to synchronize when iterating over the collection returned by copyOfKeys().
Similarly to ConcurrentHashMap (but unlike LinkedHashMap), this class does not
allow null key or null value.
Methods of this object are guaranteed to never raise ConcurrentModificationException.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Remove all mappings.booleancontainsKey(K key) booleancontainsValue(V value) Copy the current keys.Copy the current values.firstKey()booleanisEmpty()Add or replace a mapping.Remove a mapping.intsize()toString()
-
Constructor Details
-
SynchronizedLinkedMap
public SynchronizedLinkedMap()Create an empty synchronized linked map.
-
-
Method Details
-
size
public int size()- Returns:
- number of mappings
-
clear
public void clear()Remove all mappings. -
isEmpty
public boolean isEmpty()- Returns:
- true if no mapping exists
-
containsKey
- Parameters:
key- key- Returns:
- true if the key is present
-
containsValue
- Parameters:
value- value- Returns:
- true if the value is present
-
get
- Parameters:
key- key- Returns:
- value associated with the key, or null
-
put
Add or replace a mapping.- Parameters:
key- non-null keyvalue- non-null value- Returns:
- previous value, or null
-
remove
Remove a mapping.- Parameters:
key- key- Returns:
- removed value, or null
-
copyOfKeys
Copy the current keys.- Returns:
- copy of the key set
-
copyOfValues
Copy the current values.- Returns:
- copy of the values
-
firstKey
- Returns:
- first key in insertion order
- Throws:
NoSuchElementException- if the map is empty
-
toString
-