DataType
- Type of data contained in the buffer@CodeReview(reviewer="Kevin R. Dixon", date="2008-02-08", changesNeeded=false, comments={"Cleaned up minor formatting issues.","Added class documentation about running times and usage of LinkedList."}) public class FiniteCapacityBuffer<DataType> extends java.util.AbstractList<DataType> implements CloneableSerializable
Modifier and Type | Class and Description |
---|---|
protected class |
FiniteCapacityBuffer.InternalIterator
Iterator for FiniteCapacityBuffer
|
Constructor and Description |
---|
FiniteCapacityBuffer()
Default constructor with capacity of one.
|
FiniteCapacityBuffer(FiniteCapacityBuffer<DataType> other)
Copy constructor.
|
FiniteCapacityBuffer(int capacity)
Creates a new instance of FiniteCapacityBuffer.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(DataType e)
Appends the element to the end of the buffer, removing excess elements
if necessary
|
boolean |
addFirst(DataType e)
Prepend the element to the beginning of the buffer, removing excess
elements if necessary
|
boolean |
addLast(DataType e)
Appends the element to the end of the buffer, removing excess elements
if necessary
|
void |
clear() |
FiniteCapacityBuffer<DataType> |
clone()
Creates a new clone (shallow copy) of this object.
|
protected int |
convert(int index)
Converts the given index from zero-based world to circular world
|
DataType |
get(int index) |
int |
getCapacity()
Gets the capacity of the buffer, which is the maximum number of elements
that can be stored in it.
|
DataType |
getFirst()
Returns the first element in the list.
|
DataType |
getLast()
Returns the last element in the list.
|
boolean |
isFull()
Returns true if the finite-capacity buffer is full.
|
java.util.Iterator<DataType> |
iterator() |
DataType |
remove(int index) |
boolean |
remove(java.lang.Object o) |
DataType |
set(int index,
DataType element) |
void |
setCapacity(int capacity)
Sets the capacity of the buffer, which is the maximum number of elements
that can be stored in it.
|
int |
size() |
add, addAll, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, removeRange, subList
addAll, contains, containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
public FiniteCapacityBuffer()
public FiniteCapacityBuffer(int capacity)
capacity
- Maximum capacity of the buffer.public FiniteCapacityBuffer(FiniteCapacityBuffer<DataType> other)
other
- FiniteCapacityBuffer to copy.public FiniteCapacityBuffer<DataType> clone()
CloneableSerializable
clone
in interface CloneableSerializable
clone
in class java.lang.Object
public int size()
public java.util.Iterator<DataType> iterator()
public boolean add(DataType e)
public boolean remove(java.lang.Object o)
public DataType remove(int index)
protected int convert(int index)
index
- Index to convert to circular worldpublic void clear()
public boolean addFirst(DataType e)
e
- DataType to addFirst to the bufferpublic boolean addLast(DataType e)
e
- DataType to add to the bufferpublic DataType getFirst()
public DataType getLast()
public boolean isFull()
public int getCapacity()
public void setCapacity(int capacity)
capacity
- The maximum capacity of the buffer. Must be greater than zero.public DataType get(int index)