B - a bound for the types of values in the map@NotThreadSafe public class ClassToInstanceMultiMap<B> extends Object
| Modifier and Type | Field and Description |
|---|---|
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 and Description |
|---|
ClassToInstanceMultiMap()
Constructor.
|
ClassToInstanceMultiMap(boolean isIndexingSupertypes)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
private Set<Class<?>> |
getIndexTypes(B value)
Get the effective set of all class types via which the specified value should be indexed.
|
private void |
getSuperTypes(Class<?> clazz,
Set<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> map)
Adds all the values to the map.
|
void |
putAll(Iterable<? extends B> newValues)
Adds all the values to the map.
|
void |
remove(B value)
Remove the specified value from the map and from the value list of all indexes.
|
void |
remove(Class<?> type)
Remove from the map all values which have the specified type.
|
void |
removeAll(ClassToInstanceMultiMap<? extends B> map)
Remove the values contained in the specified map from this map and from the value list of all indexes.
|
void |
removeAll(Iterable<? extends B> removeValues)
Remove the specified values from the map and from the value list of all indexes.
|
Collection<? extends B> |
values()
The collection of values currently present in the map.
|
private final boolean indexSupertypes
public ClassToInstanceMultiMap()
public ClassToInstanceMultiMap(boolean isIndexingSupertypes)
isIndexingSupertypes - indicates whether supertypes of a value should be indexedpublic void clear()
public boolean containsKey(@Nullable Class<?> key)
key - key to check for in the mappublic boolean containsValue(@Nonnull B value)
value - value to check for in this map@Nonnull @NonnullElements @Unmodifiable @Live public <T> List<T> get(@Nullable Class<T> type)
T - type identifiertype - map keypublic boolean isEmpty()
@Nonnull @NonnullElements @Unmodifiable @Live public Set<Class<?>> keys()
public void put(@Nonnull B value)
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.value - value to be stored in the mappublic void putAll(@Nullable@NonnullElements Iterable<? extends B> newValues)
newValues - values to be addedput(Object)public void putAll(@Nullable@NonnullElements ClassToInstanceMultiMap<? extends B> map)
map - map containing values to be addedput(Object)public void remove(@Nonnull B value)
If the value list for a type index becomes empty due to the value removal, the entire type index will be removed
and containsKey(Class) for that type will then return false.
value - the value to removepublic void removeAll(@Nullable@NonnullElements Iterable<? extends B> removeValues)
If the value list for a type index becomes empty due to a value removal, the entire type index will be removed
and containsKey(Class) for that type will then return false.
removeValues - the values to removepublic void removeAll(@Nullable@NonnullElements ClassToInstanceMultiMap<? extends B> map)
If the value list for a type index becomes empty due to a value removal, the entire type index will be removed
and containsKey(Class) for that type will then return false.
map - the map containing the values to removepublic void remove(@Nullable Class<?> type)
Note that when a value was indexed by multiple superclass and/or interface types, it will be removed from all those type indexes, not just the specified one.
If the value list for a type index becomes empty due to a value removal, the entire type index will be removed
and containsKey(Class) for that type will then return false.
type - the type of values to remove@Nonnull @NonnullElements @Unmodifiable @Live public Collection<? extends B> values()
@Nonnull @NonnullElements private Set<Class<?>> getIndexTypes(@Nonnull B value)
value - the value to indexprivate void getSuperTypes(@Nonnull Class<?> clazz, @Nonnull@NonnullElements Set<Class<?>> accumulator)
clazz - class for which supertypes will be determinedaccumulator - collection to which supertypes are added as they are determinedCopyright © 1999–2019 Shibboleth Consortium. All rights reserved.