@Generated(date="2015-05-05T11:00:03+0200", value="KTypeArrayDeque.java") public class DoubleArrayDeque extends java.lang.Object implements DoubleDeque, Preallocable, java.lang.Cloneable
DoubleDeque
.Modifier and Type | Field and Description |
---|---|
double[] |
buffer
Internal array for storing elements of the deque.
|
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.
|
Constructor and Description |
---|
DoubleArrayDeque()
New instance with sane defaults.
|
DoubleArrayDeque(DoubleContainer container)
Creates a new deque from elements of another container, appending elements at
the end of the deque in the iteration order.
|
DoubleArrayDeque(int expectedElements)
New instance with sane defaults.
|
DoubleArrayDeque(int expectedElements,
ArraySizingStrategy resizer)
New instance with sane defaults.
|
Modifier and Type | Method and Description |
---|---|
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 (counting from head) element equal to
e1 . |
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. |
java.util.Iterator<DoubleCursor> |
descendingIterator()
Returns a cursor 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 . |
void |
ensureCapacity(int expectedElements)
Ensure this container can hold at least the given number of elements
without resizing its buffers.
|
protected boolean |
equalElements(DoubleArrayDeque other)
Compare order-aligned elements against another
DoubleDeque . |
boolean |
equals(java.lang.Object obj)
Returns
true only if the other object is an instance of
the same class and with the same elements. |
<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. |
static DoubleArrayDeque |
from(double... elements)
Create a new deque by pushing a variable number of arguments to the end of it.
|
double |
getFirst()
Retrieves the first element of this deque but does not remove it.
|
double |
getLast()
Retrieves the last element of this deque but does not remove it.
|
int |
hashCode() |
boolean |
isEmpty()
Shortcut for
size() == 0 . |
java.util.Iterator<DoubleCursor> |
iterator()
Returns a cursor over the values of this deque (in head to tail order).
|
int |
lastBufferIndexOf(double e1)
Return the index of the last (counting from tail) element equal to
e1 . |
protected static int |
oneLeft(int index,
int modulus)
Move one index to the left, wrapping around buffer.
|
protected static int |
oneRight(int index,
int modulus)
Move one index to the right, wrapping around buffer.
|
void |
release()
Release internal buffers of this deque and reallocate with the default
buffer.
|
int |
removeAll(double e1)
Removes all occurrences of
e from this collection. |
int |
removeAll(DoubleLookupContainer c)
Default implementation uses a predicate for removal.
|
int |
removeAll(DoublePredicate predicate)
Removes all elements in this collection for which the given predicate
returns
true . |
void |
removeAtBufferIndex(int index)
Removes the element at
index in the internal {#link
buffer array, returning its value. |
double |
removeFirst()
Retrieves and removes the first element of this deque.
|
int |
removeFirst(double e1)
Removes the first element that equals
e . |
double |
removeLast()
Retrieves and removes the last element of this deque.
|
int |
removeLast(double e1)
Removes the last element that equals
e . |
int |
retainAll(DoubleLookupContainer c)
Default implementation uses a predicate for retaining.
|
int |
retainAll(DoublePredicate predicate)
Default implementation redirects to
DoubleCollection.removeAll(DoublePredicate) and
negates the predicate. |
int |
size()
Return the current number of elements in this container.
|
double[] |
toArray()
Default implementation of copying to an array.
|
double[] |
toArray(double[] target)
Copies elements of this deque to an array.
|
java.lang.String |
toString()
Convert the contents of this container to a human-friendly string.
|
finalize, getClass, notify, notifyAll, wait, wait, wait
removeAll, retainAll, retainAll
public double[] buffer
public int head
public int tail
protected final ArraySizingStrategy resizer
public DoubleArrayDeque()
public DoubleArrayDeque(int expectedElements)
expectedElements
- The expected number of elements guaranteed not to cause buffer
expansion (inclusive).public DoubleArrayDeque(int expectedElements, ArraySizingStrategy resizer)
expectedElements
- The expected number of elements guaranteed not to cause buffer
expansion (inclusive).resizer
- Underlying buffer sizing strategy.public DoubleArrayDeque(DoubleContainer container)
public void addFirst(double e1)
addFirst
in interface DoubleDeque
public final void addFirst(double... elements)
This method is handy, but costly if used in tight loops (anonymous array passing)
elements
- The elements to add.public int addFirst(DoubleContainer container)
container
- The container to iterate over.public int addFirst(java.lang.Iterable<? extends DoubleCursor> iterable)
iterable
- The iterable to iterate over.public void addLast(double e1)
addLast
in interface DoubleDeque
public final void addLast(double... elements)
This method is handy, but costly if used in tight loops (anonymous array passing)
elements
- The elements to iterate over.public int addLast(DoubleContainer container)
container
- The container to iterate over.public int addLast(java.lang.Iterable<? extends DoubleCursor> iterable)
iterable
- The iterable to iterate over.public double removeFirst()
removeFirst
in interface DoubleDeque
public double removeLast()
removeLast
in interface DoubleDeque
public double getFirst()
getFirst
in interface DoubleDeque
public double getLast()
getLast
in interface DoubleDeque
public int removeFirst(double e1)
e
.removeFirst
in interface DoubleDeque
-1
if the element
was not found.public int bufferIndexOf(double e1)
e1
. The index points to the buffer
array.e1
- The element to look for.e1
or
-1
if not found.public int removeLast(double e1)
e
.removeLast
in interface DoubleDeque
-1
if the element
was not found.public int lastBufferIndexOf(double e1)
e1
. The index points to the buffer
array.e1
- The element to look for.e1
or
-1
if not found.public int removeAll(double e1)
e
from this collection.removeAll
in interface DoubleCollection
e1
- Element to be removed from this collection, if present.public void removeAtBufferIndex(int index)
index
in the internal {#link
buffer
array, returning its value.public boolean isEmpty()
size() == 0
.isEmpty
in interface DoubleContainer
public int size()
O(n)
time, although
implementing classes should try to maintain the current size and return in
constant time.size
in interface DoubleContainer
public void clear()
The internal array buffers are not released as a result of this call.
clear
in interface DoubleCollection
release()
public void release()
release
in interface DoubleCollection
DoubleCollection.clear()
public void ensureCapacity(int expectedElements)
ensureCapacity
in interface Preallocable
expectedElements
- The total number of elements, inclusive.protected void ensureBufferSpace(int expectedAdditions)
expectedAdditions
. Increases internal buffer size if needed.public double[] toArray()
toArray
in interface DoubleContainer
public double[] toArray(double[] target)
target
array is filled from index 0 (head of the queue) to
index size() - 1
(tail of the queue).target
- The target array must be large enough to hold all elements.public DoubleArrayDeque clone()
clone
in class java.lang.Object
protected static int oneLeft(int index, int modulus)
protected static int oneRight(int index, int modulus)
public java.util.Iterator<DoubleCursor> 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 DoubleContainer
iterator
in interface java.lang.Iterable<DoubleCursor>
public java.util.Iterator<DoubleCursor> 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 (Iterator<IntCursor> i = intDeque.descendingIterator(); i.hasNext();) { final IntCursor c = i.next(); System.out.println("buffer index=" + c.index + " value=" + c.value); }
descendingIterator
in interface DoubleDeque
public <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 DoubleContainer
public <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 DoubleContainer
public <T extends DoubleProcedure> T descendingForEach(T procedure)
procedure
to all elements of this deque, tail to head.descendingForEach
in interface DoubleDeque
public <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 DoubleDeque
public int removeAll(DoublePredicate predicate)
true
.removeAll
in interface DoubleCollection
public boolean contains(double e)
contains
in interface DoubleContainer
true
if this container has an element equal to
e
.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
true
only if the other object is an instance of
the same class and with the same elements.equals
in class java.lang.Object
protected boolean equalElements(DoubleArrayDeque other)
DoubleDeque
.public static DoubleArrayDeque from(double... elements)
public int removeAll(DoubleLookupContainer c)
removeAll
in interface DoubleCollection
public int retainAll(DoubleLookupContainer c)
retainAll
in interface DoubleCollection
public int retainAll(DoublePredicate predicate)
DoubleCollection.removeAll(DoublePredicate)
and
negates the predicate.retainAll
in interface DoubleCollection
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2015 Carrot Search s.c.. All Rights Reserved.