public class BufferInt extends java.lang.Object implements ChannelDataStoreInt, java.io.Serializable
Channel
(Channel.one2oneInt(org.jcsp.util.ints.ChannelDataStoreInt)
etc.).
The getState method returns EMPTY, NONEMPTYFULL or FULL according to the state of the buffer.
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 BufferInt
|
private int |
firstIndex
The index of the oldest element (when counter > 0)
|
private int |
lastIndex
The index of the next free element (when counter < buffer.length)
|
EMPTY, FULL, NONEMPTYFULL
Constructor and Description |
---|
BufferInt(int size)
Construct a new BufferInt with the specified size.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Returns a new (and EMPTY) BufferInt 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 BufferInt and removes it.
|
int |
getState()
Returns the current state of the BufferInt.
|
void |
put(int value)
Puts a new int into the BufferInt.
|
void |
removeAll() |
int |
startGet()
Returns the oldest integer from the buffer but does not remove it.
|
private final int[] buffer
private int counter
private int firstIndex
private int lastIndex
public BufferInt(int size)
size
- the number of ints the BufferInt can store.BufferIntSizeError
- if size is 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 ChannelDataStoreInt
public int startGet()
startGet
in interface ChannelDataStoreInt
ChannelDataStoreInt.endGet()
public void endGet()
endGet
in interface ChannelDataStoreInt
ChannelDataStoreInt.startGet()
public void put(int value)
Pre-condition: getState must not currently return FULL.
put
in interface ChannelDataStoreInt
value
- the int to put into the BufferIntpublic int getState()
getState
in interface ChannelDataStoreInt
public java.lang.Object clone()
Note: Only the size and structure of the BufferInt is cloned, not any stored data.
clone
in interface ChannelDataStoreInt
clone
in class java.lang.Object
public void removeAll()
removeAll
in interface ChannelDataStoreInt