Class DynamicDataContainer

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clear the container of all data.
      java.util.Map<Key,​java.lang.Object> getMap()
      Return a Key - Value Map of the data in the container.
      <T> T getUnsafe​(Key<T> key)
      Get data identified by the Key, or throw an exception.
      <T> java.util.Optional<T> getValue​(Key<T> key)
      Get an Optional of the Value identified by the Key.
      void putAll​(DataContainer dataContainer)
      Place all values from given DataContainer into this container.
      <T> void putCachingSupplier​(Key<T> key, java.util.function.Supplier<T> supplier)
      Place a caching data supplier inside the container.
      <T> void putRawData​(Key<T> key, T obj)
      Place your data inside the container.
      <T> void putSupplier​(Key<T> key, java.util.function.Supplier<T> supplier)
      Place a data supplier inside the container.
      <T> boolean supports​(Key<T> key)
      Check if a Value with the given Key has been placed into the container.
      • Methods inherited from class java.lang.Object

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

      • DynamicDataContainer

        public DynamicDataContainer()
    • Method Detail

      • putRawData

        public <T> void putRawData​(Key<T> key,
                                   T obj)
        Description copied from interface: DataContainer
        Place your data inside the container.

        What the container does with the object depends on the implementation.

        Specified by:
        putRawData in interface DataContainer
        Type Parameters:
        T - Type of the object
        Parameters:
        key - Key of type T that identifies the data and will be used later when the data needs to be fetched.
        obj - object to store
      • putSupplier

        public <T> void putSupplier​(Key<T> key,
                                    java.util.function.Supplier<T> supplier)
        Description copied from interface: DataContainer
        Place a data supplier inside the container.

        What the container does with the supplier depends on the implementation.

        Specified by:
        putSupplier in interface DataContainer
        Type Parameters:
        T - Type of the object
        Parameters:
        key - Key of type T that identifies the data and will be used later when the data needs to be fetched.
        supplier - Supplier to store
      • putCachingSupplier

        public <T> void putCachingSupplier​(Key<T> key,
                                           java.util.function.Supplier<T> supplier)
        Description copied from interface: DataContainer
        Place a caching data supplier inside the container.

        If the supplier is called the value is cached according to the implementation of the container. What the container does with the supplier depends on the implementation.

        Specified by:
        putCachingSupplier in interface DataContainer
        Type Parameters:
        T - Type of the object
        Parameters:
        key - Key of type T that identifies the data and will be used later when the data needs to be fetched.
        supplier - Supplier to store
      • supports

        public <T> boolean supports​(Key<T> key)
        Description copied from interface: DataContainer
        Check if a Value with the given Key has been placed into the container.
        Specified by:
        supports in interface DataContainer
        Type Parameters:
        T - Type of the object returned by the Value if it is present.
        Parameters:
        key - Key that identifies the data.
        Returns:
        true if found, false if not.
      • getValue

        public <T> java.util.Optional<T> getValue​(Key<T> key)
        Description copied from interface: DataContainer
        Get an Optional of the Value identified by the Key.

        It is recommended to check if the Optional is present as null values will be empty.

        Specified by:
        getValue in interface DataContainer
        Type Parameters:
        T - Type of the object returned by Value
        Parameters:
        key - Key that identifies the Value
        Returns:
        Optional of the object if the key is registered and key matches the type of the object. Otherwise empty.
      • getUnsafe

        public <T> T getUnsafe​(Key<T> key)
        Description copied from interface: DataContainer
        Get data identified by the Key, or throw an exception.

        It is recommended to use DataContainer.supports(Key) before using this method.

        Specified by:
        getUnsafe in interface DataContainer
        Type Parameters:
        T - Type of the object returned by Value
        Parameters:
        key - Key that identifies the Value
        Returns:
        the value
      • putAll

        public void putAll​(DataContainer dataContainer)
        Description copied from interface: DataContainer
        Place all values from given DataContainer into this container.
        Specified by:
        putAll in interface DataContainer
        Parameters:
        dataContainer - Container with values.
      • clear

        public void clear()
        Description copied from interface: DataContainer
        Clear the container of all data.
        Specified by:
        clear in interface DataContainer
      • getMap

        public java.util.Map<Key,​java.lang.Object> getMap()
        Description copied from interface: DataContainer
        Return a Key - Value Map of the data in the container.

        This method may call blocking methods if underlying implementation uses the given Suppliers.

        Specified by:
        getMap in interface DataContainer
        Returns:
        Map: Key - Object