net.shibboleth.metadata.util
Class ClassToInstanceMultiMap<B>

java.lang.Object
  extended by net.shibboleth.metadata.util.ClassToInstanceMultiMap<B>
Type Parameters:
B - a bound for the types of values in the map

@NotThreadSafe
public final class ClassToInstanceMultiMap<B>
extends Object

An append-only multimap where each entry associates a raw type (i.e. class) to instances of that class. In addition the map may also associate any supertype (i.e. all superclasses and interfaces implemented by the class) with the class. Null values are not supported.


Field Summary
private  HashMap<Class<?>,List<B>> backingMap
          Map which backs this map.
private  boolean indexSupertypes
          Whether supertypes should also be indexed.
private  List<B> values
          List of values that are indexed.
 
Constructor Summary
ClassToInstanceMultiMap()
          Constructor.
ClassToInstanceMultiMap(boolean isIndexingSupertypes)
          Constructor.
 
Method Summary
 void clear()
          Removes all mappings from this map.
 boolean containsKey(Class<?> key)
          Returns true if the map contains a mapping for the given key.
 boolean containsValue(B value)
          Returns true if the map contains a mapping to the given value.
 boolean equals(Object obj)
          
<T> List<T>
get(Class<T> type)
          Gets the instances mapped to the given type or an empty list, immutable, list otherwise.
private  void getSuperTypes(Class<?> clazz, ArrayList<Class<?>> accumulator)
          Gets all of the superclasses and interfaces implemented by the given class.
 int hashCode()
          
 boolean isEmpty()
          Returns true if this map contains no entries, false otherwise.
 Set<Class<?>> keys()
          Gets the set of keys contained in this map.
 void put(B value)
          Adds a value to this map.
 void putAll(ClassToInstanceMultiMap<? extends B> newValues)
          Adds all the values to the map.
 void putAll(Iterable<? extends B> newValues)
          Adds all the values to the map.
 Collection<? extends B> values()
          The collection of values currently present in the map.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

indexSupertypes

private final boolean indexSupertypes
Whether supertypes should also be indexed.


backingMap

private final HashMap<Class<?>,List<B>> backingMap
Map which backs this map.


values

private final List<B> values
List of values that are indexed.

Constructor Detail

ClassToInstanceMultiMap

public ClassToInstanceMultiMap()
Constructor. Does not index supertypes.


ClassToInstanceMultiMap

public ClassToInstanceMultiMap(boolean isIndexingSupertypes)
Constructor.

Parameters:
isIndexingSupertypes - indicates whether supertypes of a value should be indexed
Method Detail

clear

public void clear()
Removes all mappings from this map.


containsKey

public boolean containsKey(Class<?> key)
Returns true if the map contains a mapping for the given key.

Parameters:
key - key to check for in the map
Returns:
true if the map contains a mapping for the specified key

containsValue

public boolean containsValue(B value)
Returns true if the map contains a mapping to the given value.

Parameters:
value - value to check for in this map
Returns:
true if the map contains a mapping to the specified value

get

public <T> List<T> get(Class<T> type)
Gets the instances mapped to the given type or an empty list, immutable, list otherwise.

Type Parameters:
T - type identifier
Parameters:
type - map key
Returns:
instances mapped to the given type or an empty list, immutable, list otherwise

isEmpty

public boolean isEmpty()
Returns true if this map contains no entries, false otherwise.

Returns:
true if this map contains no entries, false otherwise

keys

public Set<Class<?>> keys()
Gets the set of keys contained in this map. The set is backed by the map so changes made to the map are reflected in the set. However the set does not allow direct modification, any changes need to be done through this map.

Returns:
set of keys contained in this map

put

public void put(B value)
Adds a value to this map. If indexSupertypes is false only the values class type is used as a key to the value. If indexSupertypes is true, then the class types, all its supertypes, and all implemented interfaces are used as keys to the value. Duplicate values, as determined by the values Object.hashCode() and Object.equals(Object) methods, are not stored. Only one instance of the value is ever stored in the map.

Parameters:
value - value to be stored in the map

putAll

public void putAll(Iterable<? extends B> newValues)
Adds all the values to the map.

Parameters:
newValues - values to be added
See Also:
put(Object)

putAll

public void putAll(ClassToInstanceMultiMap<? extends B> newValues)
Adds all the values to the map. This operations operates only on the given map's value collection. Therefore, regardless of the given map's policy on indexing by value supertypes, this map will index values based on its policy.

Parameters:
newValues - values to be added
See Also:
put(Object)

values

public Collection<? extends B> values()
The collection of values currently present in the map. This collection is backed by the map so changeds to the map will be reflected in the collection. However the collection does not allow direct modification so any changes must be done through this map.

Returns:
collection of values currently present in the map

getSuperTypes

private void getSuperTypes(Class<?> clazz,
                           ArrayList<Class<?>> accumulator)
Gets all of the superclasses and interfaces implemented by the given class.

Parameters:
clazz - class for which supertypes will be determined
accumulator - collection to which supertypes are added as they are determined

hashCode

public int hashCode()

Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)

Overrides:
equals in class Object


Copyright © 1999-2012. All Rights Reserved.