public class Queue<T> extends Object implements Iterable<T>
removeLast()
and addFirst(Object)
.Modifier and Type | Class and Description |
---|---|
static class |
Queue.QueueIterable<T> |
static class |
Queue.QueueIterator<T> |
Modifier and Type | Field and Description |
---|---|
int |
size
Number of elements in the queue.
|
Constructor and Description |
---|
Queue()
Creates a new Queue which can hold 16 values without needing to resize backing array.
|
Queue(int initialSize)
Creates a new Queue which can hold the specified number of values without needing to resize backing array.
|
Queue(int initialSize,
Class<T> type)
Creates a new Queue which can hold the specified number of values without needing to resize backing array.
|
Modifier and Type | Method and Description |
---|---|
void |
addFirst(T object)
Prepend given object to the head.
|
void |
addLast(T object)
Append given object to the tail.
|
void |
clear()
Removes all values from this queue.
|
void |
ensureCapacity(int additional)
Increases the size of the backing array to accommodate the specified number of additional items.
|
boolean |
equals(Object o) |
T |
first()
Returns the first (head) item in the queue (without removing it).
|
T |
get(int index)
Retrieves the value in queue without removing it.
|
int |
hashCode() |
int |
indexOf(T value,
boolean identity)
Returns the index of first occurrence of value in the queue, or -1 if no such value exists.
|
Iterator<T> |
iterator()
Returns an iterator for the items in the queue.
|
T |
last()
Returns the last (tail) item in the queue (without removing it).
|
T |
removeFirst()
Remove the first item from the queue.
|
T |
removeIndex(int index)
Removes and returns the item at the specified index.
|
T |
removeLast()
Remove the last item from the queue.
|
boolean |
removeValue(T value,
boolean identity)
Removes the first instance of the specified value in the queue.
|
String |
toString() |
forEach, spliterator
public Queue()
public Queue(int initialSize)
public void addLast(T object)
object
- can be nullpublic void addFirst(T object)
object
- can be nulladdLast(Object)
public void ensureCapacity(int additional)
public T removeFirst()
NoSuchElementException
- when queue is emptypublic T removeLast()
NoSuchElementException
- when queue is emptyremoveFirst()
public int indexOf(T value, boolean identity)
identity
- If true, == comparison will be used. If false, .equals() comparison will be used.public boolean removeValue(T value, boolean identity)
identity
- If true, == comparison will be used. If false, .equals() comparison will be used.public T removeIndex(int index)
public T first()
NoSuchElementException
- when queue is emptyaddFirst(Object)
,
removeFirst()
public T last()
NoSuchElementException
- when queue is emptyaddLast(Object)
,
removeLast()
public T get(int index)
first()
.IndexOutOfBoundsException
- when the index is negative or >= sizepublic void clear()
public Iterator<T> iterator()
Queue.QueueIterator
constructor for nested or multithreaded iteration.Copyright © 2017. All rights reserved.