Class QualifiedTypeStore<T>

  • Type Parameters:
    T - the type this store holds
    All Implemented Interfaces:
    Resolver<T>

    public class QualifiedTypeStore<T>
    extends java.lang.Object
    implements Resolver<T>
    Store which keeps track of types T for which a Key can be extracted.

    The store can be searched for all types T matching a Key. For a type T to match it must be of the same type or a subtype of the type in the key, and it must have all the qualifiers specified by the key.

    • Constructor Summary

      Constructors 
      Constructor Description
      QualifiedTypeStore​(java.util.function.Function<T,​Key> keyExtractor, java.util.function.Function<T,​java.util.Set<java.lang.reflect.Type>> typesExtractor)
      Constructs a new instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean contains​(Key key)
      Checks if there is a type T associated with the given Key in the store.
      void put​(T qualifiedType)
      Adds a type T to the store.
      void putAll​(java.util.Collection<T> qualifiedTypes)
      Adds multiple type Ts to the store.
      void remove​(T qualifiedType)
      Removes a type T from the store.
      void removeAll​(java.util.Collection<T> qualifiedTypes)
      Removes multiple type Ts from the store.
      java.util.Set<T> resolve​(Key key)
      Look up types T by Key.
      java.util.Set<T> toSet()
      Returns a set with a copy of all type Ts that are part of this store.
      <U> U toSet​(java.util.function.Function<java.util.stream.Stream<T>,​U> function)
      Applies a function over all type Ts that are part of this store.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • QualifiedTypeStore

        public QualifiedTypeStore​(java.util.function.Function<T,​Key> keyExtractor,
                                  java.util.function.Function<T,​java.util.Set<java.lang.reflect.Type>> typesExtractor)
        Constructs a new instance.
        Parameters:
        keyExtractor - a Function to extract a Key from a type T, cannot be null
        typesExtractor - a Function to extract a set of Type from a type T, cannot be null
    • Method Detail

      • resolve

        public java.util.Set<T> resolve​(Key key)
        Description copied from interface: Resolver
        Look up types T by Key. The empty set is returned if there were no matches.
        Specified by:
        resolve in interface Resolver<T>
        Parameters:
        key - the Key, cannot be null
        Returns:
        a set of type Ts matching the given Key, never null but can be empty
      • contains

        public boolean contains​(Key key)
        Checks if there is a type T associated with the given Key in the store.
        Parameters:
        key - the Key, cannot be null
        Returns:
        true if there was a type T associated with the given Key, otherwise false
      • put

        public void put​(T qualifiedType)
                 throws org.int4.dirk.api.definition.DuplicateDependencyException
        Adds a type T to the store.
        Parameters:
        qualifiedType - a type T, cannot be null
        Throws:
        org.int4.dirk.api.definition.DuplicateDependencyException - when a dependency was already present in the store
      • remove

        public void remove​(T qualifiedType)
                    throws org.int4.dirk.api.definition.MissingDependencyException
        Removes a type T from the store.
        Parameters:
        qualifiedType - a type T, cannot be null
        Throws:
        org.int4.dirk.api.definition.MissingDependencyException - when a dependency was not present in the store
      • putAll

        public void putAll​(java.util.Collection<T> qualifiedTypes)
                    throws org.int4.dirk.api.definition.DuplicateDependencyException
        Adds multiple type Ts to the store. If this method throws an exception then the store will be unmodified.
        Parameters:
        qualifiedTypes - a collection of type Ts, cannot be null or contain nulls but can be empty
        Throws:
        org.int4.dirk.api.definition.DuplicateDependencyException - when a dependency was already present in the store
      • removeAll

        public void removeAll​(java.util.Collection<T> qualifiedTypes)
                       throws org.int4.dirk.api.definition.MissingDependencyException
        Removes multiple type Ts from the store. If this method throws an exception then the store will be unmodified.
        Parameters:
        qualifiedTypes - a collection of type Ts, cannot be null or contain nulls but can be empty
        Throws:
        org.int4.dirk.api.definition.MissingDependencyException - when a dependency was not present in the store
      • toSet

        public java.util.Set<T> toSet()
        Returns a set with a copy of all type Ts that are part of this store.
        Returns:
        a set with a copy of all type Ts that are part of this store, never null or contains nulls but can be empty
      • toSet

        public <U> U toSet​(java.util.function.Function<java.util.stream.Stream<T>,​U> function)
        Applies a function over all type Ts that are part of this store.

        Note: this call is expensive as the stream contains all types in the store. Furthermore, the function provided must call a terminating operation on the stream to avoid unsynchronized access to the stores internal structures.

        Useful for debugging purposes and providing helpful exception messages.

        Type Parameters:
        U - the function result type
        Parameters:
        function - a Function to apply, cannot be null
        Returns:
        the result of applying the given function, can be null
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object