Class AbstractMap<K,V>

java.lang.Object
org.javimmutable.collections.common.AbstractMap<K,V>
All Implemented Interfaces:
Serializable, Iterable<IMapEntry<K,V>>, ICollection<IMapEntry<K,V>>, IMap<K,V>, InvariantCheckable, IStreamable<IMapEntry<K,V>>, Mapped<K,V>, SplitableIterable<IMapEntry<K,V>>
Direct Known Subclasses:
EmptyHashMap, HashMap, OrderedMap, TreeMap

@Immutable public abstract class AbstractMap<K,V> extends Object implements IMap<K,V>
See Also:
  • Constructor Details

    • AbstractMap

      public AbstractMap()
  • Method Details

    • get

      @Nullable public V get(K key)
      Description copied from interface: Mapped
      Return the value associated with key or null if no value is associated. Note that if null is an acceptable value to the container then this method will be ambiguous and find() should be used instead.
      Specified by:
      get in interface Mapped<K,V>
      Parameters:
      key - identifies the value to retrieve
      Returns:
      value associated with key or null if no value is associated
    • insert

      @Nonnull public IMap<K,V> insert(@Nonnull IMapEntry<K,V> e)
      Adds the key/value pair to this map. Any value already existing for the specified key is replaced with the new value.
      Specified by:
      insert in interface ICollection<K>
      Specified by:
      insert in interface IMap<K,V>
    • assignAll

      @Nonnull public IMap<K,V> assignAll(@Nonnull IMap<? extends K,? extends V> map)
      Description copied from interface: IMap
      Copies all key-value pairs from the given map. The map itself and its keys must be nonnull, but values can be null. If a key already has a value in the map, the old value is replaced with the new value. Returns a new IMap with the changes.
      Specified by:
      assignAll in interface IMap<K,V>
      Parameters:
      map - IMap to take values from
      Returns:
      new map reflecting the change
    • assignAll

      @Nonnull public IMap<K,V> assignAll(@Nonnull Map<? extends K,? extends V> map)
      Description copied from interface: IMap
      Copies all key-value pairs from the given map. The map itself and its keys must be nonnull, but values can be null. If a key already has a value in the map, the old value is replaced with the new value. Returns a new IMap with the changes.
      Specified by:
      assignAll in interface IMap<K,V>
      Parameters:
      map - Map to take values from
      Returns:
      new map reflecting the change
    • getMap

      @Nonnull public Map<K,V> getMap()
      Description copied from interface: IMap
      Creates an unmodifiable java.util.Map reflecting the values of this IMap.
      Specified by:
      getMap in interface IMap<K,V>
      Returns:
      Map view of this IMap
    • keys

      @Nonnull public IStreamable<K> keys()
      Description copied from interface: IMap
      Creates an IStreamable to access all of the Map's keys.
      Specified by:
      keys in interface IMap<K,V>
    • values

      @Nonnull public IStreamable<V> values()
      Description copied from interface: IMap
      Creates an IStreamable to access all of the Map's values.
      Specified by:
      values in interface IMap<K,V>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getSpliteratorCharacteristics

      public int getSpliteratorCharacteristics()
      Specified by:
      getSpliteratorCharacteristics in interface IStreamable<K>
      Returns:
      characteristics value used when creating Spliterators
    • select

      @Nonnull public IMap<K,V> select(@Nonnull java.util.function.BiPredicate<K,V> predicate)
      Description copied from interface: IMap
      Returns a map of the same type as this containing only those elements for which predicate returns true. Implementations are optimized assuming predicate will return false more often than true.
      Specified by:
      select in interface IMap<K,V>
      Parameters:
      predicate - decides whether to include an element
      Returns:
      map of same type as this containing only those elements for which predicate returns true
    • reject

      @Nonnull public IMap<K,V> reject(@Nonnull java.util.function.BiPredicate<K,V> predicate)
      Description copied from interface: IMap
      Returns a map of the same type as this containing all those elements for which predicate returns false. Implementations can be optimized assuming predicate will return false more often than true.
      Specified by:
      reject in interface IMap<K,V>
      Parameters:
      predicate - decides whether to include an element
      Returns:
      map of same type as this containing only those elements for which predicate returns false