Class LockableClassToInstanceMultiMap<B>

  • Type Parameters:
    B - a bound for the types of values in the map

    public class LockableClassToInstanceMultiMap<B>
    extends ClassToInstanceMultiMap<B>
    A specialization of ClassToInstanceMultiMap which exposes a map-specific instance of ReadWriteLock.

    Callers of the map are generally responsible for explicitly locking and unlocking for reading and writing, based on application use cases and concurrency requirements. For simple single-statement atomic operations, convenience methods are supplied which execute the corresponding superclass operation under the read or write lock, as appropriate.

    • Field Detail

      • readWriteLock

        @Nonnull
        private final ReadWriteLock readWriteLock
        The map's read write lock.
    • Constructor Detail

      • LockableClassToInstanceMultiMap

        public LockableClassToInstanceMultiMap()
        Constructor.
      • LockableClassToInstanceMultiMap

        public LockableClassToInstanceMultiMap​(boolean isIndexingSupertypes)
        Constructor.
        Parameters:
        isIndexingSupertypes - indicates whether supertypes of a value should be indexed
    • Method Detail

      • getReadWriteLock

        @Nonnull
        public ReadWriteLock getReadWriteLock()
        Get the map-specific instance of the ReadWriteLock.

        Callers of the map are responsible for explicitly locking (and unlocking) for reading and/or writing, based on application use cases.

        Returns:
        Returns the rwlock.
      • clearWithLock

        public void clearWithLock()
        Convenience method which executes the like-named method from superclass ClassToInstanceMultiMap under a write lock.
      • containsKeyWithLock

        public boolean containsKeyWithLock​(@Nullable
                                           Class<?> key)
        Convenience method which executes the like-named method from superclass ClassToInstanceMultiMap under a read lock.
        Parameters:
        key - key to check for in the map
        Returns:
        true if the map contains a mapping for the specified key
      • containsValueWithLock

        public boolean containsValueWithLock​(@Nullable
                                             B value)
        Convenience method which executes the like-named method from superclass ClassToInstanceMultiMap under a read lock.
        Parameters:
        value - value to check for in this map
        Returns:
        true if the map contains a mapping to the specified value
      • getWithLock

        @Nonnull
        @NonnullElements
        @Unmodifiable
        @Live
        public <T> List<T> getWithLock​(@Nullable
                                       Class<T> type)
        Convenience method which executes the like-named method from superclass ClassToInstanceMultiMap under a read lock.
        Type Parameters:
        T - type identifier
        Parameters:
        type - map key
        Returns:
        instances mapped to the given type or an empty list
      • isEmptyWithLock

        public boolean isEmptyWithLock()
        Convenience method which executes the like-named method from superclass ClassToInstanceMultiMap under a read lock.
        Returns:
        true if this map contains no entries, false otherwise
      • putWithLock

        public void putWithLock​(@Nonnull
                                B value)
        Convenience method which executes the like-named method from superclass ClassToInstanceMultiMap under a write lock.
        Parameters:
        value - value to be stored in the map
      • putAllWithLock

        public void putAllWithLock​(@Nullable @NonnullElements
                                   Iterable<? extends B> newValues)
        Convenience method which executes the like-named method from superclass ClassToInstanceMultiMap under a write lock.
        Parameters:
        newValues - values to be added
      • removeWithLock

        public void removeWithLock​(@Nonnull
                                   B value)
        Convenience method which executes the like-named method from superclass ClassToInstanceMultiMap under a write lock.
        Parameters:
        value - the value to remove
      • removeWithLock

        public void removeWithLock​(@Nullable
                                   Class<?> type)
        Convenience method which executes the like-named method from superclass ClassToInstanceMultiMap under a write lock.
        Parameters:
        type - the type of values to remove
      • removeAllWithLock

        public void removeAllWithLock​(@Nullable @NonnullElements
                                      Iterable<? extends B> removeValues)
        Convenience method which executes the like-named method from superclass ClassToInstanceMultiMap under a write lock.
        Parameters:
        removeValues - the values to remove