Class IntDeque
- java.lang.Object
-
- com.electronwill.nightconfig.core.utils.IntDeque
-
public final class IntDeque extends java.lang.ObjectA deque of integers that increases its capacity as necessary. Since it's a deque, it can be used as a FIFO (First-In-First-Out) queue and as a LIFO (Last-In-First-Out) stack.- See Also:
Deque
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFirst(int element)Inserts an element before the head of this deque.voidaddLast(int element)Inserts an element at the tail of this deque.voidclear()Clears this deque.voidcompact()Compacts this deque, minimizing its size in memory.intget(int index)Gets the element at the specified index of this deque, without removing it.intgetFirst()Gets the first element (head) of this deque without removing it.intgetLast()Gets the last element of this deque without removing it.booleanisEmpty()intremoveFirst()Retrieves and removes the first element (head) of this deque.intremoveLast()Retrieves and removes the last element of this deque.intsize()
-
-
-
Constructor Detail
-
IntDeque
public IntDeque()
Creates a new IntDeque with an initial capacity of 4.
-
IntDeque
public IntDeque(int initialCapacity)
Creates a new IntDeque with the specified initial capacity. The capacity must be positive and non-zero.- Parameters:
initialCapacity- the initial capacity, strictly positive
-
-
Method Detail
-
clear
public void clear()
Clears this deque. After a call of this method, the size of the deque will be zero.
-
isEmpty
public boolean isEmpty()
- Returns:
- true if the deque is empty, false if it's not
-
size
public int size()
- Returns:
- the size of the deque
-
compact
public void compact()
Compacts this deque, minimizing its size in memory.
-
addFirst
public void addFirst(int element)
Inserts an element before the head of this deque. The deque increases its capacity if necessary.- Parameters:
element- the element to add
-
addLast
public void addLast(int element)
Inserts an element at the tail of this deque. The deque increases its capacity if necessary.- Parameters:
element- the element to add
-
get
public int get(int index)
Gets the element at the specified index of this deque, without removing it.The index is relative to the head: the first element is at index 0, the next element is at index 1, etc.
- Parameters:
index- the index of the element, relative to the head- Returns:
- the element at the specified index
- Throws:
java.util.NoSuchElementException- if the deque contains less thanindex+1elements
-
getFirst
public int getFirst()
Gets the first element (head) of this deque without removing it.- Returns:
- the first element of this deque
- Throws:
java.util.NoSuchElementException- if the deque is empty
-
getLast
public int getLast()
Gets the last element of this deque without removing it.- Returns:
- the last element of this deque
- Throws:
java.util.NoSuchElementException- if the deque is empty
-
removeFirst
public int removeFirst()
Retrieves and removes the first element (head) of this deque.- Returns:
- the first element of this deque
- Throws:
java.util.NoSuchElementException- if the deque is empty
-
removeLast
public int removeLast()
Retrieves and removes the last element of this deque.- Returns:
- the last element of this deque
- Throws:
java.util.NoSuchElementException- if the deque is empty
-
-