viceroy.misc.typeSafeCollections
Class TypeSafeSortedSet

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

class TypeSafeSortedSet
extends TypeSafeSet
implements java.util.SortedSet

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


Field Summary
private  java.util.SortedSet _set
           
 
Constructor Summary
TypeSafeSortedSet(java.util.SortedSet set, java.lang.Class type)
          Constructs a new TypeSafeSortedSet 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
 java.util.Comparator comparator()
          see java.util.SortedSet
 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
 java.lang.Object first()
          see java.util.SortedSet
protected  java.lang.Class getType()
          Returns the type of objects which can be added to this collection
 java.util.SortedSet headSet(java.lang.Object toElement)
          See java.util.SortedSet Returns a type safe java.util.SortedSet
 boolean isEmpty()
          see java.util.Collection
 java.util.Iterator iterator()
          see java.util.Collection
 java.lang.Object last()
          see java.util.SortedSet
 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.util.SortedSet subSet(java.lang.Object fromElement, java.lang.Object toElement)
          See java.util.SortedSet Returns a type safe java.util.SortedSet
 java.util.SortedSet tailSet(java.lang.Object fromElement)
          See java.util.SortedSet Returns a type safe java.util.SortedSet
 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.SortedSet _set
Constructor Detail

TypeSafeSortedSet

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

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

comparator

public java.util.Comparator comparator()
see java.util.SortedSet

Specified by:
comparator in interface java.util.SortedSet

first

public java.lang.Object first()
see java.util.SortedSet

Specified by:
first in interface java.util.SortedSet

last

public java.lang.Object last()
see java.util.SortedSet

Specified by:
last in interface java.util.SortedSet

headSet

public java.util.SortedSet headSet(java.lang.Object toElement)
See java.util.SortedSet Returns a type safe java.util.SortedSet

Specified by:
headSet in interface java.util.SortedSet

subSet

public java.util.SortedSet subSet(java.lang.Object fromElement,
                                  java.lang.Object toElement)
See java.util.SortedSet Returns a type safe java.util.SortedSet

Specified by:
subSet in interface java.util.SortedSet

tailSet

public java.util.SortedSet tailSet(java.lang.Object fromElement)
See java.util.SortedSet Returns a type safe java.util.SortedSet

Specified by:
tailSet in interface java.util.SortedSet

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.