Interface MetaInfo

All Superinterfaces:
Iterable<String>

public interface MetaInfo extends Iterable<String>
Interface for meta-information similar to Properties but more sophisticated. Implements Iterable allowing to iterate the available meta-information keys.
Use empty() to get the empty instance and then call any with method to extended with real data. Example to show usage:
 @MetaInfoValues({"key1=value1", "key2=value2"})
 public class AnnotatedClass {
   public static void main(String[] args) {
     MetaInfo metaInfo = MetaInfo.empty().with(AnnotatedClass.class);
     metaInfo = metaInfo.with(Map.of("key2", "two", "key3", "value3"));
     for (String key : metaInfo) {
       String value = metaInfo.get(key);
       System.out.println(key + "=" + value);
     }
   }
 }
 
This will print the following output (order is undefined):
 key1=value1
 key2=two
 key3=value3
 
ATTENTION: Typically the with methods will return a new instance of MetaInfo with the invoked MetaInfo as parent. However, this is not guaranteed. Especially immutable implementations may return a MetaInfo with a different parent.
Since:
1.0.0
  • Method Details

    • get

      default String get(String key)
      Parameters:
      key - the key of the requested meta-information.
      Returns:
      the value of the meta-information for the given key. Will be null if no value is defined for the given key.
    • getRequired

      default String getRequired(String key)
      Parameters:
      key - the key of the requested meta-information.
      Returns:
      the value of the meta-information for the given key. Will be null if no value is defined for the given key.
      Throws:
      ObjectNotFoundException - if the specified value is undefined.
    • get

      default String get(String key, String defaultValue)
      Parameters:
      key - the key of the requested meta-information.
      defaultValue - the default value returned if the actual value is undefined.
      Returns:
      the value of the meta-information for the given key. Will be null if no value is defined for the given key.
    • get

      default String get(boolean inherit, String key, String defaultValue)
      Parameters:
      inherit - - true to inherit meta-information from the parent, false to only return plain meta-information defined in this MetaInfo itself.
      key - the key of the requested meta-information.
      defaultValue - the default value returned if the actual value is undefined.
      Returns:
      the value of the meta-information for the given key. Will be null if no value is defined for the given key.
    • get

      String get(boolean inherit, String key)
      Parameters:
      inherit - - true to inherit meta-information from the parent, false to only return plain meta-information defined in this MetaInfo itself.
      key - the key of the requested meta-information.
      Returns:
      the value of the meta-information for the given key. Will be null if no value is defined for the given key.
    • get

      String get(boolean inherit, boolean required, String key)
      Parameters:
      inherit - - true to inherit meta-information from the parent, false to only return plain meta-information defined in this MetaInfo itself.
      required - - true if the requested value is required and an exception shall be raised if it is undefined, false otherwise (return null if undefined).
      key - the key of the requested meta-information.
      Returns:
      the value of the meta-information for the given key. Will be null if no value is defined for the given key.
      Throws:
      ObjectNotFoundException - if the specified value is undefined and required was true.
    • getGeneric

      <T> T getGeneric(boolean inherit, boolean required, String key, ValueType<T> type)
      Type Parameters:
      T - type of the requested value.
      Parameters:
      inherit - - true to inherit meta-information from the parent, false to only return plain meta-information defined in this MetaInfo itself.
      required - - true if the requested value is required and an exception shall be raised if it is undefined, false otherwise (return null if undefined).
      key - the key of the requested meta-information.
      type - the Class reflecting the requested value.
      parser - the Function to parse the value from a String to the expected value type.
      Returns:
      the value of the meta-information for the given key. Will be null if no value is defined for the given key.
      Throws:
      ObjectNotFoundException - if the specified value is undefined and required was true.
    • getAsInteger

      default Integer getAsInteger(String key)
      Parameters:
      key - the key of the requested meta-information.
      Returns:
      the value of the meta-information for the given key parsed as Integer. Will be null if no value is defined for the given key.
      Throws:
      IllegalArgumentException - if the value cannot be parsed as Integer.
    • getAsIntegerRequired

      default int getAsIntegerRequired(String key)
      Parameters:
      key - the key of the requested meta-information.
      Returns:
      the value of the meta-information for the given key parsed as Integer.
      Throws:
      ObjectNotFoundException - if the specified value is undefined.
      IllegalArgumentException - if the value cannot be parsed as Integer.
    • getAsInteger

      default Integer getAsInteger(boolean inherit, boolean required, String key)
      Parameters:
      inherit - - true to inherit meta-information from the parent, false to only return plain meta-information defined in this MetaInfo itself.
      required - - true if the requested value is required and an exception shall be raised if it is undefined, false otherwise (return null if undefined).
      key - the key of the requested meta-information.
      Returns:
      the value of the meta-information for the given key parsed as Long. Will be null if no value is defined for the given key.
      Throws:
      ObjectNotFoundException - if the specified value is undefined and required was true.
      IllegalArgumentException - if the value cannot be parsed as Integer.
    • getAsInteger

      default int getAsInteger(String key, int defaultValue)
      Parameters:
      key - the key of the requested meta-information.
      defaultValue - the default value returned if the actual value is undefined.
      Returns:
      the value of the meta-information for the given key parsed as
      invalid reference
      int
      . If the actual value is undefined, the given defaultValue will be returned.
      Throws:
      IllegalArgumentException - if the value cannot be parsed as
      invalid reference
      int
      .
    • getAsInteger

      default int getAsInteger(boolean inherit, String key, int defaultValue)
      Parameters:
      inherit - - true to inherit meta-information from the parent, false to only return plain meta-information defined in this MetaInfo itself.
      key - the key of the requested meta-information.
      defaultValue - the default value returned if the actual value is undefined.
      Returns:
      the value of the meta-information for the given key parsed as
      invalid reference
      int
      . If the actual value is undefined, the given defaultValue will be returned.
      Throws:
      IllegalArgumentException - if the value cannot be parsed as
      invalid reference
      int
      .
    • getAsLong

      default Long getAsLong(String key)
      Parameters:
      key - the key of the requested meta-information.
      Returns:
      the value of the meta-information for the given key parsed as Long. Will be null if no value is defined for the given key.
      Throws:
      IllegalArgumentException - if the value cannot be parsed as Long.
    • getAsLongRequired

      default long getAsLongRequired(String key)
      Parameters:
      key - the key of the requested meta-information.
      Returns:
      the value of the meta-information for the given key parsed as Long.
      Throws:
      ObjectNotFoundException - if the specified value is undefined.
      IllegalArgumentException - if the value cannot be parsed as Long.
    • getAsLong

      default Long getAsLong(boolean inherit, boolean required, String key)
      Parameters:
      inherit - - true to inherit meta-information from the parent, false to only return plain meta-information defined in this MetaInfo itself.
      required - - true if the requested value is required and an exception shall be raised if it is undefined, false otherwise (return null if undefined).
      key - the key of the requested meta-information.
      Returns:
      the value of the meta-information for the given key parsed as Long. Will be null if no value is defined for the given key.
      Throws:
      ObjectNotFoundException - if the specified value is undefined and required was true.
      IllegalArgumentException - if the value cannot be parsed as Long.
    • getAsLong

      default long getAsLong(String key, long defaultValue)
      Parameters:
      key - the key of the requested meta-information.
      defaultValue - the default value returned if the actual value is undefined.
      Returns:
      the value of the meta-information for the given key parsed as
      invalid reference
      long
      . If the actual value is undefined, the given defaultValue will be returned.
      Throws:
      IllegalArgumentException - if the value cannot be parsed as
      invalid reference
      long
      .
    • getAsLong

      default long getAsLong(boolean inherit, String key, long defaultValue)
      Parameters:
      inherit - - true to inherit meta-information from the parent, false to only return plain meta-information defined in this MetaInfo itself.
      key - the key of the requested meta-information.
      defaultValue - the default value returned if the actual value is undefined.
      Returns:
      the value of the meta-information for the given key parsed as
      invalid reference
      long
      . If the actual value is undefined, the given defaultValue will be returned.
      Throws:
      IllegalArgumentException - if the value cannot be parsed as
      invalid reference
      long
      .
    • getAsBoolean

      default Boolean getAsBoolean(String key)
      Parameters:
      key - the key of the requested meta-information.
      Returns:
      the value of the meta-information for the given key parsed as Boolean. Will be null if no value is defined for the given key.
      Throws:
      IllegalArgumentException - if the value cannot be parsed as Boolean.
    • getAsBooleanRequired

      default boolean getAsBooleanRequired(String key)
      Parameters:
      key - the key of the requested meta-information.
      Returns:
      the value of the meta-information for the given key parsed as Boolean.
      Throws:
      ObjectNotFoundException - if the specified value is undefined.
      IllegalArgumentException - if the value cannot be parsed as Boolean.
    • getAsBoolean

      default Boolean getAsBoolean(boolean inherit, boolean required, String key)
      Parameters:
      inherit - - true to inherit meta-information from the parent, false to only return plain meta-information defined in this MetaInfo itself.
      required - - true if the requested value is required and an exception shall be raised if it is undefined, false otherwise (return null if undefined).
      key - the key of the requested meta-information.
      Returns:
      the value of the meta-information for the given key parsed as Boolean. Will be null if no value is defined for the given key.
      Throws:
      ObjectNotFoundException - if the specified value is undefined and required was true.
      IllegalArgumentException - if the value cannot be parsed as Boolean.
    • getAsBoolean

      default boolean getAsBoolean(String key, boolean defaultValue)
      Parameters:
      key - the key of the requested meta-information.
      defaultValue - the default value returned if the actual value is undefined.
      Returns:
      the value of the meta-information for the given key parsed as
      invalid reference
      boolean
      . If the actual value is undefined, the given defaultValue will be returned.
      Throws:
      IllegalArgumentException - if the value cannot be parsed as Boolean.
    • getAsBoolean

      default boolean getAsBoolean(boolean inherit, String key, boolean defaultValue)
      Parameters:
      inherit - - true to inherit meta-information from the parent, false to only return plain meta-information defined in this MetaInfo itself.
      key - the key of the requested meta-information.
      defaultValue - the default value returned if the actual value is undefined.
      Returns:
      the value of the meta-information for the given key parsed as
      invalid reference
      boolean
      . If the actual value is undefined, the given defaultValue will be returned.
      Throws:
      IllegalArgumentException - if the value cannot be parsed as Boolean.
    • size

      int size()
      Returns:
      the number of entries contained in this MetaInfo.
    • isEmpty

      default boolean isEmpty()
      Returns:
      true if empty, false otherwise.
    • getParent

      default MetaInfo getParent()
      Returns:
      the potential parent MetaInfo to inherit from. Will be null if nothing is inherited.
    • getKeyPrefix

      default String getKeyPrefix()
      Returns:
      the prefix for the keys as namespace. E.g. if the key prefix is "spring.datasource." and you call get(String) with "password" it will return the property for the key "spring.datasource.password" from the underlying mapping. The default key prefix is the empty String.
    • with

      MetaInfo with(String key, String value)
      Adds or updates the specified meta-info.
      ATTENTION: Please consider using with(Map) and other related factory methods instead of sequentially using this method that may be inefficient.
      Parameters:
      key - the new key of the meta-info.
      value - the new value of the meta-info.
      Returns:
      a new MetaInfo that extends this MetaInfo with the specified meta-information.
    • with

      default MetaInfo with(Map<String,String> map)
      Parameters:
      map - the Map with the meta-information to wrap.
      Returns:
      a new MetaInfo that inherits from this MetaInfo and extends it with the meta-information from the specified parameters.
    • with

      MetaInfo with(Map<String,String> map, String keyPrefix)
      Parameters:
      map - the Map with the meta-information to wrap.
      keyPrefix - the key prefix.
      Returns:
      a new MetaInfo that extends this MetaInfo with the specified meta-information.
    • with

      default MetaInfo with(Properties properties)
      ATTENTION: Due to the design of Properties (with ability for inheritance but no API to get access to the parent defaults) the result will be inefficient.
      Parameters:
      properties - the Properties with the meta-information to wrap.
      Returns:
      a new MetaInfo that extends this MetaInfo with the specified meta-information.
    • with

      MetaInfo with(Properties properties, String keyPrefix)
      ATTENTION: Due to the design of Properties (with ability for inheritance but no API to get access to the parent defaults) the result will be inefficient.
      Parameters:
      properties - the Properties with the meta-information to wrap.
      keyPrefix - the key prefix.
      Returns:
      a new MetaInfo that extends this MetaInfo with the specified meta-information.
    • with

      default MetaInfo with(AnnotatedElement annotatedElement)
      Parameters:
      annotatedElement - the AnnotatedElement (e.g. Class) that is (potentially) annotated with MetaInfos.
      Returns:
      a new MetaInfo that extends this MetaInfo with the meta-information from the given AnnotatedElement. Will be this instance itself if the given AnnotatedElement has no MetaInfos annotation.
    • with

      MetaInfo with(MetaInfos metaValues)
      Parameters:
      metaValues - the MetaInfos.
      Returns:
      a new MetaInfo that extends this MetaInfo with the specified meta-information.
    • with

      MetaInfo with(String keyPrefix)
      Parameters:
      keyPrefix - the key prefix.
      Returns:
      a new MetaInfo that wraps this MetaInfo with all its parents using the given key prefix. The resulting MetaInfo will return null as parent.
    • asProperties

      default Properties asProperties()
      Returns:
      a new Properties instance with all values from this MetaInfo.
    • asMap

      default Map<String,String> asMap()
      Returns:
      a new Map instance with all values from this MetaInfo.
    • empty

      static MetaInfo empty()
      Returns:
      an instance of MetaInfo that is empty.
    • config

      static MetaInfo config()
      Returns:
      the MetaInfo with the configuration for the running application.