|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.dhmp.util.AbstractCollection org.dhmp.util.AbstractList org.dhmp.util.AbstractSequentialList org.dhmp.util.LinkedList org.dhmp.util.CircularQueue
Circular Queue is a queue implemented using linked list that reuse the existent entries to store new data or appends new entry if all existent entries are not free (for instance value has added but still has not read). Once the value has read using get(), the corresponding entry is freed. Therefore the size of this linkedlist is the number of entries in a queue during the peak. Use shrink() to free-up unused entries.
Nested Class Summary | |
class |
CircularQueue.CircularQueueEntry
|
protected static class |
LinkedList.Entry
Class to represent an entry in the list. |
Field Summary | |
protected LinkedList.Entry |
first
The first element in the list. |
protected CircularQueue.CircularQueueEntry |
head
|
protected LinkedList.Entry |
last
The last element in the list. |
protected int |
modCount
A count of the number of structural modifications that have been made to the list (that is, insertions and removals). |
protected int |
size
The current length of the list. |
protected CircularQueue.CircularQueueEntry |
tail
|
Constructor Summary | |
CircularQueue()
Creates a new instance of CircularQueue |
Method Summary | |
void |
add(int index,
java.lang.Object o)
Inserts an element in the given position in the list. |
boolean |
add(java.lang.Object o)
Adds an element to the end of the list. |
protected void |
addAfter(LinkedList.Entry e,
java.lang.Object o)
|
boolean |
addAll(java.util.Collection c)
Append the elements of the collection in iteration order to the end of this list. |
boolean |
addAll(int index,
java.util.Collection c)
Insert the elements of the collection in iteration order at the given index of this list. |
void |
addFirst(java.lang.Object o)
Insert an element at the first of the list. |
void |
addLast(java.lang.Object o)
Insert an element at the last of the list. |
void |
clear()
Remove all elements from this list. |
java.lang.Object |
clone()
Create a shallow copy of this LinkedList (the elements are not cloned). |
boolean |
contains(java.lang.Object o)
Returns true if the list contains the given object. |
boolean |
containsAll(java.util.Collection c)
Tests whether this collection contains all the elements in a given collection. |
boolean |
equals(java.lang.Object o)
Test whether this list is equal to another object. |
java.lang.Object |
get()
|
java.lang.Object |
get(int index)
Return the element at index. |
protected LinkedList.Entry |
getEntry()
|
java.lang.Object |
getFirst()
Returns the first element in the list. |
java.lang.Object |
getLast()
Returns the last element in the list. |
int |
hashCode()
Obtains a hash code for this list. |
int |
indexOf(java.lang.Object o)
Returns the first index where the element is located in the list, or -1. |
boolean |
isEmpty()
Test whether this collection is empty. |
java.util.Iterator |
iterator()
Obtain an Iterator over this list, whose sequence is the list order. |
int |
lastIndexOf(java.lang.Object o)
Returns the last index where the element is located in the list, or -1. |
java.util.ListIterator |
listIterator()
Obtain a ListIterator over this list, starting at the beginning. |
java.util.ListIterator |
listIterator(int index)
Obtain a ListIterator over this list, starting at a given index. |
LinkedList.Entry |
newEntry(java.lang.Object o)
Extension point for inferited class. |
java.lang.Object |
remove(int index)
Removes the element at the given position from the list. |
boolean |
remove(java.lang.Object o)
Removes the entry at the lowest index in the list that matches the given object, comparing by if o equals null, then compare if e equals null otherwise return o equals e. |
boolean |
removeAll(java.util.Collection c)
Remove from this collection all its elements that are contained in a given collection (optional operation). |
java.lang.Object |
removeFirst()
Remove and return the first element in the list. |
java.lang.Object |
removeLast()
Remove and return the last element in the list. |
protected void |
removeRange(int fromIndex,
int toIndex)
Remove a subsection of the list. |
boolean |
retainAll(java.util.Collection c)
Remove from this collection all its elements that are not contained in a given collection (optional operation). |
java.lang.Object |
set(int index,
java.lang.Object o)
Replace the element at the given location in the list. |
void |
shrink()
|
int |
size()
Returns the size of the list. |
java.util.List |
subList(int fromIndex,
int toIndex)
Obtain a List view of a subsection of this list, from fromIndex (inclusive) to toIndex (exclusive). |
java.lang.Object[] |
toArray()
Returns an array which contains the elements of the list in order. |
java.lang.Object[] |
toArray(java.lang.Object[] a)
Returns an Array whose component type is the runtime component type of the passed-in Array. |
java.lang.String |
toString()
Creates a String representation of the Collection. |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
containsAll, equals, hashCode, iterator, listIterator, removeAll, retainAll, subList |
Field Detail |
protected CircularQueue.CircularQueueEntry head
protected CircularQueue.CircularQueueEntry tail
protected transient LinkedList.Entry first
protected transient LinkedList.Entry last
protected transient int size
protected transient int modCount
ConcurrentModificationException
in response
to the next operation on the iterator. This fail-fast behavior
saves the user from many subtle bugs otherwise possible from concurrent
modification during iteration.
To make lists fail-fast, increment this field by just 1 in the
add(int, Object)
and remove(int)
methods.
Otherwise, this field may be ignored.
Constructor Detail |
public CircularQueue()
Method Detail |
public boolean add(java.lang.Object o)
org.dhmp.util.LinkedList
o
- the entry to add
protected void addAfter(LinkedList.Entry e, java.lang.Object o)
public java.lang.Object get()
protected LinkedList.Entry getEntry()
public boolean isEmpty()
org.dhmp.util.AbstractCollection
AbstractCollection.size()
public void shrink()
public LinkedList.Entry newEntry(java.lang.Object o)
org.dhmp.util.LinkedList
o
- the object associated to the entry
public java.lang.Object getFirst()
java.util.NoSuchElementException
- if the list is emptypublic java.lang.Object getLast()
java.util.NoSuchElementException
- if the list is emptypublic java.lang.Object removeFirst()
java.util.NoSuchElementException
- if the list is emptypublic java.lang.Object removeLast()
java.util.NoSuchElementException
- if the list is emptypublic void addFirst(java.lang.Object o)
o
- the element to insertpublic void addLast(java.lang.Object o)
o
- the element to insertpublic boolean contains(java.lang.Object o)
o == null ? e = null : o.equals(e)
.
contains
in interface java.util.List
o
- the element to look for
public int size()
size
in interface java.util.List
public boolean remove(java.lang.Object o)
remove
in interface java.util.List
o
- the object to remove
Iterator.remove()
public boolean addAll(java.util.Collection c)
addAll
in interface java.util.List
c
- the collection to append
java.lang.NullPointerException
- if c is nullAbstractCollection.add(Object)
public boolean addAll(int index, java.util.Collection c)
addAll
in interface java.util.List
c
- the collection to appendindex
- the location to insert the collection
java.lang.NullPointerException
- if c is null
java.lang.IndexOutOfBoundsException
- if index < 0 || index > size()AbstractSequentialList.add(int, Object)
public void clear()
clear
in interface java.util.List
AbstractList.remove(int)
,
AbstractList.removeRange(int, int)
public java.lang.Object get(int index)
get
in interface java.util.List
index
- the place to look
java.lang.IndexOutOfBoundsException
- if index < 0 || index >= size()public java.lang.Object set(int index, java.lang.Object o)
set
in interface java.util.List
index
- which index to changeo
- the new element
java.lang.IndexOutOfBoundsException
- if index < 0 || index >= size()public void add(int index, java.lang.Object o)
add
in interface java.util.List
index
- where to insert the elemento
- the element to insert
java.lang.IndexOutOfBoundsException
- if index < 0 || index > size()public java.lang.Object remove(int index)
remove
in interface java.util.List
index
- the location of the element to remove
java.lang.IndexOutOfBoundsException
- if index < 0 || index > size()public int indexOf(java.lang.Object o)
indexOf
in interface java.util.List
o
- the element to look for
public int lastIndexOf(java.lang.Object o)
lastIndexOf
in interface java.util.List
o
- the element to look for
public java.util.ListIterator listIterator(int index)
listIterator
in interface java.util.List
index
- the index of the element to be returned by the first call to
next(), or size() to be initially positioned at the end of the list
java.lang.IndexOutOfBoundsException
- if index < 0 || index > size()public java.lang.Object clone()
public java.lang.Object[] toArray()
toArray
in interface java.util.List
public java.lang.Object[] toArray(java.lang.Object[] a)
toArray
in interface java.util.List
a
- the passed-in Array
java.lang.ArrayStoreException
- if the runtime type of a does not allow
an element in this list
java.lang.NullPointerException
- if a is nullpublic java.util.Iterator iterator()
AbstractList.modCount
public boolean equals(java.lang.Object o)
l1.size() == l2.size()
, and for every integer n between 0
and l1.size() - 1
inclusive, l1.get(n) == null ?
l2.get(n) == null : l1.get(n).equals(l2.get(n))
.
This implementation returns true if the object is this, or false if the object is not a List. Otherwise, it iterates over both lists (with iterator()), returning false if two elements compare false or one list is shorter, and true if the iteration completes successfully.
equals
in interface java.util.List
o
- the object to test for equality with this list
Object.equals(Object)
,
AbstractList.hashCode()
public int hashCode()
hashCode = 1; Iterator i = list.iterator(); while (i.hasNext()) { Object obj = i.next(); hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode()); }This ensures that the general contract of Object.hashCode() is adhered to.
hashCode
in interface java.util.List
Object.hashCode()
,
AbstractList.equals(Object)
public java.util.ListIterator listIterator()
listIterator
in interface java.util.List
protected void removeRange(int fromIndex, int toIndex)
This implementation first checks for illegal or out of range arguments. It then obtains a ListIterator over the list using listIterator(fromIndex). It then calls next() and remove() on this iterator repeatedly, toIndex - fromIndex times.
fromIndex
- the index, inclusive, to remove from.toIndex
- the index, exclusive, to remove to.
java.lang.UnsupportedOperationException
- if the list does
not support removing elements.public java.util.List subList(int fromIndex, int toIndex)
This implementation returns a subclass of AbstractList. It stores, in private fields, the offset and size of the sublist, and the expected modCount of the backing list. If the backing list implements RandomAccess, the sublist will also.
The subclass's set(int, Object)
, get(int)
,
add(int, Object)
, remove(int)
,
addAll(int, Collection)
and
removeRange(int, int)
methods all delegate to the
corresponding methods on the backing abstract list, after
bounds-checking the index and adjusting for the offset. The
addAll(Collection c)
method merely returns addAll(size, c).
The listIterator(int)
method returns a "wrapper object"
over a list iterator on the backing list, which is created with the
corresponding method on the backing list. The iterator()
method merely returns listIterator(), and the size()
method
merely returns the subclass's size field.
All methods first check to see if the actual modCount of the backing list is equal to its expected value, and throw a ConcurrentModificationException if it is not.
subList
in interface java.util.List
fromIndex
- the index that the returned list should start from
(inclusive)toIndex
- the index that the returned list should go to (exclusive)
java.lang.IndexOutOfBoundsException
- if fromIndex < 0
|| toIndex > size()
java.lang.IllegalArgumentException
- if fromIndex > toIndexConcurrentModificationException
,
RandomAccess
public boolean containsAll(java.util.Collection c)
containsAll
in interface java.util.Collection
c
- the collection to test against
java.lang.NullPointerException
- if the given collection is nullAbstractCollection.contains(Object)
public boolean removeAll(java.util.Collection c)
removeAll
in interface java.util.Collection
c
- the collection to remove the elements of
java.lang.UnsupportedOperationException
- if this collection's Iterator
does not support the remove method
java.lang.NullPointerException
- if the collection, c, is null.Iterator.remove()
public boolean retainAll(java.util.Collection c)
retainAll
in interface java.util.Collection
c
- the collection to retain the elements of
java.lang.UnsupportedOperationException
- if this collection's Iterator
does not support the remove method
java.lang.NullPointerException
- if the collection, c, is null.Iterator.remove()
public java.lang.String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |