Class ImmutableOpenMap<KType,VType>

All Implemented Interfaces:

public final class ImmutableOpenMap<KType,VType> extends Object implements Iterable<com.carrotsearch.hppc.cursors.ObjectObjectCursor<KType,VType>>
An immutable map implementation based on open hash map.

Can be constructed using a builder(), or using builder(ImmutableOpenMap) (which is an optimized option to copy over existing content and modify it).

  • Method Details

    • get

      public VType get(KType key)
      Returns the value associated with the given key or the default value for the key type, if the key is not associated with any value.

      Important note: For primitive type values, the value returned for a non-existing key may not be the default value of the primitive type (it may be any value previously assigned to that slot).

    • getOrDefault

      public VType getOrDefault(KType key, VType defaultValue)
      Returns the value associated with the given key or the provided default value if the key is not associated with any value.
    • containsKey

      public boolean containsKey(KType key)
      Returns true if this container has an association to a value for the given key.
    • size

      public int size()
      Returns the current size (number of assigned keys) in the container.
    • isEmpty

      public boolean isEmpty()
      Return true if this hash map contains no assigned keys.
    • iterator

      public Iterator<com.carrotsearch.hppc.cursors.ObjectObjectCursor<KType,VType>> iterator()
      Returns a cursor over the entries (key-value pairs) in this map. The iterator is implemented as a cursor and it returns the same cursor instance on every call to To read the current key and value use the cursor's public fields. An example is shown below.
       for (IntShortCursor c : intShortMap)
           System.out.println("index=" + c.index
             + " key=" + c.key
             + " value=" + c.value);

      The index field inside the cursor gives the internal index inside the container's implementation. The interpretation of this index depends on to the container.

      Specified by:
      iterator in interface Iterable<KType>
    • keys

      public com.carrotsearch.hppc.ObjectLookupContainer<KType> keys()
      Returns a specialized view of the keys of this associated container. The view additionally implements ObjectLookupContainer.
    • keysIt

      public Iterator<KType> keysIt()
      Returns a direct iterator over the keys.
    • keySet

      public Set<KType> keySet()
      Returns a Set view of the keys contained in this map.
    • valuesIt

      public Iterator<VType> valuesIt()
      Returns a direct iterator over the keys.
    • values

      public Collection<VType> values()
      Returns a Collection view of the values contained in the map.
    • stream

      public Stream<Map.Entry<KType,VType>> stream()
      Returns a sequential unordered stream of the map entries.
      a Stream of the map entries as Map.Entry
    • toString

      public String toString()
      toString in class Object
    • equals

      public boolean equals(Object o)
      equals in class Object
    • hashCode

      public int hashCode()
      hashCode in class Object
    • of

      public static <KType, VType> ImmutableOpenMap<KType,VType> of()
    • copyOf

      public static <KType, VType> ImmutableOpenMap<KType,VType> copyOf(com.carrotsearch.hppc.ObjectObjectMap<KType,VType> map)
      An immutable copy of the given map
    • builder

      public static <KType, VType> ImmutableOpenMap.Builder<KType,VType> builder()
    • builder

      public static <KType, VType> ImmutableOpenMap.Builder<KType,VType> builder(int size)
    • builder

      public static <KType, VType> ImmutableOpenMap.Builder<KType,VType> builder(ImmutableOpenMap<KType,VType> map)