Interface ReadOnlyMap<K,V>

Type Parameters:
K - the key type
V - the value type
All Superinterfaces:
Iterable<Map.Entry<K,V>>
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

public interface ReadOnlyMap<K,V> extends Iterable<Map.Entry<K,V>>
A read-only interface to a map. A map is an object that maps keys to values.
  • Method Details

    • isEmpty

      boolean isEmpty()
      Returns true if this map contains no entries.
      Returns:
      true if empty
    • size

      int size()
      Returns the number of entries contained in this map..
      Returns:
      the number of entries
    • get

      @Nullable V get(Object key)
      Returns the value to which the key is mapped, or null if this map contains no entry for the key.
      Parameters:
      key - a key
      Returns:
      the mapped value or null
    • getOrDefault

      default @Nullable V 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.
      Parameters:
      key - a key
      defaultValue - a default value
      Returns:
      the mapped value or the specified default value
    • containsKey

      boolean containsKey(@Nullable Object key)
      Returns true if this map contains a entry for the specified key.
      Parameters:
      key - a key
      Returns:
      true if this map contains a entry for the specified key
    • containsValue

      default boolean containsValue(@Nullable Object value)
      Returns true if this map contains one or more keys to the specified value.
      Parameters:
      value - a value
      Returns:
      true if this map maps one or more keys to the specified value
    • containsEntry

      default boolean containsEntry(Object o)
      Returns true if this map contains the specified entry.
      Parameters:
      o - an entry (should be a Map.Entry).
      Returns:
      true if this map contains the entry
    • readOnlyEntrySet

      default @NonNull ReadOnlySet<Map.Entry<K,V>> readOnlyEntrySet()
      Returns a ReadOnlySet view to the entries contained in this map.
      Returns:
      a read-only view
    • readOnlyKeySet

      default @NonNull ReadOnlySet<K> readOnlyKeySet()
      Returns a ReadOnlySet view to the keys contained in this map.
      Returns:
      a read-only view
    • readOnlyValues

      default @NonNull ReadOnlyCollection<V> readOnlyValues()
      Returns a ReadOnlyCollection view to the values contained in this map.
      Returns:
      a read-only view
    • asMap

      default @NonNull Map<K,V> asMap()
      Wraps this map in the Map interface - without copying.
      Returns:
      the wrapped map
    • mapToString

      static <K, V> @NonNull String mapToString(@NonNull ReadOnlyMap<K,V> map)
      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 type
      V - the value type
      Parameters:
      map - a map
      Returns:
      a string representation
    • mapEquals

      static <K, V> boolean mapEquals(@NonNull ReadOnlyMap<K,V> map, Object o)
      Compares a read-only map with an object for equality. Returns true if the given object is also a read-only map and the two maps represent the same entries.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map - a map
      o - an object
      Returns:
      true if the object is equal to the map
    • iteratorToHashCode

      static <K, V> int iteratorToHashCode(@NonNull Iterator<Map.Entry<K,V>> entries)
      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 type
      V - 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

      boolean equals(Object o)
      Compares the specified object with this map for equality.

      Returns true if the given object is also a read-only map and the two maps represent the same entries, ignorig the sequence of the map entries.

      Overrides:
      equals in class Object
      Parameters:
      o - an object
      Returns:
      true if the object is equal to this map
    • hashCode

      int hashCode()
      Returns the hash code value for this map. The hash code is the sum of the hash code of its entries.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code value for this map
      See Also:
    • iterator

      @NonNull Iterator<Map.Entry<K,V>> iterator()
      Returns an iterator over the entries contained in this map.
      Specified by:
      iterator in interface Iterable<K>
      Returns:
      an iterator
    • spliterator

      default @NonNull Spliterator<Map.Entry<K,V>> spliterator()
      Returns a spliterator over the entries contained in this map.
      Specified by:
      spliterator in interface Iterable<K>
      Returns:
      a spliterator
    • characteristics

      default int characteristics()
      Returns the spliterator characteristics of the key set. This implementation returns Spliterator.SIZED|Spliterator.DISTINCT.
      Returns:
      characteristics.