Class ClassToInstanceMultiMap<B>
- Type Parameters:
B
- a bound for the types of values in the map
- Direct Known Subclasses:
LockableClassToInstanceMultiMap
-
Field Summary
FieldsModifier and TypeFieldDescriptionMap which backs this map.private final boolean
Whether supertypes should also be indexed.List of values that are indexed. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.ClassToInstanceMultiMap
(boolean isIndexingSupertypes) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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 iff the map contains a mapping to the given value, false if value is null.boolean
<T> List<T>
Gets the instances mapped to the given type or an empty list.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.keys()
Gets the set of keys contained in this map.void
Adds a value to this map.void
Adds all the values to the map.void
putAll
(ClassToInstanceMultiMap<? extends B> map) Adds all the values to the map.void
Remove the specified value from the map and from the value list of all indexes.void
Remove from the map all values which have the specified type.void
Remove the specified values from the map and from the value list of all indexes.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.Collection<? extends B>
values()
The collection of values currently present in the map.
-
Field Details
-
indexSupertypes
private final boolean indexSupertypesWhether supertypes should also be indexed. -
backingMap
Map which backs this map. -
values
List of values that are indexed.
-
-
Constructor Details
-
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 Details
-
clear
public void clear()Removes all mappings from this map. -
containsKey
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
Returns true iff the map contains a mapping to the given value, false if value is null.- Parameters:
value
- value to check for in this map- Returns:
- true iff the map contains a mapping to the specified value
-
get
Gets the instances mapped to the given type or an empty list.- Type Parameters:
T
- type identifier- Parameters:
type
- map key- Returns:
- instances mapped to the given type or an empty list
-
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
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
Adds a value to this map. IfindexSupertypes
is false only the values class type is used as a key to the value. IfindexSupertypes
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 valuesObject.hashCode()
andObject.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
Adds all the values to the map.- Parameters:
newValues
- values to be added- See Also:
-
putAll
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:
map
- map containing values to be added- See Also:
-
remove
Remove the specified value from the map and from the value list of all indexes.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 returnfalse
.- Parameters:
value
- the value to remove
-
removeAll
Remove the specified values from the map and from the value list of all indexes.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 returnfalse
.- Parameters:
removeValues
- the values to remove
-
removeAll
Remove the values contained in the specified map from this map and from the value list of all indexes.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 returnfalse
.- Parameters:
map
- the map containing the values to remove
-
remove
Remove from the map all values which have the specified 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 returnfalse
.- Parameters:
type
- the type of values to remove
-
values
The collection of values currently present in the map. This collection is backed by the map so changes 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
-
getIndexTypes
Get the effective set of all class types via which the specified value should be indexed.- Parameters:
value
- the value to index- Returns:
- the set of classes by which to index the value
-
getSuperTypes
private void getSuperTypes(@Nonnull Class<?> clazz, @Nonnull @NonnullElements Set<Class<?>> accumulator) Gets all of the superclasses and interfaces implemented by the given class.- Parameters:
clazz
- class for which supertypes will be determinedaccumulator
- collection to which supertypes are added as they are determined
-
hashCode
public int hashCode() -
equals
-