viceroy.misc.typeSafeCollections
Class TypeSafeSet

java.lang.Object
  |
  +--viceroy.misc.typeSafeCollections.TypeSafeCollection
        |
        +--viceroy.misc.typeSafeCollections.TypeSafeSet
All Implemented Interfaces:
java.util.Collection, java.util.Set
Direct Known Subclasses:
TypeSafeMapEntrySet, TypeSafeSortedSet

class TypeSafeSet
extends TypeSafeCollection
implements java.util.Set

Implementation of the java.util.Set class which accepts only objects of a given type for add operations. Is backed by another implementation of Set.


Field Summary
private  java.util.Set _set
           
 
Constructor Summary
TypeSafeSet(java.util.Set set, java.lang.Class type)
          Constructs a new TypeSafeSet object.
 
Method Summary
 boolean add(java.lang.Object o)
          see java.util.Collection Checks the type of the object.
 boolean addAll(java.util.Collection c)
          see java.util.Collection Checks the type of the objects in the Collection.
protected  void checkType(java.lang.Object o)
          Tests whether the an object is an instance of the allowed type.
 void clear()
          see java.util.Collection
 boolean contains(java.lang.Object o)
          see java.util.Collection
 boolean containsAll(java.util.Collection c)
          see java.util.Collection
 boolean equals(java.lang.Object o)
          see java.util.Collection
protected  java.lang.Class getType()
          Returns the type of objects which can be added to this collection
 boolean isEmpty()
          see java.util.Collection
 java.util.Iterator iterator()
          see java.util.Collection
 boolean remove(java.lang.Object o)
          see java.util.Collection
 boolean removeAll(java.util.Collection c)
          see java.util.Collection
 boolean retainAll(java.util.Collection c)
          see java.util.Collection
 int size()
          see java.util.Collection
 java.lang.Object[] toArray()
          see java.util.Collection
 java.lang.Object[] toArray(java.lang.Object[] a)
          see java.util.Collection
 java.lang.String toString()
          Returns a string representation of the TypeSafeCollection.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 

Field Detail

_set

private java.util.Set _set
Constructor Detail

TypeSafeSet

public TypeSafeSet(java.util.Set set,
                   java.lang.Class type)
Constructs a new TypeSafeSet object. iterates over the given collection and checks if they match the given type

Parameters:
set - the Set to be wrapped
type - the type of the objects which can be added
Method Detail

checkType

protected void checkType(java.lang.Object o)
Tests whether the an object is an instance of the allowed type.

Parameters:
o - The object to be checked
Throws:
java.lang.ClassCastException - if the object is not of the right type

getType

protected java.lang.Class getType()
Returns the type of objects which can be added to this collection


size

public int size()
see java.util.Collection

Specified by:
size in interface java.util.Collection

isEmpty

public boolean isEmpty()
see java.util.Collection

Specified by:
isEmpty in interface java.util.Collection

contains

public boolean contains(java.lang.Object o)
see java.util.Collection

Specified by:
contains in interface java.util.Collection

iterator

public java.util.Iterator iterator()
see java.util.Collection

Specified by:
iterator in interface java.util.Collection

toArray

public java.lang.Object[] toArray()
see java.util.Collection

Specified by:
toArray in interface java.util.Collection

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
see java.util.Collection

Specified by:
toArray in interface java.util.Collection

add

public boolean add(java.lang.Object o)
see java.util.Collection Checks the type of the object.

Specified by:
add in interface java.util.Collection

remove

public boolean remove(java.lang.Object o)
see java.util.Collection

Specified by:
remove in interface java.util.Collection

containsAll

public boolean containsAll(java.util.Collection c)
see java.util.Collection

Specified by:
containsAll in interface java.util.Collection

addAll

public boolean addAll(java.util.Collection c)
see java.util.Collection Checks the type of the objects in the Collection.

Specified by:
addAll in interface java.util.Collection

removeAll

public boolean removeAll(java.util.Collection c)
see java.util.Collection

Specified by:
removeAll in interface java.util.Collection

retainAll

public boolean retainAll(java.util.Collection c)
see java.util.Collection

Specified by:
retainAll in interface java.util.Collection

clear

public void clear()
see java.util.Collection

Specified by:
clear in interface java.util.Collection

equals

public boolean equals(java.lang.Object o)
see java.util.Collection

Specified by:
equals in interface java.util.Collection
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Returns a string representation of the TypeSafeCollection.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the object.