Class ManyToMany<T1,T2>
java.lang.Object
org.aspectj.org.eclipse.jdt.internal.compiler.apt.util.ManyToMany<T1,T2>
Manage a
Map<T1, Set<T2>>, with reverse links so that it is possible to
efficiently find all T1s that have a particular T2 associated with them.
Access to the map is synchronized, so that it is possible to read and
write simultaneously from multiple threads.
The map permits the null value for keys nor for value elements.
Design invariants preserved by all operations on this map are as follows:
- If a key exists, it has at least one value associated with it; that is, for all k such that null != containsKey(k), getValues(k) returns a non-empty set.
- If a value exists, it has at least one key associated with it; that is, for all v such that null != containsValue(v), getKeys(v) returns a non-empty set.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanclear()Empty all maps.voidSets the dirty bit to false.booleancontainsKey(T1 key) Equivalent to keySet().contains(key).booleancontainsKeyValuePair(T1 key, T2 value) Is there a key that is mapped to the specified value? Search within the forward map.booleancontainsValue(T2 value) Equivalent to values().contains(value).Search the reverse map for all keys that have been associated with a particular value.Search the forward map for all values associated with a particular key.booleanisDirty()Return the state of the dirty bit.booleankeyHasOtherValues(T1 key, T2 value) Check whetherkeyhas an association to any values other thanvalue- that is, whether the same key has been added with multiple values.booleanAssociate the specified value with the key.booleanRemove a particular key-value association.booleanRemove the key and its associated key/value entries.booleanremoveValue(T2 value) Remove the value and its associated key/value entries.booleanvalueHasOtherKeys(T2 value, T1 key) Check whethervaluehas an association from any keys other thankey- that is, whether the same value has been added with multiple keys.
-
Constructor Details
-
ManyToMany
public ManyToMany()
-
-
Method Details
-
clear
public boolean clear()Empty all maps. If the maps previously contained entries, this will set the dirty bit.- Returns:
- true if the maps contained any entries prior to being cleared
-
clearDirtyBit
public void clearDirtyBit()Sets the dirty bit to false. Internal operations do not use the dirty bit; clearing it will not affect behavior of the map. It's just there for the convenience of callers who don't want to keep track of every put() and remove(). -
containsKey
Equivalent to keySet().contains(key).- Returns:
- true if the map contains the specified key.
-
containsKeyValuePair
-
containsValue
Equivalent to values().contains(value).- Returns:
- true if the map contains the specified value (regardless of what key it might be associated with).
-
getKeys
-
getValues
-
getKeySet
-
getValueSet
-
isDirty
public boolean isDirty()Return the state of the dirty bit. All operations that change the state of the maps, including @see #clear(), set the dirty bit if any content actually changed. The only way to clear the dirty bit is to call @see #clearDirtyBit().- Returns:
- true if the map content has changed since it was created or since the last call to clearDirtyBit().
- See Also:
-
keyHasOtherValues
Check whetherkeyhas an association to any values other thanvalue- that is, whether the same key has been added with multiple values. Equivalent to asking whether the intersection ofgetValues(key)and the set containingvalueis non-empty.- Returns:
- true iff
keyis in the map and is associated with values other thanvalue. - See Also:
-
put
Associate the specified value with the key. Adds the entry to both the forward and reverse maps. Adding the same value twice to a particular key has no effect. Because this is a many-to-many map, adding a new value for an existing key does not change the existing association, it adds a new one.- Parameters:
key- can be nullvalue- can be null- Returns:
- true if the key/value pair did not exist prior to being added
-
remove
Remove a particular key-value association. This is the inverse of put(key, value). If the key does not exist, or the value does not exist, or the association does not exist, this call has no effect.- Returns:
- true if the key/value pair existed in the map prior to removal
-
removeKey
Remove the key and its associated key/value entries. Calling removeKey(k) is equivalent to calling remove(k,v) for every v in getValues(k).- Returns:
- true if the key existed in the map prior to removal
-
removeValue
Remove the value and its associated key/value entries. Calling removeValue(v) is equivalent to calling remove(k,v) for every k in getKeys(v).- Returns:
- true if the value existed in the map prior to removal.
-
valueHasOtherKeys
Check whethervaluehas an association from any keys other thankey- that is, whether the same value has been added with multiple keys. Equivalent to asking whether the intersection ofgetKeys(value)and the set containingkeyis non-empty.- Returns:
- true iff
valueis in the map and is associated with keys other thankey. - See Also:
-