Package org.javimmutable.collections
Interface IDeque<T>
- All Superinterfaces:
ICollection<T>
,Indexed<T>
,InvariantCheckable
,IStreamable<T>
,Iterable<T>
,Serializable
,SplitableIterable<T>
- All Known Subinterfaces:
IList<T>
- All Known Implementing Classes:
ArrayDeque
,TreeList
@Immutable
public interface IDeque<T>
extends ICollection<T>, Indexed<T>, InvariantCheckable, Serializable
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.Removes the first value from the list and reduces size by 1.Removes the last value from the list and reduces size by 1.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.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.Adds a value to the end of the list.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.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.single()
Returns a Holder containing a value if this list contains only a single value and that value is non-null.suffix
(int offset) Return the (possibly empty) list containing the values starting at offset (inclusive) and including all remaining items.<A> IDeque
<A> Apply the transform function to all elements in iterator order and add each transformed value to a new collection of this type.<A> IDeque
<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.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
-
get
Retrieves the value at the specified index (which must be within the bounds of the list).- Specified by:
get
in interfaceIndexed<T>
- Throws:
IndexOutOfBoundsException
- if index is out of bounds
-
assign
Replaces the value at the specified index (which must be within current bounds of the list) with the new value.- 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.- Specified by:
insert
in interfaceICollection<T>
-
insertFirst
Adds a value to the front of the list. May be invoked on an empty list. Synonym for insert() -
insertLast
Adds a value to the end of the list. May be invoked on an empty list. Synonym for insert(). -
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.- Specified by:
insertAll
in interfaceICollection<T>
- Returns:
- instance of list containing the collection
-
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.- Specified by:
insertAll
in interfaceICollection<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.- 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.- 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()- 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()- 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- 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- Returns:
- new
IList
without last value - Throws:
IndexOutOfBoundsException
- if list is already empty
-
deleteAll
- Specified by:
deleteAll
in interfaceICollection<T>
- Returns:
- an equivalent collection with no values
-
getList
Returns an unmodifiable List implementation backed by this list. -
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.- Parameters:
predicate
- decides whether to include an element- Returns:
- list of same type as this containing only those elements for which predicate returns 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.- Parameters:
predicate
- decides whether to include an element- Returns:
- list of same type as this containing only those elements for which predicate returns false
-
dequeCollector
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.- Parameters:
transform
- transformation applied to each element- Returns:
- the collection after all elements have been processed
-
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.- Parameters:
transform
- transformation applied to each element- Returns:
- the collection after all elements have been processed
-
single
Returns a Holder containing a value if this list contains only a single value and that value is non-null. Otherwise returns and empty Holder. i.e. empty unless size() == 1 and get(0) returns a non-null value.- Returns:
- Holder possibly containing the single non-null value in this list
-
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.- Parameters:
offset
- first index (inclusive) of values to include- Returns:
- a possibly empty list containing the values
-
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.- Parameters:
offset
- first index (inclusive) of values to includelimit
- last index (exclusive) of values to include- Returns:
- a possibly empty list containing the values
-