Package org.javimmutable.collections
Interface IList<T>
- All Superinterfaces:
ICollection<T>
,IDeque<T>
,Indexed<T>
,InvariantCheckable
,IStreamable<T>
,Iterable<T>
,Serializable
,SplitableIterable<T>
- All Known Implementing Classes:
TreeList
Interface for containers that store items in list form with individual items available
for get() and assign() using their indexes. Items inserted into the list are always
added at either the front or the end of the list and indexes of items are always in
the range 0 through size() - 1.
-
Method Summary
Modifier and TypeMethodDescriptionReplaces the value at the specified index (which must be within current bounds of the list) with the new value.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.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.Returns a Collector that creates a list of the same type as this containing all of the collected values inserted after whatever starting values this already contained.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.prefix
(int limit) Return the (possibly empty) list containing the first limit values.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.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.<A> IList
<A> Apply the transform function to all elements in iterator order and add each transformed value to a new collection of this type.<A> IList
<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 interface org.javimmutable.collections.ICollection
isEmpty, isNonEmpty, size
Methods inherited from interface org.javimmutable.collections.IDeque
dequeCollector, get, getList, single
Methods inherited from interface org.javimmutable.collections.Indexed
find, reversed, size, transformed
Methods inherited from interface org.javimmutable.collections.InvariantCheckable
checkInvariants
Methods inherited from interface org.javimmutable.collections.IStreamable
getSpliteratorCharacteristics, iterator, parallelStream, spliterator, stream
Methods inherited from interface org.javimmutable.collections.SplitableIterable
forEachThrows, indexedForEach, indexedForEachThrows, reduce, reduceThrows
-
Method Details
-
assign
Replaces the value at the specified index (which must be within current bounds of the list) with the new value.- Specified by:
assign
in interfaceIDeque<T>
- Throws:
IndexOutOfBoundsException
- if index is out of bounds
-
insert
Adds a value to the end of the list. May be invoked on an empty list. -
insert
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
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>
-
insertLast
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>
-
insertAll
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
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
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.- Returns:
- instance of list containing the collection
-
insertAll
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.- Returns:
- instance of list containing the collection
-
insertAllFirst
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>
- Returns:
- instance of list containing the collection
-
insertAllFirst
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>
- Returns:
- instance of list containing the collection
-
insertAllLast
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>
- Returns:
- instance of list containing the collection
-
insertAllLast
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>
- Returns:
- instance of list containing the collection
-
deleteFirst
Removes the first value from the list and reduces size by 1. size() must be greater than zero- Specified by:
deleteFirst
in interfaceIDeque<T>
- Returns:
- new
IList
without last value - Throws:
IndexOutOfBoundsException
- if list is already empty
-
deleteLast
Removes the last value from the list and reduces size by 1. size() must be greater than zero- Specified by:
deleteLast
in interfaceIDeque<T>
- Returns:
- new
IList
without last value - Throws:
IndexOutOfBoundsException
- if list is already empty
-
delete
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
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. -
select
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
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. -
listCollector
Returns a Collector that creates a list of the same type as this containing all of the collected values inserted after whatever starting values this already contained. -
transform
Apply the transform function to all elements in iterator order and add each transformed value to a new collection of this type. -
transformSome
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>
- Parameters:
transform
- transformation applied to each element- Returns:
- the collection after all elements have been processed
-
prefix
Return the (possibly empty) list containing the first limit values. -
suffix
Return the (possibly empty) list containing the values starting at offset (inclusive) and including all remaining items. -
middle
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
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).- Parameters:
offset
- first index (inclusive) of values to includelimit
- last index (exclusive) of values to include- Returns:
- a possibly empty list containing the values
-