@Generated(date="2017-07-11T19:16:25+0200",
value="KTypeArrayDeque.java")
public class DoubleArrayDeque
extends AbstractDoubleCollection
implements DoubleDeque, DoubleIndexedContainer, java.lang.Cloneable
ArraySizingStrategy
and may be expensive if they move around really large chunks of memory.
This dequeue is also a DoubleIndexedContainer, where index 0 is the head of the queue, and
size() - 1 index is the last element.
See ObjectArrayDeque class for API similarities and differences against Java
Collections.
| Modifier and Type | Class and Description |
|---|---|
class |
DoubleArrayDeque.DescendingValueIterator
An iterator implementation for
ObjectArrayDeque.descendingIterator(). |
class |
DoubleArrayDeque.ValueIterator
An iterator implementation for
ObjectArrayDeque.iterator(). |
| Modifier and Type | Field and Description |
|---|---|
double[] |
buffer
Internal array for storing elements.
|
protected IteratorPool<DoubleCursor,DoubleArrayDeque.DescendingValueIterator> |
descendingValueIteratorPool
internal pool of DescendingValueIterator (must be created in constructor)
|
int |
head
The index of the element at the head of the deque or an
arbitrary number equal to tail if the deque is empty.
|
protected ArraySizingStrategy |
resizer
Buffer resizing strategy.
|
int |
tail
The index at which the next element would be added to the tail
of the deque.
|
protected IteratorPool<DoubleCursor,DoubleArrayDeque.ValueIterator> |
valueIteratorPool
internal pool of ValueIterator (must be created in constructor)
|
containsNegateTestPredicate, containsTestPredicate, negatePredicate, testContainer, testPredicate| Constructor and Description |
|---|
DoubleArrayDeque()
Default constructor.
|
DoubleArrayDeque(DoubleContainer container)
Creates a new deque from elements of another container, appending them
at the end of this deque.
|
DoubleArrayDeque(int initialCapacity)
Create with default sizing strategy and the given initial capacity.
|
DoubleArrayDeque(int initialCapacity,
ArraySizingStrategy resizer)
Create with a custom buffer resizing strategy.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(double e1)
Adds an element to the end of this container (the last index is incremented by one).
|
void |
addFirst(double... elements)
Vararg-signature method for adding elements at the front of this deque.
|
void |
addFirst(double e1)
Inserts the specified element at the front of this deque.
|
int |
addFirst(DoubleContainer container)
Inserts all elements from the given container to the front of this deque.
|
int |
addFirst(java.lang.Iterable<? extends DoubleCursor> iterable)
Inserts all elements from the given iterable to the front of this deque.
|
void |
addLast(double... elements)
Vararg-signature method for adding elements at the end of this deque.
|
void |
addLast(double e1)
Inserts the specified element at the end of this deque.
|
int |
addLast(DoubleContainer container)
Inserts all elements from the given container to the end of this deque.
|
int |
addLast(java.lang.Iterable<? extends DoubleCursor> iterable)
Inserts all elements from the given iterable to the end of this deque.
|
int |
bufferIndexOf(double e1)
Return the index of the first element equal to
e1. |
int |
capacity()
Return the maximum number of elements this container is guaranteed to hold without reallocating.
|
void |
clear()
Removes all elements from this collection.
|
DoubleArrayDeque |
clone()
Clone this object.
|
boolean |
contains(double e)
Lookup a given element in the container.
|
<T extends DoublePredicate> |
descendingForEach(T predicate)
Applies a
predicate to container elements as long, as the predicate
returns true. |
<T extends DoubleProcedure> |
descendingForEach(T procedure)
Applies
procedure to all elements of this deque, tail to head. |
DoubleArrayDeque.DescendingValueIterator |
descendingIterator()
Returns an iterator over the values of this deque (in tail to head order).
|
protected void |
ensureBufferSpace(int expectedAdditions)
Ensures the internal buffer has enough free slots to store
expectedAdditions. |
boolean |
equals(java.lang.Object obj) |
<T extends DoublePredicate> |
forEach(T predicate)
Applies a
predicate to container elements, as long as the predicate
returns true. |
<T extends DoubleProcedure> |
forEach(T procedure)
Applies a
procedure to all container elements. |
<T extends DoublePredicate> |
forEach(T predicate,
int fromIndex,
int toIndex)
Applies
predicate to a slice of the container,
fromIndex, inclusive, to toIndex,
exclusive, or until predicate returns false. |
<T extends DoubleProcedure> |
forEach(T procedure,
int fromIndex,
int toIndex)
Applies
procedure to a slice of the container,
fromIndex, inclusive, to toIndex, exclusive. |
static DoubleArrayDeque |
from(double... elements)
Create a new deque by pushing a variable number of arguments to the end of it.
|
static DoubleArrayDeque |
from(DoubleContainer container)
Create a new deque by pushing a variable number of arguments to the end of it.
|
double |
get(int index)
The position is relative to the head,
i.e w.r.t the
DoubleIndexedContainer, index 0 is the head of the queue, size() - 1 is the last element position. |
double |
getFirst()
Retrieves, but does not remove, the first element of this deque.
|
double |
getLast()
Retrieves, but does not remove, the last element of this deque.
|
int |
hashCode() |
int |
indexOf(double e1)
Returns the index of the first occurrence of the specified element in this list,
or -1 if this list does not contain the element.
|
void |
insert(int index,
double e1)
This operation is not supported on array deques, throwing UnsupportedOperationException.
|
DoubleArrayDeque.ValueIterator |
iterator()
Returns an iterator over the values of this deque (in head to tail order).
|
int |
lastBufferIndexOf(double e1)
Return the index of the last element equal to
e1. |
int |
lastIndexOf(double e1)
Returns the index of the last occurrence of the specified element in this list,
or -1 if this list does not contain the element.
|
static DoubleArrayDeque |
newInstance()
Returns a new object of this class with no need to declare generic type (shortcut
instead of using a constructor).
|
static DoubleArrayDeque |
newInstance(int initialCapacity)
Returns a new object of this class with no need to declare generic type (shortcut
instead of using a constructor).
|
void |
release()
Release internal buffers of this deque and reallocate the smallest buffer possible.
|
double |
remove(int index)
Removes the element at the specified position in this list and returns it.
|
int |
removeAll(double e1)
Removes all occurrences of
e from this collection. |
int |
removeAll(DoublePredicate predicate)
Removes all elements in this collection for which the
given predicate returns
true. |
double |
removeFirst()
Retrieves and removes the first element of this deque.
|
int |
removeFirst(double e1)
Removes the first element that equals
e1, returning its
deleted position or -1 if the element was not found. |
double |
removeLast()
Retrieves and removes the last element of this deque.
|
int |
removeLast(double e1)
Removes the last element that equals
e1, returning its
deleted position or -1 if the element was not found. |
void |
removeRange(int fromIndex,
int toIndex)
Removes from this list all of the elements whose index is between
fromIndex, inclusive, and toIndex, exclusive. |
double |
set(int index,
double e1)
Replaces the element at the specified position in this list
with the specified element.
|
int |
size()
Return the current number of elements in this container.
|
void |
sort()
In-place sort the whole dequeue by natural ordering (smaller first)
|
void |
sort(DoubleComparator comp)
In-place sort the whole dequeue
using a
DoubleComparator |
void |
sort(int beginIndex,
int endIndex)
In-place sort the dequeue from [beginIndex, endIndex[
by natural ordering (smaller first)
|
void |
sort(int beginIndex,
int endIndex,
DoubleComparator comp)
In-place sort the dequeue from [beginIndex, endIndex[
using a
DoubleComparator * @param beginIndex the start index to be sorted |
double[] |
toArray(double[] target)
Copies elements of this deque to an array.
|
isEmpty, removeAll, retainAll, retainAll, toArray, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitremoveAll, retainAll, retainAllisEmpty, toArraypublic double[] buffer
Direct deque iteration from head to tail: iterate buffer[i % buffer.length] for i in [this.head; this.head + size()[
public int head
public int tail
protected final ArraySizingStrategy resizer
protected final IteratorPool<DoubleCursor,DoubleArrayDeque.DescendingValueIterator> descendingValueIteratorPool
protected final IteratorPool<DoubleCursor,DoubleArrayDeque.ValueIterator> valueIteratorPool
public DoubleArrayDeque()
public DoubleArrayDeque(int initialCapacity)
BoundedProportionalArraySizingStrategypublic DoubleArrayDeque(int initialCapacity,
ArraySizingStrategy resizer)
public DoubleArrayDeque(DoubleContainer container)
public void addFirst(double e1)
addFirst in interface DoubleDequee1 - the element to addpublic void addFirst(double... elements)
This method is handy, but costly if used in tight loops (anonymous array passing)
public int addFirst(DoubleContainer container)
public int addFirst(java.lang.Iterable<? extends DoubleCursor> iterable)
public void addLast(double e1)
addLast in interface DoubleDequee1 - the element to addpublic void addLast(double... elements)
This method is handy, but costly if used in tight loops (anonymous array passing)
public int addLast(DoubleContainer container)
public int addLast(java.lang.Iterable<? extends DoubleCursor> iterable)
public double removeFirst()
removeFirst in interface DoubleDequepublic double removeLast()
removeLast in interface DoubleDequepublic double getFirst()
getFirst in interface DoubleDequepublic double getLast()
getLast in interface DoubleDequepublic int removeFirst(double e1)
e1, returning its
deleted position or -1 if the element was not found.
The returned position is relative to the head,
i.e w.r.t the DoubleIndexedContainer, index 0 is the head of the queue, size() - 1 is the last element position.removeFirst in interface DoubleDequeremoveFirst in interface DoubleIndexedContainerpublic int bufferIndexOf(double e1)
e1. The index points to the buffer array.e1 - The element to look for.buffer of the first element equal to e1
or -1 if not found.public int removeLast(double e1)
e1, returning its
deleted position or -1 if the element was not found.
The returned position is relative to the head,
i.e w.r.t the DoubleIndexedContainer, index 0 is the head of the queue, size() - 1 is the last element position.removeLast in interface DoubleDequeremoveLast in interface DoubleIndexedContainerpublic int lastBufferIndexOf(double e1)
e1. The index points to the buffer array.e1 - The element to look for.buffer of the first element equal to e1
or -1 if not found.public int indexOf(double e1)
DoubleIndexedContainer, index 0 is the head of the queue, size() - 1 is the last element position.indexOf in interface DoubleIndexedContainerpublic int lastIndexOf(double e1)
DoubleIndexedContainer, index 0 is the head of the queue, size() - 1 is the last element position.lastIndexOf in interface DoubleIndexedContainerpublic int removeAll(double e1)
e from this collection.removeAll in interface DoubleCollectione1 - Element to be removed from this collection, if present.public int size()
O(n) time, although implementing classes
should try to maintain the current size and return in constant time.size in interface DoubleContainerpublic int capacity()
O(n) time.capacity in interface DoubleContainerpublic void clear()
The internal array buffers are not released as a result of this call.
clear in interface DoubleCollectionpublic void release()
protected void ensureBufferSpace(int expectedAdditions)
expectedAdditions. Increases internal buffer size if needed.public double[] toArray(double[] target)
target
array is filled from index 0 (head of the queue) to index size() - 1
(tail of the queue).toArray in interface DoubleContainertoArray in class AbstractDoubleCollectiontarget - The target array must be large enough to hold all elements.public DoubleArrayDeque clone()
clone in class java.lang.Objectpublic DoubleArrayDeque.ValueIterator iterator()
Iterator.next() (to avoid boxing of primitive types). To
read the current value, or index in the deque's buffer, use the cursor's public
fields. An example is shown below.
for (IntValueCursor c : intDeque)
{
System.out.println("buffer index="
+ c.index + " value=" + c.value);
}
iterator in interface DoubleContaineriterator in interface java.lang.Iterable<DoubleCursor>public DoubleArrayDeque.DescendingValueIterator descendingIterator()
Iterator.next() (to avoid boxing of primitive types). To
read the current value, or index in the deque's buffer, use the cursor's public
fields. An example is shown below.
for (Iteratori = intDeque.descendingIterator(); i.hasNext(); ) { final IntCursor c = i.next(); System.out.println("buffer index=" + c.index + " value=" + c.value); }
descendingIterator in interface DoubleDequepublic <T extends DoubleProcedure> T forEach(T procedure)
procedure to all container elements. Returns the argument (any
subclass of DoubleProcedure. This lets the caller to call methods of the argument
by chaining the call (even if the argument is an anonymous type) to retrieve computed values,
for example (IntContainer):
int count = container.forEach(new IntProcedure() {
int count; // this is a field declaration in an anonymous class.
public void apply(int value) { count++; }}).count;
forEach in interface DoubleContainerpublic <T extends DoubleProcedure> T forEach(T procedure, int fromIndex, int toIndex)
procedure to a slice of the container,
fromIndex, inclusive, to toIndex, exclusive.forEach in interface DoubleIndexedContainerpublic <T extends DoublePredicate> T forEach(T predicate)
predicate to container elements, as long as the predicate
returns true. The iteration is interrupted otherwise.forEach in interface DoubleContainerpublic <T extends DoublePredicate> T forEach(T predicate, int fromIndex, int toIndex)
predicate to a slice of the container,
fromIndex, inclusive, to toIndex,
exclusive, or until predicate returns false.forEach in interface DoubleIndexedContainerpublic <T extends DoubleProcedure> T descendingForEach(T procedure)
procedure to all elements of this deque, tail to head.descendingForEach in interface DoubleDequepublic <T extends DoublePredicate> T descendingForEach(T predicate)
predicate to container elements as long, as the predicate
returns true. The iteration is interrupted otherwise.descendingForEach in interface DoubleDequepublic int removeAll(DoublePredicate predicate)
true.removeAll in interface DoubleCollectionpublic boolean contains(double e)
contains in interface DoubleContainertrue if this container has an element
equal to e.public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic static DoubleArrayDeque newInstance()
public static DoubleArrayDeque newInstance(int initialCapacity)
public static DoubleArrayDeque from(double... elements)
public static DoubleArrayDeque from(DoubleContainer container)
public void sort(int beginIndex,
int endIndex)
beginIndex - the start index to be sortedendIndex - the end index to be sorted (excluded)public void sort(int beginIndex,
int endIndex,
DoubleComparator comp)
DoubleComparator * @param beginIndex the start index to be sortedendIndex - the end index to be sorted (excluded)public void sort()
public void sort(DoubleComparator comp)
DoubleComparatorpublic void add(double e1)
add in interface DoubleIndexedContainerpublic void insert(int index,
double e1)
insert in interface DoubleIndexedContainerindex - The index at which the element should be inserted, shifting
any existing and subsequent elements to the right.
Precondition : index must be valid !java.lang.UnsupportedOperationExceptionpublic double set(int index,
double e1)
DoubleIndexedContainer, index 0 is the head of the queue, size() - 1 is the last element position.set in interface DoubleIndexedContainerpublic double get(int index)
DoubleIndexedContainer, index 0 is the head of the queue, size() - 1 is the last element position.get in interface DoubleIndexedContainerindex from the list.
Precondition : index must be valid !public double remove(int index)
Careful. Do not confuse this method with the overridden signature in
Java Collections (List.remove(Object)). Use: DoubleCollection.removeAll(double),
DoubleIndexedContainer.removeFirst(double) or DoubleIndexedContainer.removeLast(double) depending
on the actual need.
DoubleIndexedContainer, index 0 is the head of the queue, size() - 1 is the last element position.remove in interface DoubleIndexedContainerpublic void removeRange(int fromIndex,
int toIndex)
fromIndex, inclusive, and toIndex, exclusive.
The position is relative to the head,
i.e w.r.t the DoubleIndexedContainer, index 0 is the head of the queue, size() - 1 is the last element position.removeRange in interface DoubleIndexedContainerCopyright © 2017. All rights reserved.