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>>
- See Also:
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionSets the value associated with a specific index.static <T> IArrayBuilder
<T> builder()
void
Checks invariants of implementing class.static <T> java.util.stream.Collector
<T, ?, IArray<T>> delete
(int index) Deletes the entry for the specified index (if any).boolean
find
(int index) Return a Holder containing the value associated wth the index or an empty Holder if no value is associated with the index.findEntry
(int index) 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.void
void
forEach
(IndexedProc1<T> proc) Visits every element in the array in order by index and passes the index and value to the provided lambda.<E extends Exception>
voidforEachThrows
(IndexedProc1Throws<T, E> proc) Visits every element in the array in order by index and passes the index and value to the provided lambda.<E extends Exception>
voidforEachThrows
(Proc1Throws<IMapEntry<Integer, T>, E> proc) Processes every value using the provided function.get
(int index) Return the value associated with index or null if no value is associated.getMap()
Creates an unmodifiable java.util.Map reflecting the values of theIMap
backing the array.int
getValueOr
(int index, T defaultValue) Return the value associated with index or defaultValue if no value is associated.int
hashCode()
Add value to the container in some manner appropriate to the implementation.Add all values to the container in some manner appropriate to the implementation.Add all values to the container in some manner appropriate to the implementation.iterator()
Overridden here to require implementations to return a SplitableIterator rather than a basic Iterator.keys()
Creates an IStreamable to access all of the array's keys.static <T> IArray
<T> of()
int
size()
Retrieve the number of values available in the container.Creates and returns a new Builder object for the same value type as this array.toString()
values()
Creates an IStreamable to access all of the array's values.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.javimmutable.collections.ICollection
isEmpty, isNonEmpty
Methods inherited from interface org.javimmutable.collections.Indexed
prefix, reversed, transformed
Methods inherited from interface org.javimmutable.collections.IStreamable
parallelStream, spliterator, stream
Methods inherited from interface org.javimmutable.collections.SplitableIterable
indexedForEach, indexedForEachThrows, reduce, reduceThrows
-
Method Details
-
of
-
builder
-
collector
-
get
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. -
getValueOr
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 interfaceIArray<T>
- Parameters:
index
- identifies the value to retrievedefaultValue
- value to return if no entry exists for index- Returns:
- value associated with index or defaultValue if no value is associated
-
find
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. -
findEntry
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. -
assign
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 newIMap
reflecting any changes. The original map is always left unchanged. -
delete
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. -
size
public int size()Description copied from interface:Indexed
Retrieve the number of values available in the container. -
deleteAll
-
getMap
Description copied from interface:IArray
Creates an unmodifiable java.util.Map reflecting the values of theIMap
backing the array. -
insert
Description copied from interface:ICollection
Add value to the container in some manner appropriate to the implementation. -
insertAll
Description copied from interface:ICollection
Add all values to the container in some manner appropriate to the implementation. -
insertAll
Description copied from interface:ICollection
Add all values to the container in some manner appropriate to the implementation. -
checkInvariants
public void checkInvariants()Description copied from interface:InvariantCheckable
Checks invariants of implementing class.- Specified by:
checkInvariants
in interfaceInvariantCheckable
-
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 interfaceIStreamable<T>
- Specified by:
iterator
in interfaceIterable<T>
- Specified by:
iterator
in interfaceSplitableIterable<T>
-
keys
Description copied from interface:IArray
Creates an IStreamable to access all of the array's keys. -
values
Description copied from interface:IArray
Creates an IStreamable to access all of the array's values. -
getSpliteratorCharacteristics
public int getSpliteratorCharacteristics()- Specified by:
getSpliteratorCharacteristics
in interfaceIStreamable<T>
- Returns:
- characteristics value used when creating Spliterators
-
forEach
-
forEachThrows
public <E extends Exception> void forEachThrows(@Nonnull Proc1Throws<IMapEntry<Integer, T>, throws EE> proc) Description copied from interface:SplitableIterable
Processes every value using the provided function.- Specified by:
forEachThrows
in interfaceSplitableIterable<T>
- Throws:
E
-
forEach
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. -
forEachThrows
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 interfaceIArray<T>
- Throws:
E
-
equals
-
hashCode
public int hashCode() -
toString
-
toBuilder
Description copied from interface:IArray
Creates and returns a new Builder object for the same value type as this array.
-