Class OneToManyIndex<K,V>

java.lang.Object
com.atlassian.bamboo.plan.cache.index.util.OneToManyIndex<K,V>

@Internal @ThreadSafe public class OneToManyIndex<K,V> extends Object
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 Details

    • OneToManyIndex

      public OneToManyIndex()
  • Method Details

    • addToIndex

      public void addToIndex(@NotNull K key, @NotNull V value)
      To be used when you can be sure no prior mapping exists for the value.
    • index

      public void index(@NotNull K key, @NotNull V value)
    • reindex

      public void reindex(@NotNull K key, @NotNull V value)
      Replace key value pair with a new value. This is useful if value object can change content without changing identity.
    • reindexSet

      @Nullable public @Nullable Set<V> reindexSet(@NotNull K key, @NotNull @NotNull Set<V> values)
      Replace complete value set for a key.
      Returns:
      the old set
    • getForwardMapping

      @NotNull public @NotNull Map<K,Set<V>> getForwardMapping()
      You need to synchronize on this object using getReadWriteLock() when calling this method and while working with its result.
    • getBackwardMapping

      @NotNull public @NotNull Map<V,K> getBackwardMapping()
      You need to synchronize on this object using getReadWriteLock() when calling this method and while working with its result.
    • removeByKey

      @Nullable public @Nullable Set<V> removeByKey(@NotNull K key)
    • removeByValue

      @Nullable public K removeByValue(@NotNull V value)
    • removeMatchingValuesForKey

      public void removeMatchingValuesForKey(@NotNull K key, @NotNull @NotNull Predicate<V> predicate)
    • getByKey

      @NotNull public @NotNull Set<V> getByKey(@NotNull K key)
    • getByKeyUnsafe

      @NotNull public @NotNull Set<V> getByKeyUnsafe(@NotNull K key)
      Does not perform a copy, can only be used in context that are thread safe from perspective of this object
    • getByValue

      @Nullable public K getByValue(@NotNull V value)
    • clear

      public void clear()
    • getReadWriteLock

      public io.atlassian.util.concurrent.ManagedLock.ReadWrite getReadWriteLock()