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). The
Map.entrySet
method 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.
These ImmutableMap.ImmutableEntry
objects 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 the setValue
operation on the map entry.-
Constructor Summary
Constructors Constructor Description ImmutableEntry(Map.Entry<K,V> wrappedEntry)
-
Method Summary
Modifier and Type Method Description static <K extends Comparable<? super K>, V>
Comparator<ImmutableMap.ImmutableEntry<K,V>>comparingByKey()
Returns a comparator that comparesImmutableMap.ImmutableEntry
in natural order on key.static <K, V> Comparator<ImmutableMap.ImmutableEntry<K,V>>
comparingByKey(Comparator<? super K> cmp)
Returns a comparator that comparesImmutableMap.ImmutableEntry
by key using the givenComparator
.static <K, V extends Comparable<? super V>>
Comparator<ImmutableMap.ImmutableEntry<K,V>>comparingByValue()
Returns a comparator that comparesImmutableMap.ImmutableEntry
in natural order on value.static <K, V> Comparator<ImmutableMap.ImmutableEntry<K,V>>
comparingByValue(Comparator<? super V> cmp)
Returns a comparator that comparesImmutableMap.ImmutableEntry
by value using the givenComparator
.boolean
equals(Object obj)
K
getKey()
Returns the key corresponding to this entry.V
getValue()
Returns the value corresponding to this entry.int
hashCode()
String
toString()
-
Constructor Details
-
ImmutableEntry
- Parameters:
wrappedEntry
- the wrapped entry
-
-
Method Details
-
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
Returns the value corresponding to this entry. If the mapping has been removed from the backing map (by the iterator'sremove
operation), 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.
-
hashCode
public int hashCode() -
equals
-
comparingByKey
public static <K extends Comparable<? super K>, V> Comparator<ImmutableMap.ImmutableEntry<K,V>> comparingByKey()Returns a comparator that comparesImmutableMap.ImmutableEntry
in natural order on key.The returned comparator is serializable and throws
NullPointerException
when comparing an entry with a null key.- Type Parameters:
K
- theComparable
type of then map keysV
- the type of the map values- Returns:
- a comparator that compares
ImmutableMap.ImmutableEntry
in 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.ImmutableEntry
in natural order on value.The returned comparator is serializable and throws
NullPointerException
when comparing an entry with null values.- Type Parameters:
K
- the type of the map keysV
- theComparable
type of the map values- Returns:
- a comparator that compares
ImmutableMap.ImmutableEntry
in 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.ImmutableEntry
by 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
- the keyComparator
- Returns:
- a comparator that compares
ImmutableMap.ImmutableEntry
by 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.ImmutableEntry
by 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
- the valueComparator
- Returns:
- a comparator that compares
ImmutableMap.ImmutableEntry
by the value. - Since:
- 1.8
-
toString
-