public class Buffer<T> extends ChannelValueStore<T>
The Buffer class is an implementation of ChannelValueStore which allows more than one Object to be sent across the Channel at any one time. The Buffer will store the Objects and allow them to be read in the same order as they were written.
The getState method will return EMPTY if the Channel does not contain any Objects, FULL if it cannot accept more data and NONEMPTYFULL otherwise.
EMPTY, FULL, NONEMPTYFULL| Constructor and Description |
|---|
Buffer()
Construct a new Buffer with no maximum size.
|
Buffer(int maxSize)
Construct a new Buffer with the specified maximum size.
|
Buffer(Queue<T> buffer)
Construct a new Buffer with the no maximum size.
|
Buffer(Queue<T> buffer,
int maxSize)
Construct a new Buffer with the specified maximum size.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Empty the buffer.
|
protected Object |
clone()
Returns a new Object with the same creation parameters as this Object.
|
protected T |
get()
Returns the first Object from the Buffer and removes the Object from the
Buffer.
|
protected int |
getState()
Returns the current state of the Buffer, should be called to ensure the
Pre-conditions of the other methods are not broken.
|
protected void |
put(T value)
Puts a new Object into the Buffer.
|
boolean |
remove(T object)
Remove the object from the buffer.
|
int |
size()
The number of items in the buffer.
|
String |
toString() |
public Buffer()
public Buffer(int maxSize)
maxSize - The maximum number of Objects the Buffer can storepublic Buffer(Queue<T> buffer)
buffer - The buffer to store the elements in.public void clear()
protected Object clone()
clone in class ChannelValueStore<T>protected T get()
NOTE: getState should be called before this method to check that the state is not EMPTY. If the state is EMPTY the Buffer will be left in an undefined state.
Pre-condition: The state must not be EMPTY
get in class ChannelValueStore<T>protected int getState()
getState in class ChannelValueStore<T>protected void put(T value)
NOTE: getState should be called before this method to check that the state is not FULL. If the state is FULL the Buffer will be left in an undefined state.
Pre-condition: The state must not be FULL
put in class ChannelValueStore<T>value - The object to put in the Bufferpublic boolean remove(T object)
object - The object to remove.public int size()
Copyright © 2015 Revolution Systems Inc.. All rights reserved.