dsto.dfc.collections
Class CountedSet

java.lang.Object
  extended by dsto.dfc.collections.CountedSet
All Implemented Interfaces:
MonitoredCollection, MonitoredSet, Iterable, Collection, Set

public class CountedSet
extends Object
implements MonitoredSet

A set that counts add's and remove's on values. If a value is added N times, then it must be removed N times to be deleted from the set.

Version:
$Revision$

Constructor Summary
CountedSet()
           
CountedSet(Collection data)
           
CountedSet(Map dataMap)
          Constructor to allow users to get CountedSet to use their Map implementation.
 
Method Summary
 boolean add(Object o)
           
 boolean addAll(Collection c)
           
 void addCollectionListener(CollectionListener l)
           
 void clear()
          Clears the set regardless of value counts.
 boolean contains(Object o)
           
 boolean containsAll(Collection c)
           
protected static Integer decrement(Integer i)
          Return an Integer minus 1.
 boolean equals(Object o)
           
protected static Integer increment(Integer i)
          Return an Integer plus 1.
 boolean isEmpty()
           
 Iterator iterator()
           
 boolean remove(Object o)
           
 boolean removeAll(Collection c)
           
 void removeCollectionListener(CollectionListener l)
           
 boolean retainAll(Collection c)
           
 int size()
           
 Object[] toArray()
           
 Object[] toArray(Object[] array)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
hashCode
 

Constructor Detail

CountedSet

public CountedSet()

CountedSet

public CountedSet(Map dataMap)
Constructor to allow users to get CountedSet to use their Map implementation. The data must be structured with the map key being the data-object being stored, and the map value being an Integer object of the appropriate value (eg. Integer(3) would indicate that the map knows about three of the corresponding data-objects).

The reason behind this constructor is so that users can implement Maps with they own comparator implementations rather than relying on HashMap's and TreeMap's implementations.


CountedSet

public CountedSet(Collection data)
Method Detail

addCollectionListener

public void addCollectionListener(CollectionListener l)
Specified by:
addCollectionListener in interface MonitoredCollection

removeCollectionListener

public void removeCollectionListener(CollectionListener l)
Specified by:
removeCollectionListener in interface MonitoredCollection

size

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

isEmpty

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

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection
Specified by:
contains in interface Set

iterator

public Iterator iterator()
Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection
Specified by:
iterator in interface Set

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection
Specified by:
toArray in interface Set

toArray

public Object[] toArray(Object[] array)
Specified by:
toArray in interface Collection
Specified by:
toArray in interface Set

add

public boolean add(Object o)
Specified by:
add in interface Collection
Specified by:
add in interface Set

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection
Specified by:
remove in interface Set

containsAll

public boolean containsAll(Collection c)
Specified by:
containsAll in interface Collection
Specified by:
containsAll in interface Set

addAll

public boolean addAll(Collection c)
Specified by:
addAll in interface Collection
Specified by:
addAll in interface Set

retainAll

public boolean retainAll(Collection c)
Specified by:
retainAll in interface Collection
Specified by:
retainAll in interface Set

removeAll

public boolean removeAll(Collection c)
Specified by:
removeAll in interface Collection
Specified by:
removeAll in interface Set

clear

public void clear()
Clears the set regardless of value counts.

Specified by:
clear in interface Collection
Specified by:
clear in interface Set

equals

public boolean equals(Object o)
Specified by:
equals in interface Collection
Specified by:
equals in interface Set
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

increment

protected static Integer increment(Integer i)
Return an Integer plus 1. Uses predefined instances for 0-5.


decrement

protected static Integer decrement(Integer i)
Return an Integer minus 1. Uses predefined instances for 0-5.



Copyright © 2008 Commonwealth of Australia