public class CircularIndex extends Object
| Constructor and Description |
|---|
CircularIndex(long capacity)
Creates a circular index based on a fixed capacity of elements.
|
CircularIndex(long capacity,
boolean resetOnZero) |
CircularIndex(long capacity,
long first,
long size) |
CircularIndex(long capacity,
long first,
long size,
boolean resetOnZero)
Creates a circular index based on a fixed capacity of elements.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addFirst()
Adds an element to the front of the index if its not full.
|
boolean |
addLast()
Adds an element to the back of the index if its not full.
|
protected long |
calculateNewIndex(long index,
long offset) |
long |
getCapacity()
Gets the underlying capacity of the index.
|
long |
getFirst()
Gets the index to the first element if it exists.
|
protected long |
getInternalFirst()
protected methods just for testing purposes
|
protected long |
getInternalNext() |
long |
getLast()
Gets the index to the last element if it exists.
|
long |
getMaxSize()
Gets the maximum number of elements this index can support.
|
long |
getNextFirst()
Gets the index where the next first element will be put.
|
long |
getNextLast()
Gets the index where the next last element will be put.
|
long |
getSize()
Gets the current number of elements in this index.
|
boolean |
isEmpty()
Checks if the index is currently empty (contains no elements).
|
boolean |
isFull()
Checks if the index is currently full (contains all elements).
|
boolean |
removeFirst()
Removes the first element from the front of the index if its not empty.
|
boolean |
removeLast()
Removes the last element from the back of the index if its not empty.
|
void |
reset()
Resets index back to defaults with a zero size and no elements.
|
String |
toString() |
public CircularIndex(long capacity)
capacity - The fixed capacity of elements. If this index is to be
used with an array, the capacity should match the capacity of the
array. Must be > 0.public CircularIndex(long capacity,
boolean resetOnZero)
public CircularIndex(long capacity,
long first,
long size)
public CircularIndex(long capacity,
long first,
long size,
boolean resetOnZero)
capacity - The fixed capacity of elements. If this index is to be
used with an array, the capacity should match the capacity of the
array. Must be > 0.first - The initial index of the first element. This must be within
the range based on the capacity.size - The number of elements contained within the index. Used in
conjunction with the first element index to calculate the "next"
index used internally. Can be set to zero in order to control
which will be the index of the first element added.resetOnZero - Controls whether this index should automatically reset
when the size hits zero. A reset sets the first and next indexes
back to their defaults.public void reset()
public long getCapacity()
public long getMaxSize()
public long getSize()
public boolean isEmpty()
public boolean isFull()
protected long calculateNewIndex(long index,
long offset)
public boolean addLast()
public boolean addFirst()
public boolean removeLast()
public boolean removeFirst()
public long getFirst()
public long getLast()
public long getNextLast()
public long getNextFirst()
protected long getInternalFirst()
protected long getInternalNext()
Copyright © 2012-2015 Cloudhopper by Twitter. All Rights Reserved.