Module aeonics.core

Class Config

  • All Implemented Interfaces:
    Exportable, Snapshotable

    public abstract class Config
    extends Manager.Type
    Manages common configuration parameters for all entity instances. The configuration parameters are typically grouped by entity type. Entities have the possibility to watch(String, String, BiConsumer) a specified value and be notified when the value changes.

    The official parameter name is based on a category linked to a class type and a final friendly name. The resulting string can be obrained from implodeName(Class, String). The other way around, the couple of category/name can be retreived using explodeName(String).

    • Constructor Summary

      Constructors 
      Constructor Description
      Config()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​Data>> all()
      Returns all the values for all the parameters of all entity types.
      java.util.Map<java.lang.String,​Data> all​(Entity entity)
      Returns all the values for all the parameters of the given entity type.
      java.util.Map<java.lang.String,​Data> all​(java.lang.Class<?> type)
      Returns all the values for all the parameters of the given entity type.
      abstract java.util.Map<java.lang.String,​Data> all​(java.lang.String type)
      Returns all the values for all the parameters of the given entity type.
      boolean contains​(Entity entity, java.lang.String name)
      Checks if the configuration parameter value for the specified entity type and parameter name is set.
      boolean contains​(java.lang.Class<?> type, java.lang.String name)
      Checks if the configuration parameter value for the specified entity type and parameter name is set.
      boolean contains​(java.lang.String key)
      Checks if the configuration parameter value for the specified concatenated key is set.
      abstract boolean contains​(java.lang.String type, java.lang.String name)
      Checks if the configuration parameter value for the specified entity type and parameter name is set.
      void declare​(java.lang.Class<?> type, Parameter parameter)
      Declares a new common configuration parameter for the target entity type.
      abstract void declare​(java.lang.String type, Parameter parameter)
      Declares a new common configuration parameter for the target entity type.
      Parameter definition​(java.lang.Class<?> type, java.lang.String parameter)
      Returns the parameter definition for the target entity type.
      abstract Parameter definition​(java.lang.String type, java.lang.String parameter)
      Returns the parameter definition for the target entity type.
      static Tuples.Tuple<java.lang.String,​java.lang.String> explodeName​(java.lang.String name)
      Returns the normalized exploded parameter name based on the imploded name.
      Data get​(Entity entity, java.lang.String name)
      Fetches the configuration parameter value for the specified entity type and parameter name.
      Data get​(java.lang.Class<?> type, java.lang.String name)
      Fetches the configuration parameter value for the specified entity type and parameter name.
      Data get​(java.lang.String key)
      Fetches the configuration parameter value for the specified concatenated key.
      abstract Data get​(java.lang.String type, java.lang.String name)
      Fetches the configuration parameter value for the specified entity type and parameter name.
      static java.lang.String implodeName​(Tuples.Tuple<java.lang.String,​java.lang.String> name)
      Returns the normalized imploded parameter name based on the normalized exploded name.
      static java.lang.String implodeName​(java.lang.Class<?> type, java.lang.String name)
      Returns the normalized imploded parameter name based on the type and friendly name.
      static java.lang.String implodeName​(java.lang.String type, java.lang.String name)
      Returns the normalized imploded parameter name based on the type and friendly name.
      java.lang.Class<? extends Manager.Type> manager()
      Hardcoded manager type
      Data remove​(Entity entity, java.lang.String name)
      Removes the value of the specified configuration parameter.
      Data remove​(java.lang.Class<?> type, java.lang.String name)
      Removes the value of the specified configuration parameter.
      Data remove​(java.lang.String key)
      Removes the value of the specified concatenated configuration parameter.
      abstract Data remove​(java.lang.String type, java.lang.String name)
      Removes the value of the specified configuration parameter.
      Data set​(Entity entity, java.lang.String name, java.lang.Object value)
      Sets the value of the specified configuration parameter.
      Data set​(java.lang.Class<?> type, java.lang.String name, java.lang.Object value)
      Sets the value of the specified configuration parameter.
      Data set​(java.lang.String key, java.lang.Object value)
      Sets the value of the specified concatenated configuration parameter.
      abstract Data set​(java.lang.String type, java.lang.String name, java.lang.Object value)
      Sets the value of the specified configuration parameter.
      void watch​(Entity entity, java.lang.String name, Functions.BiConsumer<java.lang.String,​Data> callback)
      Adds a callback that will be triggered when the config value changes.
      void watch​(java.lang.Class<?> type, java.lang.String name, Functions.BiConsumer<java.lang.String,​Data> callback)
      Adds a callback that will be triggered when the config value changes.
      void watch​(java.lang.String key, Functions.BiConsumer<java.lang.String,​Data> callback)
      Adds a callback that will be triggered when the config value changes.
      abstract void watch​(java.lang.String type, java.lang.String name, Functions.BiConsumer<java.lang.String,​Data> callback)
      Adds a callback that will be triggered when the config value changes.
      • Methods inherited from class java.lang.Object

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

      • Config

        public Config()
    • Method Detail

      • manager

        public final java.lang.Class<? extends Manager.Type> manager()
        Hardcoded manager type
        Specified by:
        manager in class Manager.Type
        Returns:
        the type of manager
      • implodeName

        public static java.lang.String implodeName​(java.lang.Class<?> type,
                                                   java.lang.String name)
        Returns the normalized imploded parameter name based on the type and friendly name.

        The normalization process is:

        type.getName().toLowerCase().replace('_', '.') + ":" + name.toLowerCase().replace('_', '.');
        Parameters:
        type - the parameter type
        name - the parameter friendly name
        Returns:
        the normalized parameter name
        See Also:
        explodeName(String)
      • implodeName

        public static java.lang.String implodeName​(java.lang.String type,
                                                   java.lang.String name)
        Returns the normalized imploded parameter name based on the type and friendly name.

        The normalization process is:

        type.toLowerCase().replace('_', '.') + ":" + name.toLowerCase().replace('_', '.');
        Parameters:
        type - the parameter type
        name - the parameter friendly name
        Returns:
        the normalized parameter name
        See Also:
        explodeName(String)
      • implodeName

        public static java.lang.String implodeName​(Tuples.Tuple<java.lang.String,​java.lang.String> name)
        Returns the normalized imploded parameter name based on the normalized exploded name.
        Parameters:
        name - the parameter friendly name
        Returns:
        the normalized parameter name
        See Also:
        implodeName(Class, String)
      • explodeName

        public static Tuples.Tuple<java.lang.String,​java.lang.String> explodeName​(java.lang.String name)
        Returns the normalized exploded parameter name based on the imploded name.
        Parameters:
        name - the imploded parameter name
        Returns:
        the normalized parameter name
        See Also:
        implodeName(Class, String)
      • declare

        public abstract void declare​(java.lang.String type,
                                     Parameter parameter)
        Declares a new common configuration parameter for the target entity type. Redeclaring an existing parameter does not change the current value, only the definition.
        Parameters:
        type - the entity type (should be or will be converted to lower case).
        parameter - the parameter definition
      • declare

        public void declare​(java.lang.Class<?> type,
                            Parameter parameter)
        Declares a new common configuration parameter for the target entity type. Redeclaring an existing parameter does not change the current value, only the definition.
        Parameters:
        type - the entity type
        parameter - the parameter definition
      • definition

        public abstract Parameter definition​(java.lang.String type,
                                             java.lang.String parameter)
        Returns the parameter definition for the target entity type.
        Parameters:
        type - the entity type
        parameter - the parameter name
        Returns:
        the parameter definition or null if the parameter is not found
      • definition

        public Parameter definition​(java.lang.Class<?> type,
                                    java.lang.String parameter)
        Returns the parameter definition for the target entity type.
        Parameters:
        type - the entity type
        parameter - the parameter name
        Returns:
        the parameter definition or null if the parameter is not found
      • get

        public abstract Data get​(java.lang.String type,
                                 java.lang.String name)
        Fetches the configuration parameter value for the specified entity type and parameter name.
        Parameters:
        type - the entity type (should be or will be converted to lower case)
        name - the name of the configuration parameter
        Returns:
        the configuration parameter value or Data.empty() if there is no value
      • get

        public Data get​(java.lang.Class<?> type,
                        java.lang.String name)
        Fetches the configuration parameter value for the specified entity type and parameter name.
        Parameters:
        type - the entity type
        name - the name of the configuration parameter
        Returns:
        the configuration parameter value or Data.empty() if there is no value
      • get

        public Data get​(Entity entity,
                        java.lang.String name)
        Fetches the configuration parameter value for the specified entity type and parameter name.
        Parameters:
        entity - the entity instance. Its Entity.type() method will be used.
        name - the name of the configuration parameter
        Returns:
        the configuration parameter value or Data.empty() if there is no value
      • get

        public Data get​(java.lang.String key)
        Fetches the configuration parameter value for the specified concatenated key. The key will be split by '_' or '.' and converted to lower case: Entity.Type.NAME will be converted to the configuration parameter entity type > name
        Parameters:
        key - the parameter name with at least two components separated by a '.' or a '_'
        Returns:
        the configuration parameter value or Data.empty() if there is no value
      • contains

        public abstract boolean contains​(java.lang.String type,
                                         java.lang.String name)
        Checks if the configuration parameter value for the specified entity type and parameter name is set.
        Parameters:
        type - the entity type (should be or will be converted to lower case)
        name - the name of the configuration parameter
        Returns:
        true if the configuration parameter is set, regardless of its value
      • contains

        public boolean contains​(java.lang.Class<?> type,
                                java.lang.String name)
        Checks if the configuration parameter value for the specified entity type and parameter name is set.
        Parameters:
        type - the entity type
        name - the name of the configuration parameter
        Returns:
        true if the configuration parameter is set, regardless of its value
      • contains

        public boolean contains​(Entity entity,
                                java.lang.String name)
        Checks if the configuration parameter value for the specified entity type and parameter name is set.
        Parameters:
        entity - the entity instance. Its Entity.type() method will be used.
        name - the name of the configuration parameter
        Returns:
        true if the configuration parameter is set, regardless of its value
      • contains

        public boolean contains​(java.lang.String key)
        Checks if the configuration parameter value for the specified concatenated key is set. The key will be split by '_' or '.' and converted to lower case: Entity.Type.NAME will be converted to the configuration parameter entity type > name
        Parameters:
        key - the parameter name with at least two components separated by a '.' or a '_'
        Returns:
        true if the configuration parameter is set, regardless of its value
      • set

        public abstract Data set​(java.lang.String type,
                                 java.lang.String name,
                                 java.lang.Object value)
        Sets the value of the specified configuration parameter.
        Parameters:
        type - the entity type (should be or will be converted to lower case)
        name - the name of the configuration parameter (should be or will be converted to lower case)
        value - the new parameter value
        Returns:
        the previous value associated with that parameter if any
        Throws:
        java.lang.IllegalArgumentException - if the value does not match the parameter requirements
      • set

        public Data set​(java.lang.Class<?> type,
                        java.lang.String name,
                        java.lang.Object value)
        Sets the value of the specified configuration parameter.
        Parameters:
        type - the entity type
        name - the name of the configuration parameter (should be or will be converted to lower case)
        value - the new parameter value
        Returns:
        the previous value associated with that parameter if any
        Throws:
        java.lang.IllegalArgumentException - if the value does not match the parameter requirements
      • set

        public Data set​(Entity entity,
                        java.lang.String name,
                        java.lang.Object value)
        Sets the value of the specified configuration parameter.
        Parameters:
        entity - the entity instance. Its Entity.type() method will be used.
        name - the name of the configuration parameter (should be or will be converted to lower case)
        value - the new parameter value
        Returns:
        the previous value associated with that parameter if any
        Throws:
        java.lang.IllegalArgumentException - if the value does not match the parameter requirements
      • set

        public Data set​(java.lang.String key,
                        java.lang.Object value)
        Sets the value of the specified concatenated configuration parameter. The key will be split by '_' or '.' and converted to lower case: Entity.Type.NAME will be converted to the configuration parameter entity type > name
        Parameters:
        key - the parameter name with at least two components separated by a '.' or a '_'
        value - the new parameter value
        Returns:
        the previous value associated with that parameter if any, or null if the key is invalid
      • remove

        public abstract Data remove​(java.lang.String type,
                                    java.lang.String name)
        Removes the value of the specified configuration parameter.
        Parameters:
        type - the entity type (should be or will be converted to lower case)
        name - the name of the configuration parameter (should be or will be converted to lower case)
        Returns:
        the previous value associated with that parameter if any
      • remove

        public Data remove​(java.lang.Class<?> type,
                           java.lang.String name)
        Removes the value of the specified configuration parameter.
        Parameters:
        type - the entity type
        name - the name of the configuration parameter (should be or will be converted to lower case)
        Returns:
        the previous value associated with that parameter if any
      • remove

        public Data remove​(Entity entity,
                           java.lang.String name)
        Removes the value of the specified configuration parameter.
        Parameters:
        entity - the entity instance. Its Entity.type() method will be used.
        name - the name of the configuration parameter (should be or will be converted to lower case)
        Returns:
        the previous value associated with that parameter if any
      • remove

        public Data remove​(java.lang.String key)
        Removes the value of the specified concatenated configuration parameter. The key will be split by '_' or '.' and converted to lower case: Entity.Type.NAME will be converted to the configuration parameter entity type > name
        Parameters:
        key - the parameter name with at least two components separated by a '.' or a '_'
        Returns:
        the previous value associated with that parameter if any
      • watch

        public void watch​(java.lang.String key,
                          Functions.BiConsumer<java.lang.String,​Data> callback)
        Adds a callback that will be triggered when the config value changes. The key will be split by '_' or '.' and converted to lower case: Entity.Type.NAME will be converted to the configuration parameter entity type > name
        Parameters:
        key - the parameter name with at least two components separated by a '.' or a '_'
        callback - the callback function, it will receive a Tuples.Tuple with the full config key and the value
      • watch

        public void watch​(java.lang.Class<?> type,
                          java.lang.String name,
                          Functions.BiConsumer<java.lang.String,​Data> callback)
        Adds a callback that will be triggered when the config value changes.
        Parameters:
        type - the entity type
        name - the name of the configuration parameter (should be or will be converted to lower case)
        callback - the callback function, it will receive a Tuples.Tuple with the full config key and the value
      • watch

        public void watch​(Entity entity,
                          java.lang.String name,
                          Functions.BiConsumer<java.lang.String,​Data> callback)
        Adds a callback that will be triggered when the config value changes.
        Parameters:
        entity - the entity instance. Its Entity.type() method will be used.
        name - the name of the configuration parameter (should be or will be converted to lower case)
        callback - the callback function, it will receive a Tuples.Tuple with the full config key and the value
      • watch

        public abstract void watch​(java.lang.String type,
                                   java.lang.String name,
                                   Functions.BiConsumer<java.lang.String,​Data> callback)
        Adds a callback that will be triggered when the config value changes.
        Parameters:
        type - the entity type
        name - the name of the configuration parameter (should be or will be converted to lower case)
        callback - the callback function, it will receive a Tuples.Tuple with the full config key and the value
      • all

        public abstract java.util.Map<java.lang.String,​Data> all​(java.lang.String type)
        Returns all the values for all the parameters of the given entity type.
        Parameters:
        type - the entity type (should be or will be converted to lower case)
        Returns:
        all matching parameters and their value
      • all

        public java.util.Map<java.lang.String,​Data> all​(java.lang.Class<?> type)
        Returns all the values for all the parameters of the given entity type.
        Parameters:
        type - the entity type
        Returns:
        all matching parameters and their value
      • all

        public java.util.Map<java.lang.String,​Data> all​(Entity entity)
        Returns all the values for all the parameters of the given entity type.
        Parameters:
        entity - the entity instance. Its Entity.type() method will be used.
        Returns:
        all matching parameters and their value
      • all

        public abstract java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​Data>> all()
        Returns all the values for all the parameters of all entity types.
        Returns:
        all parameters and their value grouped by entity type