|
Rakesh API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.rakeshv.utils.SimpleFIFO<T>
public class SimpleFIFO<T>
A First In First Out
implementation using an array.
SharedObject,
Copyright 2002-2006 Rakesh Vidyadharan
| Field Summary | |
|---|---|
private T[] |
fifo
An array that is used to implement a FIFO. |
private boolean |
filled
A flag to indicate that the fifo has been filled. |
private int |
index
A variable that holds the index into the fifo at which
a new instance is to be added. |
| Fields inherited from interface org.rakeshv.utils.DataStructure |
|---|
DYNAMIC, FIFO, FIFO_IMPLEMENTATION, LRU, LRU_IMPLEMENTATION |
| Constructor Summary | |
|---|---|
SimpleFIFO(int size)
Construct a new FIFO of the specified size. |
|
| Method Summary | |
|---|---|
void |
add(T object)
Add the specified object to fifo. |
void |
clear()
Removes all the objects from the fifo. |
T |
get()
Return the current Object in the fifo. |
T |
remove()
Removes the current Object designated for removal
(located at index) from the fifo. |
boolean |
remove(T object)
Removes the specified object from the fifo. |
int |
size()
Returns the size of the fifo. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private T[] fifo
FIFO.
private int index
fifo at which
a new instance is to be added. The index rolls around
from the end of the fifo to the beginning when the fifo
is full.
private boolean filled
| Constructor Detail |
|---|
public SimpleFIFO(int size)
FIFO of the specified size.
| Method Detail |
|---|
public T get()
Object in the fifo. This
is the object that will be replaced when the next call to
add( Object ) is made.
get in interface DataStructure<T>index within the fifo.
This will be null if the fifo has not been
filled yet.public void add(T object)
fifo. Updates the index after adding the specified object to the next location
in the fifo. Sets filled to true when the
index rolls around to the beginning of the fifo for the
first time.
Note: This method does not perform any
synchronisation, and hence is not thread-safe.
Client's must perform their own synchronisation if they so desire.
add in interface DataStructure<T>object - The object to be added to the fifo.
java.lang.IllegalArgumentException - If a null value was
specified for the object.public T remove()
Object designated for removal
(located at index) from the fifo.
remove in interface DataStructure<T>public boolean remove(T object)
fifo. The time to
remove the specified object will be directly proportional to the
size of the fifo.
This operation can be very heavy, since it involves iterating through the fifo. The following conditions apply:
index to point to the end of the fifo
or to the previous position depending upon whether the fifo was
filled or not.
== operator), and not the equivalent matching rule
(the Object.equals( Object )) operator.
If there are multiple instances of the same object in the fifo, only the first matching object is removed.
Note: This method does not perform any
synchronisation, and hence is not thread-safe.
Client's must perform their own synchronisation if they so desire.
remove in interface DataStructure<T>object - The object that is to be removed from the fifo.
true if the specified object was
found and removed from the fifo.public void clear()
fifo. The most
efficient way to do it is to create a new instance of the fifo
array, and consign the old instance to the garbage collector.
Note: This method does not perform any
synchronisation, and hence is not thread-safe.
Client's must perform their own synchronisation if they so desire.
clear in interface DataStructure<T>public int size()
fifo. Returns the total size
of the fifo, if the fifo has been filled, else returns
the index value.
size in interface DataStructure<T>
|
Rakesh API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||