Class ArrayDeque<T>
java.lang.Object
org.javimmutable.collections.deque.ArrayDeque<T>
- All Implemented Interfaces:
Serializable
,Iterable<T>
,ICollection<T>
,IDeque<T>
,Indexed<T>
,InvariantCheckable
,IStreamable<T>
,SplitableIterable<T>
IDeque implementation using 32-way trees. The underlying trees
only allow values to be inserted or deleted from the head or tail.
- 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.static <T> ArrayDeque.Builder
<T> builder()
void
Checks invariants of implementing class.static <T> java.util.stream.Collector
<T, ?, IDeque<T>> 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.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()
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.boolean
isEmpty()
boolean
iterator()
Overridden here to require implementations to return a SplitableIterator rather than a basic Iterator.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> ArrayDeque
<T> of()
static <T> IDeque
<T> 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.int
size()
Retrieve the number of values available in the container.suffix
(int offset) Return the (possibly empty) list containing the values starting at offset (inclusive) and including all remaining items.toString()
<A> ArrayDeque
<A> Apply the transform function to all elements in iterator order and add each transformed value to a new collection of this type.<A> ArrayDeque
<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.Indexed
reversed, transformed
Methods inherited from interface org.javimmutable.collections.IStreamable
parallelStream, spliterator, stream
Methods inherited from interface org.javimmutable.collections.SplitableIterable
forEachThrows, indexedForEach, indexedForEachThrows, reduce, reduceThrows
-
Method Details
-
of
-
of
-
builder
-
collector
-
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. -
assign
Description copied from interface:IDeque
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:IDeque
Adds a value to the end of the list. May be invoked on an empty list. -
select
Description copied from interface:IDeque
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:IDeque
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. -
insertFirst
Description copied from interface:IDeque
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
Description copied from interface:IDeque
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
Description copied from interface:IDeque
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:IDeque
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. -
insertAllFirst
Description copied from interface:IDeque
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
Description copied from interface:IDeque
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
Description copied from interface:IDeque
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
Description copied from interface:IDeque
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
Description copied from interface:IDeque
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
-
deleteLast
Description copied from interface:IDeque
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
-
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
-
deleteAll
-
getList
Description copied from interface:IDeque
Returns an unmodifiable List implementation backed by this list. -
reverse
Description copied from interface:IDeque
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. -
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>
-
transform
Description copied from interface:IDeque
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:IDeque
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
Description copied from interface:IDeque
Return the (possibly empty) list containing the first limit values. -
suffix
Description copied from interface:IDeque
Return the (possibly empty) list containing the values starting at offset (inclusive) and including all remaining items. -
middle
Description copied from interface:IDeque
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. -
getSpliteratorCharacteristics
public int getSpliteratorCharacteristics()- Specified by:
getSpliteratorCharacteristics
in interfaceIStreamable<T>
- Returns:
- characteristics value used when creating Spliterators
-
checkInvariants
public void checkInvariants()Description copied from interface:InvariantCheckable
Checks invariants of implementing class.- Specified by:
checkInvariants
in interfaceInvariantCheckable
-
equals
-
hashCode
public int hashCode() -
toString
-