Package org.djutils.immutablecollections
Class ImmutableMap.ImmutableEntry<K,V>
- java.lang.Object
-
- org.djutils.immutablecollections.ImmutableMap.ImmutableEntry<K,V>
-
- Type Parameters:
K- keyV- value
- Enclosing interface:
- ImmutableMap<K,V>
public static class ImmutableMap.ImmutableEntry<K,V> extends Object
A map entry (key-value pair). TheMap.entrySetmethod returns a collection-view of the map, whose elements are of this class. The only way to obtain a reference to a map entry is from the iterator of this collection-view. TheseImmutableMap.ImmutableEntryobjects are valid only for the duration of the iteration; more formally, the behavior of a map entry is undefined if the backing map has been modified after the entry was returned by the iterator, except through thesetValueoperation on the map entry.
-
-
Constructor Summary
Constructors Constructor Description ImmutableEntry(Map.Entry<K,V> wrappedEntry)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <K extends Comparable<? super K>,V>
Comparator<ImmutableMap.ImmutableEntry<K,V>>comparingByKey()Returns a comparator that comparesImmutableMap.ImmutableEntryin natural order on key.static <K,V>
Comparator<ImmutableMap.ImmutableEntry<K,V>>comparingByKey(Comparator<? super K> cmp)Returns a comparator that comparesImmutableMap.ImmutableEntryby key using the givenComparator.static <K,V extends Comparable<? super V>>
Comparator<ImmutableMap.ImmutableEntry<K,V>>comparingByValue()Returns a comparator that comparesImmutableMap.ImmutableEntryin natural order on value.static <K,V>
Comparator<ImmutableMap.ImmutableEntry<K,V>>comparingByValue(Comparator<? super V> cmp)Returns a comparator that comparesImmutableMap.ImmutableEntryby value using the givenComparator.booleanequals(Object obj)KgetKey()Returns the key corresponding to this entry.VgetValue()Returns the value corresponding to this entry.inthashCode()StringtoString()
-
-
-
Method Detail
-
getKey
public K getKey()
Returns the key corresponding to this entry.- Returns:
- the key corresponding to this entry
- Throws:
IllegalStateException- implementations may, but are not required to, throw this exception if the entry has been removed from the backing map.
-
getValue
public V getValue()
Returns the value corresponding to this entry. If the mapping has been removed from the backing map (by the iterator'sremoveoperation), the results of this call are undefined.- Returns:
- the value corresponding to this entry
- Throws:
IllegalStateException- implementations may, but are not required to, throw this exception if the entry has been removed from the backing map.
-
comparingByKey
public static <K extends Comparable<? super K>,V> Comparator<ImmutableMap.ImmutableEntry<K,V>> comparingByKey()
Returns a comparator that comparesImmutableMap.ImmutableEntryin natural order on key.The returned comparator is serializable and throws
NullPointerExceptionwhen comparing an entry with a null key.- Type Parameters:
K- theComparabletype of then map keysV- the type of the map values- Returns:
- a comparator that compares
ImmutableMap.ImmutableEntryin natural order on key. - Since:
- 1.8
- See Also:
Comparable
-
comparingByValue
public static <K,V extends Comparable<? super V>> Comparator<ImmutableMap.ImmutableEntry<K,V>> comparingByValue()
Returns a comparator that comparesImmutableMap.ImmutableEntryin natural order on value.The returned comparator is serializable and throws
NullPointerExceptionwhen comparing an entry with null values.- Type Parameters:
K- the type of the map keysV- theComparabletype of the map values- Returns:
- a comparator that compares
ImmutableMap.ImmutableEntryin natural order on value. - Since:
- 1.8
- See Also:
Comparable
-
comparingByKey
public static <K,V> Comparator<ImmutableMap.ImmutableEntry<K,V>> comparingByKey(Comparator<? super K> cmp)
Returns a comparator that comparesImmutableMap.ImmutableEntryby key using the givenComparator.The returned comparator is serializable if the specified comparator is also serializable.
- Type Parameters:
K- the type of the map keysV- the type of the map values- Parameters:
cmp- Comparator<? super K>; the keyComparator- Returns:
- a comparator that compares
ImmutableMap.ImmutableEntryby the key. - Since:
- 1.8
-
comparingByValue
public static <K,V> Comparator<ImmutableMap.ImmutableEntry<K,V>> comparingByValue(Comparator<? super V> cmp)
Returns a comparator that comparesImmutableMap.ImmutableEntryby value using the givenComparator.The returned comparator is serializable if the specified comparator is also serializable.
- Type Parameters:
K- the type of the map keysV- the type of the map values- Parameters:
cmp- Comparator<? super V>; the valueComparator- Returns:
- a comparator that compares
ImmutableMap.ImmutableEntryby the value. - Since:
- 1.8
-
-