rita.support
Class HistoryQueue

java.lang.Object
  extended by rita.support.HistoryQueue
All Implemented Interfaces:
java.lang.Iterable, java.util.Collection, java.util.Set

public class HistoryQueue
extends java.lang.Object
implements java.util.Set, java.util.Collection

This is an implementation of a growable(by default) or fixed-size array of Objects that implements the java.util.Set & Collection interfaces. In fixed-size mode, a simple first-in, first-out(FIFO) strategy is used to maintain maximum size. The backing structure is an Object[] for fast, unsychronized access. Care should be taken when using this class in a multi-threaded application.


Constructor Summary
HistoryQueue()
           
HistoryQueue(java.util.Collection stringList, boolean growable)
           
HistoryQueue(int capacity)
           
HistoryQueue(int capacity, boolean growable)
           
HistoryQueue(java.lang.Object[] stringArr, boolean growable)
           
 
Method Summary
 boolean add(java.lang.Object o)
           
 boolean addAll(java.util.Collection c)
           
 boolean addAll(java.lang.Object[] s)
           
 boolean allowDuplicates()
           
 java.lang.Object[] asArray()
           
 void clear()
           
 boolean contains(java.lang.Object o)
           
 boolean containsAll(java.util.Collection c)
           
 boolean equals(java.lang.Object o)
           
 java.lang.Object get(int index)
           
 int getCapacity()
           
 java.lang.Object getNewest()
          Returns the oldest item in the queue.
 java.lang.Object getOldest()
          Returns the oldest item in the queue.
 int getTotalAdds()
           
 int hashCode()
           
 int indexOf(java.lang.Object s)
           
 boolean isEmpty()
           
 boolean isFull()
           
 boolean isGrowable()
           
 java.util.Iterator iterator()
          Returns an iterator over the Strings in proper sequence.
 long lastModifiedAt()
           
static void main(java.lang.String[] args)
           
 java.lang.Object randomElement()
           
 java.lang.Object remove(int index)
          Removes the element at the specified index in this list and shifts any subsequent elements to the left
 boolean remove(java.lang.Object s)
           
 boolean removeAll(java.util.Collection c)
           
 java.lang.Object removeNewest()
          Removes the oldest item in the queue and shifts any subsequent elements appropriately.
 java.lang.Object removeOldest()
          Removes the oldest item in the queue and shifts any subsequent elements appropriately.
 boolean retainAll(java.util.Collection c)
           
 void setAllowDuplicates(boolean allowDuplicates)
           
 void setGrowable(boolean growable)
           
 void shuffle()
           
 int size()
           
 void sort()
           
 java.lang.Object[] toArray()
           
 java.lang.Object[] toArray(java.lang.Object[] arg0)
           
 java.lang.String toString()
           
 void trimToSize()
          Trims the capacity of this StringSet instance to be the current size.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HistoryQueue

public HistoryQueue()

HistoryQueue

public HistoryQueue(int capacity)

HistoryQueue

public HistoryQueue(java.util.Collection stringList,
                    boolean growable)

HistoryQueue

public HistoryQueue(java.lang.Object[] stringArr,
                    boolean growable)

HistoryQueue

public HistoryQueue(int capacity,
                    boolean growable)
Method Detail

randomElement

public java.lang.Object randomElement()
Returns:
- a random memeber of the set

sort

public void sort()

shuffle

public void shuffle()

asArray

public java.lang.Object[] asArray()

add

public boolean add(java.lang.Object o)
Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.Set
Parameters:
o -

addAll

public boolean addAll(java.lang.Object[] s)
Parameters:
s -

trimToSize

public void trimToSize()
Trims the capacity of this StringSet instance to be the current size. An application can use this operation to minimize the storage of an StringSet instance.


addAll

public boolean addAll(java.util.Collection c)
Specified by:
addAll in interface java.util.Collection
Specified by:
addAll in interface java.util.Set
Parameters:
c -

clear

public void clear()
Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.Set

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Collection
Specified by:
equals in interface java.util.Set
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

get

public java.lang.Object get(int index)
Parameters:
index -

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Collection
Specified by:
hashCode in interface java.util.Set
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

indexOf

public int indexOf(java.lang.Object s)
Parameters:
s -

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection
Specified by:
isEmpty in interface java.util.Set

remove

public boolean remove(java.lang.Object s)
Specified by:
remove in interface java.util.Collection
Specified by:
remove in interface java.util.Set
Parameters:
s -

iterator

public java.util.Iterator iterator()
Returns an iterator over the Strings in proper sequence.

Specified by:
iterator in interface java.lang.Iterable
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in interface java.util.Set

removeNewest

public java.lang.Object removeNewest()
Removes the oldest item in the queue and shifts any subsequent elements appropriately. Equivalent to remove(0);

Returns:
Object removed from the list or null if size == 0

getNewest

public java.lang.Object getNewest()
Returns the oldest item in the queue. Equivalent to get(0).

Returns:
Object removed from the list or null if size == 0

removeOldest

public java.lang.Object removeOldest()
Removes the oldest item in the queue and shifts any subsequent elements appropriately. Equivalent to remove(0);

Returns:
Object removed from the list or null if size == 0

getOldest

public java.lang.Object getOldest()
Returns the oldest item in the queue. Equivalent to get(0).

Returns:
Object removed from the list or null if size == 0

remove

public java.lang.Object remove(int index)
Removes the element at the specified index in this list and shifts any subsequent elements to the left

Returns:
Object removed from the list or null if size == 0

removeAll

public boolean removeAll(java.util.Collection c)
Specified by:
removeAll in interface java.util.Collection
Specified by:
removeAll in interface java.util.Set
Parameters:
c -

retainAll

public boolean retainAll(java.util.Collection c)
Specified by:
retainAll in interface java.util.Collection
Specified by:
retainAll in interface java.util.Set
Parameters:
c -

size

public int size()
Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.Set

containsAll

public boolean containsAll(java.util.Collection c)
Specified by:
containsAll in interface java.util.Collection
Specified by:
containsAll in interface java.util.Set
Parameters:
c -

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.Set

isFull

public boolean isFull()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

getCapacity

public int getCapacity()

isGrowable

public boolean isGrowable()

setGrowable

public void setGrowable(boolean growable)

allowDuplicates

public boolean allowDuplicates()

setAllowDuplicates

public void setAllowDuplicates(boolean allowDuplicates)

getTotalAdds

public int getTotalAdds()

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection
Specified by:
contains in interface java.util.Set

toArray

public java.lang.Object[] toArray(java.lang.Object[] arg0)
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.Set

lastModifiedAt

public long lastModifiedAt()

main

public static void main(java.lang.String[] args)