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, immutable, list otherwise.
|
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(Class<?> key)
key
- key to check for in the mappublic boolean containsValue(B value)
value
- value to check for in this mappublic <T> List<T> get(Class<T> type)
T
- type identifiertype
- map keypublic boolean isEmpty()
public Set<Class<?>> keys()
public void put(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(Iterable<? extends B> newValues)
newValues
- values to be addedput(Object)
public void putAll(ClassToInstanceMultiMap<? extends B> map)
map
- map containing values to be addedput(Object)
public void remove(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(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(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(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 removepublic Collection<? extends B> values()
private Set<Class<?>> getIndexTypes(B value)
value
- the value to indexprivate void getSuperTypes(Class<?> clazz, Set<Class<?>> accumulator)
clazz
- class for which supertypes will be determinedaccumulator
- collection to which supertypes are added as they are determinedCopyright © 1999–2016. All rights reserved.