|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectutil.Shelf<E>
public class Shelf<E>
A Shelf is an implementation of a special queue. It has a distinct size, specified at construct. Adding values to the end of the queue behaves normally, until the size is reached. Further addition of objects to the end of the Shelf result in the loss of the very first object.
Implementation detail: A LinkedList is used by the shelf. Unwanted methods, like add(int, Object) throw an UnsupportedOperationException.
To avoid unwanted functions to be available, we do not subclass but rather compose this Shelf from a LinkedList
| Field Summary | |
|---|---|
private int |
accumulated
The number of elements added during the liftime of the shelf. |
static int |
DEFSIZE
The default size of a shelf. |
private int |
maxsize
The defined maximal size of the shelf. |
private E |
recent
The most recently removed object. |
private LinkedList<E> |
shelflist
The backing linked list of this shelf. |
| Constructor Summary | |
|---|---|
Shelf()
Creates a Shelf with the default size. |
|
Shelf(Collection<E> all)
Creates a Shelf from a collection. |
|
Shelf(Collection<E> all,
int max)
Creates a Shelf from a collection. |
|
Shelf(int max)
Creates a Shelf with the given size. |
|
| Method Summary | ||
|---|---|---|
int |
accumulated()
Returns the cummulated number of items. |
|
boolean |
add(E toadd)
Adds the object to the end of the list. |
|
void |
add(int index,
E toadd)
Removes the first element, if the new list is too big. |
|
boolean |
addAll(Collection<? extends E> toadd)
Only allowed if the size of the collection is less then the maximum size. |
|
boolean |
addAll(int index,
Collection<? extends E> toadd)
Not supported. |
|
void |
clear()
Empties the shelf, resets the accumulated count to zero. |
|
boolean |
contains(Object that)
Returns true if this list contains the specified element. |
|
boolean |
containsAll(Collection<?> that)
Returns true if this list contains all specified element. |
|
boolean |
equals(Object that)
Returns true, if two shelfs are equal. |
|
E |
get(int index)
Returns the Object on the given index. |
|
E |
getFirst()
Returns the first element in this Shelf. |
|
E |
getLast()
Returns the last element in the Shelf. |
|
int |
getMaxSize()
Used for equals method. |
|
(package private) LinkedList |
getShelf()
Used for equals method. |
|
int |
hashCode()
Returns a unique hash code. |
|
int |
indexOf(Object that)
Returns the index of the specified object. |
|
boolean |
isEmpty()
Returns true if the shelf is empty. |
|
boolean |
isFull()
Returns true, if the shelf is full. |
|
Iterator<E> |
iterator()
Returns an iterator over the shelf's objects. |
|
int |
lastIndexOf(Object that)
Returns the last index of the specified object. |
|
ListIterator<E> |
listIterator()
Returns a list iterator of the shelf's objects. |
|
ListIterator<E> |
listIterator(int index)
Returns a list iterator of the elements in this Shelf. |
|
Object |
recentlyRemoved()
Returns the object that has just fallen off the shelf. |
|
E |
remove(int index)
Removes and returns the Object on the specified index. |
|
boolean |
remove(Object that)
Removes the specified object, if possible. |
|
boolean |
removeAll(Collection<?> that)
Remove all Objects specified. |
|
E |
removeFirst()
Returns and removes the first element in this Shelf. |
|
E |
removeLast()
Returns and removes the last element in the Shelf. |
|
boolean |
retainAll(Collection<?> that)
Retain only the specified objects. |
|
E |
set(int index,
E that)
Sets the object on the specified index. |
|
int |
size()
Return the actual size of the Shelf. |
|
List<E> |
subList(int from,
int to)
Returns a part of the Shelf as a list. |
|
Object[] |
toArray()
Returns all elements in this Shelf in proper sequence. |
|
|
toArray(T[] type)
Returns all elements in this Shelf in proper sequence using the same type of object as specified in the argument. |
|
String |
toString()
Returns my internale list as a string. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFSIZE
private int maxsize
private int accumulated
private LinkedList<E> shelflist
private E recent
add(int, E).
| Constructor Detail |
|---|
public Shelf()
public Shelf(int max)
public Shelf(Collection<E> all)
public Shelf(Collection<E> all,
int max)
| Method Detail |
|---|
public void add(int index,
E toadd)
add in interface List<E>public boolean add(E toadd)
recentlyRemoved() method.
add in interface Collection<E>add in interface List<E>toadd - The object to put on the shelf.
public Object recentlyRemoved()
add(int, E) to get the object that was removed when
the new object was inserted.
public boolean addAll(Collection<? extends E> toadd)
addAll in interface Collection<E>addAll in interface List<E>
public boolean addAll(int index,
Collection<? extends E> toadd)
addAll in interface List<E>public void clear()
clear in interface Collection<E>clear in interface List<E>public boolean contains(Object that)
contains in interface Collection<E>contains in interface List<E>that - The object to search.public boolean containsAll(Collection<?> that)
containsAll in interface Collection<E>containsAll in interface List<E>that - The Collection to search.LinkedList getShelf()
public int getMaxSize()
public boolean isFull()
public boolean equals(Object that)
equals in interface Collection<E>equals in interface List<E>equals in class Objectthat - The Shelf this one should be compared to.public E get(int index)
get in interface List<E>index - The index of the object to retrieve.public E getFirst()
public E removeFirst()
public E getLast()
public E removeLast()
public int hashCode()
hashCode in interface Collection<E>hashCode in interface List<E>hashCode in class Objectpublic int indexOf(Object that)
indexOf in interface List<E>public boolean isEmpty()
isEmpty in interface Collection<E>isEmpty in interface List<E>public Iterator<E> iterator()
iterator in interface Iterable<E>iterator in interface Collection<E>iterator in interface List<E>public int lastIndexOf(Object that)
lastIndexOf in interface List<E>public ListIterator<E> listIterator()
listIterator in interface List<E>public ListIterator<E> listIterator(int index)
listIterator in interface List<E>public E remove(int index)
remove in interface List<E>public boolean remove(Object that)
remove in interface Collection<E>remove in interface List<E>that - The object to remove.public boolean removeAll(Collection<?> that)
removeAll in interface Collection<E>removeAll in interface List<E>that - The collection to remove.public boolean retainAll(Collection<?> that)
retainAll in interface Collection<E>retainAll in interface List<E>that - The collection to keep.
public E set(int index,
E that)
set in interface List<E>index - The index, where the object should squeeze in.that - The object to set.
public int size()
size in interface Collection<E>size in interface List<E>public int accumulated()
public List<E> subList(int from,
int to)
subList in interface List<E>from - The index to start (inclusively).to - The index to end (exclusively).public Object[] toArray()
toArray in interface Collection<E>toArray in interface List<E>public <T> T[] toArray(T[] type)
toArray in interface Collection<E>toArray in interface List<E>type - The object template.public String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||