viceroy.misc.typeSafeCollections
Class TypeSafeCollections

java.lang.Object
  |
  +--viceroy.misc.typeSafeCollections.TypeSafeCollections

public class TypeSafeCollections
extends java.lang.Object

This class contains a Collection of static methods which return a wrapper to an existing container interface of the Java Collection Framework. The wrappers make sure, that only objects of a given type can be added to the container.


Field Summary
protected static boolean performTypeCheck
           
 
Constructor Summary
TypeSafeCollections()
           
 
Method Summary
static void setPerformTypeCheck(boolean doCheck)
          sets the behaviour of all the type-safe collection classes.
static java.util.Collection typeSafeCollection(java.util.Collection collection, java.lang.Class type)
          Returns a wrapper for a type safe java.util.Collection.
static java.util.List typeSafeList(java.util.List list, java.lang.Class type)
          Returns a wrapper for a type safe java.util.List.
static java.util.Map typeSafeMap(java.util.Map map, java.lang.Class keyType, java.lang.Class valueType)
          Returns a wrapper for a type safe java.util.Map.
static java.util.Set typeSafeSet(java.util.Set set, java.lang.Class type)
          Returns a wrapper for a type safe java.util.Set.
static java.util.SortedMap typeSafeSortedMap(java.util.SortedMap map, java.lang.Class keyType, java.lang.Class valueType)
          Returns a wrapper for a type safe java.util.SortedMap.
static java.util.SortedSet typeSafeSortedSet(java.util.SortedSet set, java.lang.Class type)
          Returns a wrapper for a type safe java.util.SortedSet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

performTypeCheck

protected static boolean performTypeCheck
Constructor Detail

TypeSafeCollections

public TypeSafeCollections()
Method Detail

setPerformTypeCheck

public static void setPerformTypeCheck(boolean doCheck)
sets the behaviour of all the type-safe collection classes. The run-time check is probably expensive, and might be performed only in "debug" mode.

Parameters:
doCheck - true enables the run-time type check, false disables the run-time check.

typeSafeCollection

public static java.util.Collection typeSafeCollection(java.util.Collection collection,
                                                      java.lang.Class type)
Returns a wrapper for a type safe java.util.Collection. iterates over the given collection and checks if they match the given type

Parameters:
collection - The java.util.Collection object to be wrapped
type - The type of the objects you can add
Returns:
The type safe Collection

typeSafeList

public static java.util.List typeSafeList(java.util.List list,
                                          java.lang.Class type)
Returns a wrapper for a type safe java.util.List. iterates over the given collection and checks if they match the given type

Parameters:
list - The java.util.List object to be wrapped
type - The type of the objects you can add
Returns:
The type safe java.util.List

typeSafeSet

public static java.util.Set typeSafeSet(java.util.Set set,
                                        java.lang.Class type)
Returns a wrapper for a type safe java.util.Set. iterates over the given collection and checks if they match the given type

Parameters:
set - The java.util.Set object to be wrapped
type - The type of the objects you can add
Returns:
The type safe java.util.Set

typeSafeSortedSet

public static java.util.SortedSet typeSafeSortedSet(java.util.SortedSet set,
                                                    java.lang.Class type)
Returns a wrapper for a type safe java.util.SortedSet. iterates over the given collection and checks if they match the given type

Parameters:
set - The java.util.SortedSet object to be wrapped
type - The type of the objects you can add
Returns:
The type safe java.util.SortedSet

typeSafeMap

public static java.util.Map typeSafeMap(java.util.Map map,
                                        java.lang.Class keyType,
                                        java.lang.Class valueType)
Returns a wrapper for a type safe java.util.Map. iterates over the given collection and checks if they match the given type

Parameters:
map - The java.util.Map object to be wrapped
keyType - The type of the objects you use as keys
valueType - The type of the objects you add as values
Returns:
The type safe java.util.Map

typeSafeSortedMap

public static java.util.SortedMap typeSafeSortedMap(java.util.SortedMap map,
                                                    java.lang.Class keyType,
                                                    java.lang.Class valueType)
Returns a wrapper for a type safe java.util.SortedMap. iterates over the given collection and checks if they match the given type

Parameters:
map - The java.util.SortedMap object to be wrapped
keyType - The type of the objects you use as keys
valueType - The type of the objects you add as values
Returns:
The type safe java.util.SortedMap