Module org.jhotdraw8.icollection
Interface ReadOnlyMap<K,V>
- Type Parameters:
K- the key typeV- the value type
- All Known Subinterfaces:
ImmutableMap<K,,V> ImmutableNavigableMap<K,,V> ImmutableSequencedMap<K,,V> ImmutableSortedMap<K,,V> ReadOnlyNavigableMap<K,,V> ReadOnlySequencedMap<K,,V> ReadOnlySortedMap<K,V>
- All Known Implementing Classes:
org.jhotdraw8.icollection.impl.champ.AbstractMutableChampMap,org.jhotdraw8.icollection.impl.champmap.AbstractMutableChampMap,AbstractReadOnlyMap,ChampMap,ChampVectorMap,ImmutableMapFacade,MutableChampMap,MutableChampVectorMap,MutableRedBlackMap,ReadOnlyMapFacade,ReadOnlyNavigableMapFacade,ReadOnlySequencedMapFacade,ReadOnlySortedMapFacade,RedBlackMap
A read-only interface to a map. A map is an object that maps keys to values.
-
Method Summary
Modifier and TypeMethodDescriptionasMap()Wraps this map in theMapinterface - without copying.default intReturns the spliterator characteristics of the key set.default booleanReturns true if this map contains the specified entry.booleancontainsKey(@Nullable Object key) Returnstrueif this map contains a entry for the specified key.default booleancontainsValue(@Nullable Object value) Returnstrueif this map contains one or more keys to the specified value.booleanCompares the specified object with this map for equality.Returns the value to which the key is mapped, ornullif this map contains no entry for the key.getOrDefault(Object key, @Nullable V defaultValue) Returns the value to which the key is mapped, or the specified default value if this map contains no entry for the key.inthashCode()Returns the hash code value for this map.booleanisEmpty()Returnstrueif this map contains no entries.iterator()Returns an iterator over the entries contained in this map.static <K,V> int iteratorToHashCode(@NonNull Iterator<Map.Entry<K, V>> entries) Returns the hash code of the provided iterable.static <K,V> boolean mapEquals(@NonNull ReadOnlyMap<K, V> map, Object o) Compares a read-only map with an object for equality.mapToString(@NonNull ReadOnlyMap<K, V> map) Returns a string representation of the specified map.default @NonNull ReadOnlySet<Map.Entry<K, V>> Returns aReadOnlySetview to the entries contained in this map.default @NonNull ReadOnlySet<K> Returns aReadOnlySetview to the keys contained in this map.default @NonNull ReadOnlyCollection<V> Returns aReadOnlyCollectionview to the values contained in this map.intsize()Returns the number of entries contained in this map..default @NonNull Spliterator<Map.Entry<K, V>> Returns a spliterator over the entries contained in this map.
-
Method Details
-
isEmpty
boolean isEmpty()Returnstrueif this map contains no entries.- Returns:
trueif empty
-
size
int size()Returns the number of entries contained in this map..- Returns:
- the number of entries
-
get
Returns the value to which the key is mapped, ornullif this map contains no entry for the key.- Parameters:
key- a key- Returns:
- the mapped value or
null
-
getOrDefault
Returns the value to which the key is mapped, or the specified default value if this map contains no entry for the key.- Parameters:
key- a keydefaultValue- a default value- Returns:
- the mapped value or the specified default value
-
containsKey
Returnstrueif this map contains a entry for the specified key.- Parameters:
key- a key- Returns:
trueif this map contains a entry for the specified key
-
containsValue
Returnstrueif this map contains one or more keys to the specified value.- Parameters:
value- a value- Returns:
trueif this map maps one or more keys to the specified value
-
containsEntry
Returns true if this map contains the specified entry.- Parameters:
o- an entry (should be aMap.Entry).- Returns:
- true if this map contains the entry
-
readOnlyEntrySet
Returns aReadOnlySetview to the entries contained in this map.- Returns:
- a read-only view
-
readOnlyKeySet
Returns aReadOnlySetview to the keys contained in this map.- Returns:
- a read-only view
-
readOnlyValues
Returns aReadOnlyCollectionview to the values contained in this map.- Returns:
- a read-only view
-
asMap
Wraps this map in theMapinterface - without copying.- Returns:
- the wrapped map
-
mapToString
Returns a string representation of the specified map.The string representation is consistent with the one produced by
AbstractMap.toString().- Type Parameters:
K- the key typeV- the value type- Parameters:
map- a map- Returns:
- a string representation
-
mapEquals
Compares a read-only map with an object for equality. Returnstrueif the given object is also a read-only map and the two maps represent the same entries.- Type Parameters:
K- the key typeV- the value type- Parameters:
map- a mapo- an object- Returns:
trueif the object is equal to the map
-
iteratorToHashCode
Returns the hash code of the provided iterable. The hash code is the sum of the hash code of the entries.- Type Parameters:
K- the key typeV- the value type- Parameters:
entries- an iterable that is an entry set- Returns:
- the sum of the hash codes of the elements in the set
- See Also:
-
equals
Compares the specified object with this map for equality.Returns
trueif the given object is also a read-only map and the two maps represent the same entries, ignorig the sequence of the map entries. -
hashCode
int hashCode()Returns the hash code value for this map. The hash code is the sum of the hash code of its entries. -
iterator
Returns an iterator over the entries contained in this map. -
spliterator
Returns a spliterator over the entries contained in this map.- Specified by:
spliteratorin interfaceIterable<K>- Returns:
- a spliterator
-
characteristics
default int characteristics()Returns the spliterator characteristics of the key set. This implementation returnsSpliterator.SIZED|Spliterator.DISTINCT.- Returns:
- characteristics.
-