viceroy.misc.typeSafeCollections
Class TypeSafeSortedMap

java.lang.Object
  |
  +--viceroy.misc.typeSafeCollections.TypeSafeMap
        |
        +--viceroy.misc.typeSafeCollections.TypeSafeSortedMap
All Implemented Interfaces:
java.util.Map, java.util.SortedMap

class TypeSafeSortedMap
extends TypeSafeMap
implements java.util.SortedMap

Implementation of the java.util.SortedMap class which accepts only key and value objects of a given type for put operations. Is backed by another implementation of SortedMap.


Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
private  java.util.SortedMap _map
           
 
Constructor Summary
TypeSafeSortedMap(java.util.SortedMap map, java.lang.Class keyType, java.lang.Class valueType)
          Constructs a new TypeSafeSortedMap object.
 
Method Summary
protected  void checkKeyType(java.lang.Object o)
          Tests whether a key object is an instance of the allowed type.
protected  void checkType(java.lang.Object o, java.lang.Class type)
          Tests whether an object is an instance of the allowed type.
protected  void checkValueType(java.lang.Object o)
          Tests whether a value object is an instance of the allowed type.
 void clear()
          see java.util.Map
 java.util.Comparator comparator()
          see java.util.SortedMap
 boolean containsKey(java.lang.Object key)
          see java.util.Map
 boolean containsValue(java.lang.Object value)
          see java.util.Map
 java.util.Set entrySet()
          see java.util.Map Returns a type safe java.util.Set which prevents values of the wrong type to be set via the stored java.util.Map.Entry object.
 boolean equals(java.lang.Object o)
          see java.util.Map
 java.lang.Object firstKey()
          see java.util.SortedMap
 java.lang.Object get(java.lang.Object key)
          see java.util.Map
protected  java.lang.Class getKeyType()
          Returns the type of the keys.
protected  java.lang.Class getValueType()
          Returns the type of the values.
 java.util.SortedMap headMap(java.lang.Object toKey)
          See java.util.SortedMap Returns a type safe java.util.SortedMap
 boolean isEmpty()
          see java.util.Map
 java.util.Set keySet()
          see java.util.Map
 java.lang.Object lastKey()
          see java.util.SortedMap
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          see java.util.Map Checks the types of the key and value objects
 void putAll(java.util.Map t)
          see java.util.Map Checks the types of the key and value objects in the Map
 java.lang.Object remove(java.lang.Object key)
          see java.util.Map
 int size()
          see java.util.Map
 java.util.SortedMap subMap(java.lang.Object fromKey, java.lang.Object toKey)
          See java.util.SortedMap Returns a type safe java.util.SortedMap
 java.util.SortedMap tailMap(java.lang.Object fromKey)
          See java.util.SortedMap Returns a type safe java.util.SortedMap
 java.util.Collection values()
          see java.util.Map
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Field Detail

_map

private java.util.SortedMap _map
Constructor Detail

TypeSafeSortedMap

public TypeSafeSortedMap(java.util.SortedMap map,
                         java.lang.Class keyType,
                         java.lang.Class valueType)
Constructs a new TypeSafeSortedMap object. iterates over the given map and checks if they match the given type

Parameters:
map - the map to be wrapped
keyType - the type of the objects which can be used as keys
valueType - the type of the objects which can be added as values
Method Detail

comparator

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

Specified by:
comparator in interface java.util.SortedMap

firstKey

public java.lang.Object firstKey()
see java.util.SortedMap

Specified by:
firstKey in interface java.util.SortedMap

lastKey

public java.lang.Object lastKey()
see java.util.SortedMap

Specified by:
lastKey in interface java.util.SortedMap

headMap

public java.util.SortedMap headMap(java.lang.Object toKey)
See java.util.SortedMap Returns a type safe java.util.SortedMap

Specified by:
headMap in interface java.util.SortedMap

subMap

public java.util.SortedMap subMap(java.lang.Object fromKey,
                                  java.lang.Object toKey)
See java.util.SortedMap Returns a type safe java.util.SortedMap

Specified by:
subMap in interface java.util.SortedMap

tailMap

public java.util.SortedMap tailMap(java.lang.Object fromKey)
See java.util.SortedMap Returns a type safe java.util.SortedMap

Specified by:
tailMap in interface java.util.SortedMap

checkType

protected void checkType(java.lang.Object o,
                         java.lang.Class type)
Tests whether 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

checkKeyType

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

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

checkValueType

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

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

getKeyType

protected java.lang.Class getKeyType()
Returns the type of the keys.

Returns:
The class descriptor for the accepted key objects

getValueType

protected java.lang.Class getValueType()
Returns the type of the values.

Returns:
The class descriptor for the accepted value objects

size

public int size()
see java.util.Map

Specified by:
size in interface java.util.Map

isEmpty

public boolean isEmpty()
see java.util.Map

Specified by:
isEmpty in interface java.util.Map

containsKey

public boolean containsKey(java.lang.Object key)
see java.util.Map

Specified by:
containsKey in interface java.util.Map

containsValue

public boolean containsValue(java.lang.Object value)
see java.util.Map

Specified by:
containsValue in interface java.util.Map

get

public java.lang.Object get(java.lang.Object key)
see java.util.Map

Specified by:
get in interface java.util.Map

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
see java.util.Map Checks the types of the key and value objects

Specified by:
put in interface java.util.Map

remove

public java.lang.Object remove(java.lang.Object key)
see java.util.Map

Specified by:
remove in interface java.util.Map

putAll

public void putAll(java.util.Map t)
see java.util.Map Checks the types of the key and value objects in the Map

Specified by:
putAll in interface java.util.Map

clear

public void clear()
see java.util.Map

Specified by:
clear in interface java.util.Map

keySet

public java.util.Set keySet()
see java.util.Map

Specified by:
keySet in interface java.util.Map

values

public java.util.Collection values()
see java.util.Map

Specified by:
values in interface java.util.Map

entrySet

public java.util.Set entrySet()
see java.util.Map Returns a type safe java.util.Set which prevents values of the wrong type to be set via the stored java.util.Map.Entry object.

Specified by:
entrySet in interface java.util.Map

equals

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

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