org.ddogleg.struct
Class CircularQueue<T>
- java.lang.Object
-
- org.ddogleg.struct.CircularQueue<T>
-
public class CircularQueue<T> extends java.lang.ObjectA circular queue which can grow as needed.
-
-
Constructor Summary
Constructors Constructor and Description CircularQueue(java.lang.Class<T> type)CircularQueue(java.lang.Class<T> type, int maxSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidadd(T value)Adds a new element to the queue.voidaddW(T value)Adds a new element to the queue, but if the queue is full write over the oldest element.Tget(int index)Returns the element in the queue at index.Tgrow()Adds a new element to the end of the list and returns it.TgrowW()Adds a new element to the end of the list and returns it.Thead()Value of the first element in the queuebooleanisEmpty()booleanisFull()TpopHead()Returns and removes the first element from the queue.TpopTail()Returns and removes the last element from the queue.voidremoveHead()Removes the first elementvoidremoveTail()Removes the last elementvoidreset()intsize()Ttail()Value of the last element in the queue
-
-
-
Field Detail
-
data
public T[] data
-
start
public int start
-
size
public int size
-
-
Constructor Detail
-
CircularQueue
public CircularQueue(java.lang.Class<T> type)
-
CircularQueue
public CircularQueue(java.lang.Class<T> type, int maxSize)
-
-
Method Detail
-
reset
public void reset()
-
popHead
public T popHead()
Returns and removes the first element from the queue.- Returns:
- first element in the queue
-
popTail
public T popTail()
Returns and removes the last element from the queue.- Returns:
- last element in the queue
-
head
public T head()
Value of the first element in the queue
-
tail
public T tail()
Value of the last element in the queue
-
removeHead
public void removeHead()
Removes the first element
-
removeTail
public void removeTail()
Removes the last element
-
get
public T get(int index)
Returns the element in the queue at index. No bounds check is performed and a garbage value might be returned.- Parameters:
index- Which element in the queue you wish to access- Returns:
- the element's value
-
grow
public T grow()
Adds a new element to the end of the list and returns it. If the inner array isn't large enough then it will grow.- Returns:
- instance at the tail
-
growW
public T growW()
Adds a new element to the end of the list and returns it. If the inner array isn't large enough then the oldest element will be written over.- Returns:
- instance at the tail
-
add
public void add(T value)
Adds a new element to the queue. If the queue isn't large enough to store this value then its internal data array will grow- Parameters:
value- Value which is to be added
-
addW
public void addW(T value)
Adds a new element to the queue, but if the queue is full write over the oldest element.- Parameters:
value- Value which is to be added
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
isFull
public boolean isFull()
-
-
DataMelt 3.0 © DataMelt by jWork.ORG