public class InfiniteBufferInt extends java.lang.Object implements ChannelDataStoreInt, java.io.Serializable
Channel
(Channel.one2oneInt(org.jcsp.util.ints.ChannelDataStoreInt) etc.).
The getState method returns EMPTY or NONEMPTYFULL, but never FULL.
An initial size for the buffer can be specified during construction.
| Modifier and Type | Field and Description |
|---|---|
private int[] |
buffer
The storage for the buffered ints
|
private int |
counter
The number of ints stored in the InfiniteBufferInt
|
private static int |
DEFAULT_SIZE
The default size of the buffer
|
private int |
firstIndex
The index of the oldest element (when counter > 0)
|
private int |
initialSize
The initial size of the buffer
|
private int |
lastIndex
The index of the next free element (when counter < buffer.length)
|
EMPTY, FULL, NONEMPTYFULL| Constructor and Description |
|---|
InfiniteBufferInt()
Construct a new InfiniteBufferInt with the default size (of 8).
|
InfiniteBufferInt(int initialSize)
Construct a new InfiniteBufferInt with the specified initial size.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
clone()
Returns a new (and EMPTY) InfiniteBufferInt with the same
creation parameters as this one.
|
void |
endGet()
Removes the oldest integer from the buffer.
|
int |
get()
Returns the oldest int from the InfiniteBufferInt and removes it.
|
int |
getState()
Returns the current state of the InfiniteBufferInt.
|
void |
put(int value)
Puts a new int into the InfiniteBufferInt.
|
void |
removeAll() |
int |
startGet()
Returns the oldest integer from the buffer but does not remove it.
|
private static final int DEFAULT_SIZE
private int initialSize
private int[] buffer
private int counter
private int firstIndex
private int lastIndex
public InfiniteBufferInt()
public InfiniteBufferInt(int initialSize)
initialSize - the number of ints
the InfiniteBufferInt can initially store.BufferIntSizeError - if initialSize is zero or negative. Note: no action
should be taken to try/catch this exception
- application code generating it is in error and needs correcting.public int get()
Pre-condition: getState must not currently return EMPTY.
get in interface ChannelDataStoreIntpublic int startGet()
startGet in interface ChannelDataStoreIntChannelDataStoreInt.endGet()public void endGet()
endGet in interface ChannelDataStoreIntChannelDataStoreInt.startGet()public void put(int value)
Implementation note: if InfiniteBufferInt is full, a new internal buffer with double the capacity is constructed and the old data copied across.
put in interface ChannelDataStoreIntvalue - the int to put into the InfiniteBufferIntpublic int getState()
getState in interface ChannelDataStoreIntpublic java.lang.Object clone()
Note: Only the initial size and structure of the InfiniteBufferInt is cloned, not any stored data.
clone in interface ChannelDataStoreIntclone in class java.lang.Objectpublic void removeAll()
removeAll in interface ChannelDataStoreInt