Class TreeList<T>
java.lang.Object
org.javimmutable.collections.list.TreeList<T>
- All Implemented Interfaces:
Serializable,Iterable<T>,ICollection<T>,IDeque<T>,IList<T>,Indexed<T>,InvariantCheckable,IStreamable<T>,SplitableIterable<T>
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionReplaces the value at the specified index (which must be within current bounds of the list) with the new value.voidChecks invariants of implementing class.static <T> java.util.stream.Collector<T, ?, IList<T>> delete(int index) Delete value at index (which must be within the current bounds of the list).Removes the first value from the list and reduces size by 1.Removes the last value from the list and reduces size by 1.booleanfind(int index) Retrieves a Holder containing the (possibly null) value at the specified index if it exists.void<E extends Exception>
voidforEachThrows(Proc1Throws<T, E> proc) Processes every value using the provided function.get(int index) Retrieves the value at the specified index (which must be within the bounds of the list).getList()Returns an unmodifiable List implementation backed by this list.intinthashCode()Insert value at index (which must be within 0 to size).Adds a value to the end of the list.Inserts all elements at index (which must be within 0 to size) in the same order they appear in the Iterable.Inserts all elements at index (which must be within 0 to size) in the same order they appear in the Iterable.Adds the values to the end of the list in the same order they appear in the Iterable.Adds the values to the end of the list in the same order they appear in the Iterable.insertAllFirst(Iterable<? extends T> values) Adds the values to the beginning of the list in the same order they appear in the Iterable.insertAllFirst(Iterator<? extends T> values) Adds the values to the beginning of the list in the same order they appear in the Iterable.insertAllLast(Iterable<? extends T> values) Adds the values to the end of the list in the same order they appear in the Iterable.insertAllLast(Iterator<? extends T> values) Adds the values to the end of the list in the same order they appear in the Iterable.insertFirst(T value) Adds a value to the front of the list.insertLast(T value) Adds a value to the end of the list.booleanisEmpty()booleaniterator()Overridden here to require implementations to return a SplitableIterator rather than a basic Iterator.static <T> TreeList.ListBuilder<T> middle(int offset, int limit) Return the (possibly empty) list containing the values starting at offset (inclusive) and including all remaining items up to but excluding the value at index limit.static <T> TreeList<T> of()static <T> TreeList<T> static <T> TreeList<T> static <T> TreeList<T> prefix(int limit) Return the (possibly empty) list containing the first limit values.<V> VApply the specified accumulator to all elements in iterator order calling the accumulator function for each element.<V,E extends Exception>
VreduceThrows(V initialValue, Sum1Throws<T, V, E> accumulator) Returns a list of the same type as this containing all those elements for which predicate returns false.reverse()Returns a list containing the same elements as this list but with their order reversed so that first in this list is last in returned list etc.Returns a list of the same type as this containing only those elements for which predicate returns true.intsize()Retrieve the number of values available in the container.slice(int offset, int limit) Return the (possibly empty) list containing the values starting at offset (inclusive) and including all remaining items up to but excluding the value at index limit.suffix(int offset) Return the (possibly empty) list containing the values starting at offset (inclusive) and including all remaining items.toString()<A> TreeList<A> Apply the transform function to all elements in iterator order and add each transformed value to a new collection of this type.<A> TreeList<A> transformSome(Func1<T, Maybe<A>> transform) Apply the transform function to all elements in iterator order and add the contents of non-empty Holders to a new collection of this type.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.javimmutable.collections.IDeque
dequeCollector, singleMethods inherited from interface org.javimmutable.collections.IList
listCollectorMethods inherited from interface org.javimmutable.collections.Indexed
reversed, transformedMethods inherited from interface org.javimmutable.collections.IStreamable
parallelStream, spliterator, streamMethods inherited from interface org.javimmutable.collections.SplitableIterable
indexedForEach, indexedForEachThrows
-
Method Details
-
of
-
of
-
of
-
of
-
listBuilder
-
createListCollector
-
assign
Description copied from interface:IListReplaces the value at the specified index (which must be within current bounds of the list) with the new value. -
insert
Description copied from interface:IListAdds a value to the end of the list. May be invoked on an empty list. -
insert
Description copied from interface:IListInsert value at index (which must be within 0 to size). Shifts all values at and after index one position to the right and adds 1 to size of the list. -
insertFirst
Description copied from interface:IListAdds a value to the front of the list. May be invoked on an empty list. Synonym for insert()- Specified by:
insertFirstin interfaceIDeque<T>- Specified by:
insertFirstin interfaceIList<T>
-
insertLast
Description copied from interface:IListAdds a value to the end of the list. May be invoked on an empty list. Synonym for insert().- Specified by:
insertLastin interfaceIDeque<T>- Specified by:
insertLastin interfaceIList<T>
-
insertAll
Description copied from interface:IListAdds the values to the end of the list in the same order they appear in the Iterable. May be invoked on an empty list. -
insertAll
Description copied from interface:IListAdds the values to the end of the list in the same order they appear in the Iterable. May be invoked on an empty list. -
insertAll
Description copied from interface:IListInserts all elements at index (which must be within 0 to size) in the same order they appear in the Iterable. Shifts all values at and after index x positions to the right and adds x to size of the list, where x is the number of elements being inserted. -
insertAll
Description copied from interface:IListInserts all elements at index (which must be within 0 to size) in the same order they appear in the Iterable. Shifts all values at and after index x positions to the right and adds x to size of the list, where x is the number of elements being inserted. -
insertAllFirst
Description copied from interface:IListAdds the values to the beginning of the list in the same order they appear in the Iterable. May be invoked on an empty list.- Specified by:
insertAllFirstin interfaceIDeque<T>- Specified by:
insertAllFirstin interfaceIList<T>- Returns:
- instance of list containing the collection
-
insertAllFirst
Description copied from interface:IListAdds the values to the beginning of the list in the same order they appear in the Iterable. May be invoked on an empty list.- Specified by:
insertAllFirstin interfaceIDeque<T>- Specified by:
insertAllFirstin interfaceIList<T>- Returns:
- instance of list containing the collection
-
insertAllLast
Description copied from interface:IListAdds the values to the end of the list in the same order they appear in the Iterable. May be invoked on an empty list. Synonym for insertAll()- Specified by:
insertAllLastin interfaceIDeque<T>- Specified by:
insertAllLastin interfaceIList<T>- Returns:
- instance of list containing the collection
-
insertAllLast
Description copied from interface:IListAdds the values to the end of the list in the same order they appear in the Iterable. May be invoked on an empty list. Synonym for insertAll()- Specified by:
insertAllLastin interfaceIDeque<T>- Specified by:
insertAllLastin interfaceIList<T>- Returns:
- instance of list containing the collection
-
deleteFirst
Description copied from interface:IListRemoves the first value from the list and reduces size by 1. size() must be greater than zero- Specified by:
deleteFirstin interfaceIDeque<T>- Specified by:
deleteFirstin interfaceIList<T>- Returns:
- new
IListwithout last value
-
deleteLast
Description copied from interface:IListRemoves the last value from the list and reduces size by 1. size() must be greater than zero- Specified by:
deleteLastin interfaceIDeque<T>- Specified by:
deleteLastin interfaceIList<T>- Returns:
- new
IListwithout last value
-
delete
Description copied from interface:IListDelete value at index (which must be within the current bounds of the list). Shifts all values at and after index one position to the left and subtracts 1 from size of the list. -
deleteAll
-
reverse
Description copied from interface:IListReturns a list containing the same elements as this list but with their order reversed so that first in this list is last in returned list etc. -
transform
Description copied from interface:IListApply the transform function to all elements in iterator order and add each transformed value to a new collection of this type. -
transformSome
Description copied from interface:IListApply the transform function to all elements in iterator order and add the contents of non-empty Holders to a new collection of this type.- Specified by:
transformSomein interfaceIDeque<T>- Specified by:
transformSomein interfaceIList<T>- Parameters:
transform- transformation applied to each element- Returns:
- the collection after all elements have been processed
-
size
public int size()Description copied from interface:IndexedRetrieve the number of values available in the container. -
get
Description copied from interface:IDequeRetrieves the value at the specified index (which must be within the bounds of the list). -
find
Description copied from interface:IndexedRetrieves a Holder containing the (possibly null) value at the specified index if it exists. If no such value exists returns an empty Holder. -
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceICollection<T>- Returns:
- true only if collection contains no values
-
isNonEmpty
public boolean isNonEmpty()- Specified by:
isNonEmptyin interfaceICollection<T>- Returns:
- false only if collection contains no values
-
select
Description copied from interface:IListReturns a list 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. -
reject
Description copied from interface:IListReturns a list 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. -
prefix
Description copied from interface:IListReturn the (possibly empty) list containing the first limit values. -
suffix
Description copied from interface:IListReturn the (possibly empty) list containing the values starting at offset (inclusive) and including all remaining items. -
middle
Description copied from interface:IListReturn the (possibly empty) list containing the values starting at offset (inclusive) and including all remaining items up to but excluding the value at index limit. -
slice
Description copied from interface:IListReturn the (possibly empty) list containing the values starting at offset (inclusive) and including all remaining items up to but excluding the value at index limit. Similar to middle() but accepts a more permissive set of values. Negative values are interpreted relative to the end of the list and are inclusive when used as limit. This (-5,-1) would return the last 5 elements of the list. Bounds checking is removed and values past the end of the list are simply set to the end of the list. So (0,10000) for a list with five elements would be equivalent to (0,5). -
getList
Description copied from interface:IDequeReturns an unmodifiable List implementation backed by this list. -
checkInvariants
public void checkInvariants()Description copied from interface:InvariantCheckableChecks invariants of implementing class.- Specified by:
checkInvariantsin interfaceInvariantCheckable
-
iterator
Description copied from interface:IStreamableOverridden 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:
iteratorin interfaceIStreamable<T>- Specified by:
iteratorin interfaceIterable<T>- Specified by:
iteratorin interfaceSplitableIterable<T>
-
getSpliteratorCharacteristics
public int getSpliteratorCharacteristics()- Specified by:
getSpliteratorCharacteristicsin interfaceIStreamable<T>- Returns:
- characteristics value used when creating Spliterators
-
equals
-
hashCode
public int hashCode() -
toString
-
forEach
-
forEachThrows
Description copied from interface:SplitableIterableProcesses every value using the provided function.- Specified by:
forEachThrowsin interfaceSplitableIterable<T>- Throws:
E
-
reduce
Description copied from interface:SplitableIterableApply the specified accumulator to all elements in iterator order calling the accumulator function for each element. The first call to accumulator is passed initialValue and first element in the sequence. All remaining calls to accumulator are passed the result from the previous call and next element in the sequence.- Specified by:
reducein interfaceSplitableIterable<T>- Parameters:
initialValue- value passed to accumulator on first callaccumulator- method called to compute result- Returns:
- result from last call to accumulator
-
reduceThrows
public <V,E extends Exception> V reduceThrows(V initialValue, Sum1Throws<T, V, throws EE> accumulator) - Specified by:
reduceThrowsin interfaceSplitableIterable<T>- Throws:
E
-