public abstract class ItemBuffer<T> extends Object implements Iterable<T>
Copyright: Copyright 2003-2014, Knowledge Science Group, University of Calgary. Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. The Knowledge Science Group makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.
Modifier and Type | Field and Description |
---|---|
private LinkedList<T> |
items
refers to the actual underlying data structure being used
|
Modifier | Constructor and Description |
---|---|
protected |
ItemBuffer()
Constructs an empty ItemBuffer
|
Modifier and Type | Method and Description |
---|---|
boolean |
contains(T item) |
protected T |
getItem()
Returns the first object in the list
|
protected int |
insertPos(T item)
Template method to be overridden to change the behaviour of
method putItem().
|
boolean |
isEmpty()
Returns true iff the buffer is empty
|
Iterator<T> |
iterator()
Warning: the returned iterator is NOT synchronized.
|
protected void |
notifyNewItem(T item)
This method is called whenever
putItem(Object) is called. |
protected T |
peek() |
protected void |
putItem(T item)
Inserts the item into the buffer at the position specified by
the insertPos(item) method.
|
protected boolean |
remove(Object o) |
int |
size()
Returns the number of items in the buffer
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
private LinkedList<T> items
protected T getItem()
protected boolean remove(Object o)
protected T peek()
protected void putItem(T item)
item
- object to insert into the listprotected void notifyNewItem(T item)
putItem(Object)
is called. Subclasses
should override to provide the actual behaviour. This method does nothing.item
- the item that was queuedpublic boolean isEmpty()
protected int insertPos(T item)
item
- the item to decide where to put in the bufferpublic int size()
public boolean contains(T item)