Package 

Class SimpleArrayMap


  • 
    public class SimpleArrayMap<K, V>
    
                        

    Base implementation of ArrayMap that doesn't include any standard Java container API interoperability. These features are generally heavier-weight ways to interact with the container, so discouraged, but they can be useful to make it easier to use as a drop-in replacement for HashMap. If you don't need them, this class can be preferrable since it doesn't bring in any of the implementation of those APIs, allowing that code to be stripped by ProGuard.

    • Method Summary

      Modifier and Type Method Description
      void clear() Make the array map empty.
      void ensureCapacity(int minimumCapacity) Ensure the array map can hold at least minimumCapacityitems.
      boolean containsKey(@Nullable() Object key) Check whether a key exists in the array.
      int indexOfKey(@Nullable() Object key) Returns the index of a key in the set.
      boolean containsValue(Object value) Check whether a value exists in the array.
      V get(Object key) Retrieve a value from the array.
      V getOrDefault(Object key, V defaultValue) Retrieve a value from the array, or {@code defaultValue} if there is no mapping for the key.
      K keyAt(int index) Return the key at the given index in the array.
      V valueAt(int index) Return the value at the given index in the array.
      V setValueAt(int index, V value) Set the value at a given index in the array.
      boolean isEmpty() Return true if the array map contains no items.
      V put(K key, V value) Add a new value to the array map.
      void putAll(@NonNull() SimpleArrayMap<out K, out V> array) Perform a put of all key/value pairs in array
      V putIfAbsent(K key, V value) Add a new value to the array map only if the key does not already have a value or it ismapped to {@code null}.
      V remove(Object key) Remove an existing key from the array map.
      boolean remove(Object key, Object value) Remove an existing key from the array map only if it is currently mapped to {@code value}.
      V removeAt(int index) Remove the key/value mapping at the given index.
      V replace(K key, V value) Replace the mapping for {@code key} only if it is already mapped to a value.
      boolean replace(K key, V oldValue, V newValue) Replace the mapping for {@code key} only if it is already mapped to a value.
      int size() Return the number of items in this array map.
      boolean equals(Object object) This implementation returns false if the object is not a Map orSimpleArrayMap, or if the maps have different sizes.
      int hashCode()
      String toString() This implementation composes a string by iterating over its mappings.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SimpleArrayMap

        SimpleArrayMap()
        Create a new empty ArrayMap.
      • SimpleArrayMap

        SimpleArrayMap(int capacity)
        Create a new ArrayMap with a given initial capacity.
      • SimpleArrayMap

        SimpleArrayMap(SimpleArrayMap<K, V> map)
        Create a new ArrayMap with the mappings from the given ArrayMap.
    • Method Detail

      • clear

         void clear()

        Make the array map empty. All storage is released.

      • ensureCapacity

         void ensureCapacity(int minimumCapacity)

        Ensure the array map can hold at least minimumCapacityitems.

      • containsKey

         boolean containsKey(@Nullable() Object key)

        Check whether a key exists in the array.

        Parameters:
        key - The key to search for.
      • indexOfKey

         int indexOfKey(@Nullable() Object key)

        Returns the index of a key in the set.

        Parameters:
        key - The key to search for.
      • containsValue

         boolean containsValue(Object value)

        Check whether a value exists in the array. This requires a linear searchthrough the entire array.

        Parameters:
        value - The value to search for.
      • get

        @Nullable() V get(Object key)

        Retrieve a value from the array.

        Parameters:
        key - The key of the value to retrieve.
      • getOrDefault

         V getOrDefault(Object key, V defaultValue)

        Retrieve a value from the array, or {@code defaultValue} if there is no mapping for the key.

        Parameters:
        key - The key of the value to retrieve.
        defaultValue - The default mapping of the key
      • keyAt

         K keyAt(int index)

        Return the key at the given index in the array.

        Parameters:
        index - The desired index, must be between 0 and size-1.
      • valueAt

         V valueAt(int index)

        Return the value at the given index in the array.

        Parameters:
        index - The desired index, must be between 0 and size-1.
      • setValueAt

         V setValueAt(int index, V value)

        Set the value at a given index in the array.

        Parameters:
        index - The desired index, must be between 0 and size-1.
        value - The new value to store at this index.
      • isEmpty

         boolean isEmpty()

        Return true if the array map contains no items.

      • put

        @Nullable() V put(K key, V value)

        Add a new value to the array map.

        Parameters:
        key - The key under which to store the value.
        value - The value to store for the given key.
      • putAll

         void putAll(@NonNull() SimpleArrayMap<out K, out V> array)

        Perform a put of all key/value pairs in array

        Parameters:
        array - The array whose contents are to be retrieved.
      • putIfAbsent

        @Nullable() V putIfAbsent(K key, V value)

        Add a new value to the array map only if the key does not already have a value or it ismapped to {@code null}.

        Parameters:
        key - The key under which to store the value.
        value - The value to store for the given key.
      • remove

        @Nullable() V remove(Object key)

        Remove an existing key from the array map.

        Parameters:
        key - The key of the mapping to remove.
      • remove

         boolean remove(Object key, Object value)

        Remove an existing key from the array map only if it is currently mapped to {@code value}.

        Parameters:
        key - The key of the mapping to remove.
        value - The value expected to be mapped to the key.
      • removeAt

         V removeAt(int index)

        Remove the key/value mapping at the given index.

        Parameters:
        index - The desired index, must be between 0 and size-1.
      • replace

        @Nullable() V replace(K key, V value)

        Replace the mapping for {@code key} only if it is already mapped to a value.

        Parameters:
        key - The key of the mapping to replace.
        value - The value to store for the given key.
      • replace

         boolean replace(K key, V oldValue, V newValue)

        Replace the mapping for {@code key} only if it is already mapped to a value.

        Parameters:
        key - The key of the mapping to replace.
        oldValue - The value expected to be mapped to the key.
        newValue - The value to store for the given key.
      • size

         int size()

        Return the number of items in this array map.

      • equals

         boolean equals(Object object)

        This implementation returns false if the object is not a Map orSimpleArrayMap, or if the maps have different sizes. Otherwise, for eachkey in this map, values of both maps are compared. If the values for anykey are not equal, the method returns false, otherwise it returns true.

      • toString

         String toString()

        This implementation composes a string by iterating over its mappings. Ifthis map contains itself as a key or a value, the string "(this Map)"will appear in its place.