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
-
Method Summary
Modifier and TypeMethodDescriptionReplaces the value at the specified index (which must be within current bounds of the list) with the new value.void
Checks 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.boolean
find
(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.int
int
hashCode()
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.boolean
isEmpty()
boolean
iterator()
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> V
Apply 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.int
size()
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, wait
Methods inherited from interface org.javimmutable.collections.IDeque
dequeCollector, single
Methods inherited from interface org.javimmutable.collections.IList
listCollector
Methods inherited from interface org.javimmutable.collections.Indexed
reversed, transformed
Methods inherited from interface org.javimmutable.collections.IStreamable
parallelStream, spliterator, stream
Methods inherited from interface org.javimmutable.collections.SplitableIterable
indexedForEach, indexedForEachThrows
-
Method Details
-
of
-
of
-
of
-
of
-
listBuilder
-
createListCollector
-
assign
Description copied from interface:IList
Replaces the value at the specified index (which must be within current bounds of the list) with the new value. -
insert
Description copied from interface:IList
Adds a value to the end of the list. May be invoked on an empty list. -
insert
Description copied from interface:IList
Insert 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:IList
Adds a value to the front of the list. May be invoked on an empty list. Synonym for insert()- Specified by:
insertFirst
in interfaceIDeque<T>
- Specified by:
insertFirst
in interfaceIList<T>
-
insertLast
Description copied from interface:IList
Adds a value to the end of the list. May be invoked on an empty list. Synonym for insert().- Specified by:
insertLast
in interfaceIDeque<T>
- Specified by:
insertLast
in interfaceIList<T>
-
insertAll
Description copied from interface:IList
Adds 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:IList
Adds 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:IList
Inserts 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:IList
Inserts 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:IList
Adds 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:
insertAllFirst
in interfaceIDeque<T>
- Specified by:
insertAllFirst
in interfaceIList<T>
- Returns:
- instance of list containing the collection
-
insertAllFirst
Description copied from interface:IList
Adds 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:
insertAllFirst
in interfaceIDeque<T>
- Specified by:
insertAllFirst
in interfaceIList<T>
- Returns:
- instance of list containing the collection
-
insertAllLast
Description copied from interface:IList
Adds 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:
insertAllLast
in interfaceIDeque<T>
- Specified by:
insertAllLast
in interfaceIList<T>
- Returns:
- instance of list containing the collection
-
insertAllLast
Description copied from interface:IList
Adds 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:
insertAllLast
in interfaceIDeque<T>
- Specified by:
insertAllLast
in interfaceIList<T>
- Returns:
- instance of list containing the collection
-
deleteFirst
Description copied from interface:IList
Removes the first value from the list and reduces size by 1. size() must be greater than zero- Specified by:
deleteFirst
in interfaceIDeque<T>
- Specified by:
deleteFirst
in interfaceIList<T>
- Returns:
- new
IList
without last value
-
deleteLast
Description copied from interface:IList
Removes the last value from the list and reduces size by 1. size() must be greater than zero- Specified by:
deleteLast
in interfaceIDeque<T>
- Specified by:
deleteLast
in interfaceIList<T>
- Returns:
- new
IList
without last value
-
delete
Description copied from interface:IList
Delete 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:IList
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. -
transform
Description copied from interface:IList
Apply 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:IList
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.- Specified by:
transformSome
in interfaceIDeque<T>
- Specified by:
transformSome
in 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:Indexed
Retrieve the number of values available in the container. -
get
Description copied from interface:IDeque
Retrieves the value at the specified index (which must be within the bounds of the list). -
find
Description copied from interface:Indexed
Retrieves 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:
isEmpty
in interfaceICollection<T>
- Returns:
- true only if collection contains no values
-
isNonEmpty
public boolean isNonEmpty()- Specified by:
isNonEmpty
in interfaceICollection<T>
- Returns:
- false only if collection contains no values
-
select
Description copied from interface:IList
Returns 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:IList
Returns 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:IList
Return the (possibly empty) list containing the first limit values. -
suffix
Description copied from interface:IList
Return the (possibly empty) list containing the values starting at offset (inclusive) and including all remaining items. -
middle
Description copied from interface:IList
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. -
slice
Description copied from interface:IList
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. 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:IDeque
Returns an unmodifiable List implementation backed by this list. -
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>
-
getSpliteratorCharacteristics
public int getSpliteratorCharacteristics()- Specified by:
getSpliteratorCharacteristics
in interfaceIStreamable<T>
- Returns:
- characteristics value used when creating Spliterators
-
equals
-
hashCode
public int hashCode() -
toString
-
forEach
-
forEachThrows
Description copied from interface:SplitableIterable
Processes every value using the provided function.- Specified by:
forEachThrows
in interfaceSplitableIterable<T>
- Throws:
E
-
reduce
Description copied from interface:SplitableIterable
Apply 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:
reduce
in 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:
reduceThrows
in interfaceSplitableIterable<T>
- Throws:
E
-