Class OneToManyIndex<K,V>
java.lang.Object
com.atlassian.bamboo.plan.cache.index.util.OneToManyIndex<K,V>
A class that allows to index any key <-> value, one-to-many relationship. The key characteristics of this class is that,
unlike Multimap<K,V>, it doesn't require linear scan when removing by value.
Both K and V must have hashCode() and equals() correctly defined.
The class is, for the most part, thread safe. Important: if accessing forward and backward mapping directly, calling code should
synchronize on lock returned by
getReadWriteLock()
.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addToIndex
(K key, V value) To be used when you can be sure no prior mapping exists for the value.void
clear()
You need to synchronize on this object usinggetReadWriteLock()
when calling this method and while working with its result.getByKeyUnsafe
(K key) Does not perform a copy, can only be used in context that are thread safe from perspective of this objectgetByValue
(V value) You need to synchronize on this object usinggetReadWriteLock()
when calling this method and while working with its result.io.atlassian.util.concurrent.ManagedLock.ReadWrite
void
void
Replace key value pair with a new value.reindexSet
(K key, @NotNull Set<V> values) Replace complete value set for a key.removeByKey
(K key) removeByValue
(V value) void
removeMatchingValuesForKey
(K key, @NotNull Predicate<V> predicate)
-
Constructor Details
-
OneToManyIndex
public OneToManyIndex()
-
-
Method Details
-
addToIndex
To be used when you can be sure no prior mapping exists for the value. -
index
-
reindex
Replace key value pair with a new value. This is useful if value object can change content without changing identity. -
reindexSet
Replace complete value set for a key.- Returns:
- the old set
-
getForwardMapping
You need to synchronize on this object usinggetReadWriteLock()
when calling this method and while working with its result. -
getBackwardMapping
You need to synchronize on this object usinggetReadWriteLock()
when calling this method and while working with its result. -
removeByKey
-
removeByValue
-
removeMatchingValuesForKey
-
getByKey
-
getByKeyUnsafe
Does not perform a copy, can only be used in context that are thread safe from perspective of this object -
getByValue
-
clear
public void clear() -
getReadWriteLock
public io.atlassian.util.concurrent.ManagedLock.ReadWrite getReadWriteLock()
-