Class TrieArray<T>

java.lang.Object
org.javimmutable.collections.array.TrieArray<T>
All Implemented Interfaces:
Serializable, Iterable<IMapEntry<Integer,T>>, IArray<T>, ICollection<IMapEntry<Integer,T>>, Indexed<T>, InvariantCheckable, IStreamable<IMapEntry<Integer,T>>, SplitableIterable<IMapEntry<Integer,T>>

public class TrieArray<T> extends Object implements Serializable, IArray<T>
See Also:
  • Method Details

    • of

      @Nonnull public static <T> IArray<T> of()
    • builder

      @Nonnull public static <T> IArrayBuilder<T> builder()
    • collector

      @Nonnull public static <T> java.util.stream.Collector<T,?,IArray<T>> collector()
    • get

      @Nullable public T get(int index)
      Description copied from interface: IArray
      Return the value associated with index 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 IArray<T>
      Specified by:
      get in interface Indexed<T>
      Parameters:
      index - identifies the value to retrieve
      Returns:
      value associated with index or null if no value is associated
    • getValueOr

      public T getValueOr(int index, @Nullable T defaultValue)
      Description copied from interface: IArray
      Return the value associated with index or defaultValue if no value is associated. Note that if defaultValue is an acceptable value to the container then this method will be ambiguous and find() should be used instead.
      Specified by:
      getValueOr in interface IArray<T>
      Parameters:
      index - identifies the value to retrieve
      defaultValue - value to return if no entry exists for index
      Returns:
      value associated with index or defaultValue if no value is associated
    • find

      @Nonnull public Maybe<T> find(int index)
      Description copied from interface: IArray
      Return a Holder containing the value associated wth the index or an empty Holder if no value is associated with the index.
      Specified by:
      find in interface IArray<T>
      Specified by:
      find in interface Indexed<T>
      Parameters:
      index - identifies the value to retrieve
      Returns:
      possibly empty Holder containing any value associated with the index
    • findEntry

      @Nonnull public Maybe<IMapEntry<Integer,T>> findEntry(int index)
      Description copied from interface: IArray
      Search for an Entry within the map and return a Holder indicating if the Entry was found and, if it was found, the Entry itself.
      Specified by:
      findEntry in interface IArray<T>
      Parameters:
      index - index to search for
      Returns:
      empty Holder if not found, otherwise filled Holder with Entry
    • assign

      @Nonnull public IArray<T> assign(int index, @Nullable T value)
      Description copied from interface: IArray
      Sets the value associated with a specific index. Index must be non-null but value can be null. If the index already has a value in the map the old value is discarded and the new value is stored in its place. Returns a new IMap reflecting any changes. The original map is always left unchanged.
      Specified by:
      assign in interface IArray<T>
      Parameters:
      index - index
      value - possibly null value
      Returns:
      new map reflecting the change
    • delete

      @Nonnull public IArray<T> delete(int index)
      Description copied from interface: IArray
      Deletes the entry for the specified index (if any). Returns a new map if the value was deleted or the current map if the index was not contained in the map.
      Specified by:
      delete in interface IArray<T>
      Parameters:
      index - index
      Returns:
      same or different map depending on whether index was removed
    • size

      public int size()
      Description copied from interface: Indexed
      Retrieve the number of values available in the container.
      Specified by:
      size in interface ICollection<T>
      Specified by:
      size in interface Indexed<T>
      Returns:
      number of values in the collection
    • deleteAll

      @Nonnull public IArray<T> deleteAll()
      Specified by:
      deleteAll in interface IArray<T>
      Specified by:
      deleteAll in interface ICollection<T>
      Returns:
      an equivalent collection with no values
    • getMap

      @Nonnull public Map<Integer,T> getMap()
      Description copied from interface: IArray
      Creates an unmodifiable java.util.Map reflecting the values of the IMap backing the array.
      Specified by:
      getMap in interface IArray<T>
      Returns:
      Map view of this IMap
    • insert

      @Nonnull public IArray<T> insert(IMapEntry<Integer,T> e)
      Description copied from interface: ICollection
      Add value to the container in some manner appropriate to the implementation.
      Specified by:
      insert in interface IArray<T>
      Specified by:
      insert in interface ICollection<T>
    • insertAll

      @Nonnull public IArray<T> insertAll(@Nonnull Iterator<? extends IMapEntry<Integer,T>> iterator)
      Description copied from interface: ICollection
      Add all values to the container in some manner appropriate to the implementation.
      Specified by:
      insertAll in interface IArray<T>
      Specified by:
      insertAll in interface ICollection<T>
    • insertAll

      @Nonnull public IArray<T> insertAll(@Nonnull Iterable<? extends IMapEntry<Integer,T>> iterable)
      Description copied from interface: ICollection
      Add all values to the container in some manner appropriate to the implementation.
      Specified by:
      insertAll in interface IArray<T>
      Specified by:
      insertAll in interface ICollection<T>
    • checkInvariants

      public void checkInvariants()
      Description copied from interface: InvariantCheckable
      Checks invariants of implementing class.
      Specified by:
      checkInvariants in interface InvariantCheckable
    • iterator

      Description copied from interface: IStreamable
      Overridden here to require implementations to return a SplitableIterator rather than a basic Iterator. This is necessary to allow composition of new objects from methods like keys() and values().
      Specified by:
      iterator in interface IStreamable<T>
      Specified by:
      iterator in interface Iterable<T>
      Specified by:
      iterator in interface SplitableIterable<T>
    • keys

      @Nonnull public IStreamable<Integer> keys()
      Description copied from interface: IArray
      Creates an IStreamable to access all of the array's keys.
      Specified by:
      keys in interface IArray<T>
    • values

      @Nonnull public IStreamable<T> values()
      Description copied from interface: IArray
      Creates an IStreamable to access all of the array's values.
      Specified by:
      values in interface IArray<T>
    • getSpliteratorCharacteristics

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

      public void forEach(java.util.function.Consumer<? super IMapEntry<Integer,T>> action)
      Specified by:
      forEach in interface Iterable<T>
    • forEachThrows

      public <E extends Exception> void forEachThrows(@Nonnull Proc1Throws<IMapEntry<Integer,T>,E> proc) throws E
      Description copied from interface: SplitableIterable
      Processes every value using the provided function.
      Specified by:
      forEachThrows in interface SplitableIterable<T>
      Throws:
      E
    • forEach

      public void forEach(@Nonnull IndexedProc1<T> proc)
      Description copied from interface: IArray
      Visits every element in the array in order by index and passes the index and value to the provided lambda. Unlike indexedForEach method the index values passed to the lambda are the actual key value in the array.
      Specified by:
      forEach in interface IArray<T>
    • forEachThrows

      public <E extends Exception> void forEachThrows(@Nonnull IndexedProc1Throws<T,E> proc) throws E
      Description copied from interface: IArray
      Visits every element in the array in order by index and passes the index and value to the provided lambda. Unlike indexedForEach method the index values passed to the lambda are the actual key value in the array.
      Specified by:
      forEachThrows in interface IArray<T>
      Throws:
      E
    • equals

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

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

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

      @Nonnull public IArrayBuilder<T> toBuilder()
      Description copied from interface: IArray
      Creates and returns a new Builder object for the same value type as this array.
      Specified by:
      toBuilder in interface IArray<T>
      Returns:
      An empty Builder object ready for use to create a new IArray.