Class ConfigPath


  • public class ConfigPath
    extends java.lang.Object
    Сonfiguration path's value. Value is resolved using type information from configuration class and actual instance analysis. This means that item declaration could change if configuration changes. The most obvious example is property-dependent mapping, like server object (when one property could completely change available configuration paths (simple and usual servers)).

    One edge case is possible (but assumed to never happen): when property declared as Object in class, actual type could be resolved from value. But that means that if value become null, property binding type would change to Object. Assume no one would ever use Object for configuration property (or, if so, value will never be null because otherwise there will be no binding available in both cases).

    Item contains root and child references and might be traversed like a tree.

    Since:
    04.05.2018
    • Constructor Summary

      Constructors 
      Constructor Description
      ConfigPath​(ConfigPath root, java.lang.Class declarationClass, java.lang.Class declaredType, java.lang.Class valueType, java.util.List<java.lang.reflect.Type> declaredTypeGenerics, java.util.List<java.lang.reflect.Type> valueTypeGenerics, java.lang.String path, java.lang.Object value, boolean customType, boolean objectDeclaration, java.lang.annotation.Annotation qualifier)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      java.util.List<ConfigPath> getChildren()
      For example, if current path is "sub" then returned items would be next level paths: "sub.val1", "sub.val2" etc.
      java.lang.Class getDeclarationClass()
      Note that this would be last path's part (property) declaration class.
      java.lang.Class getDeclaredType()
      If property is declared as collection implementation then collection interface will be used instead.
      java.util.List<java.lang.Class> getDeclaredTypeGenericClasses()
      Useful for quick analysis when deeper generic type knowledge is not important (e.g. to know type in list, set or map).
      java.util.List<java.lang.reflect.Type> getDeclaredTypeGenerics()
      For example, if value is List then one parameter will be available with list generic type.
      java.lang.reflect.Type getDeclaredTypeWithGenerics()  
      java.lang.String getLastPathLevel()  
      java.lang.String getPath()
      E.g.
      java.lang.annotation.Annotation getQualifier()
      Custom qualifiers might be used to simplify configuration bindings (because @Config qualifier requires the exact yaml path).
      ConfigPath getRoot()
      For example, if current path is "some.long.path" then method returns "some.long" path item.
      java.lang.Class getRootDeclarationClass()
      Useful to filter out core dropwizard properties (where root type would be Configuration.
      java.lang.reflect.Type getTypeWithGenerics()
      When value null will be the same as getDeclaredTypeWithGenerics().
      java.lang.Object getValue()  
      java.lang.Class getValueType()
      When value is null, type may be still different from getDeclaredType() if declared type was actually some collection implementation.
      java.util.List<java.lang.Class> getValueTypeGenericClasses()
      Useful for quick analysis when deeper generic type knowledge is not important..
      java.util.List<java.lang.reflect.Type> getValueTypeGenerics()
      Even when value is null, generics could differ from declared type generics.
      int hashCode()  
      boolean isCustomType()
      Type considered custom when it's not primitive, collection and few other simple types.
      boolean isObjectDeclaration()
      True means that property declared as Object.
      java.lang.String toString()  
      java.lang.String toStringDeclaredType()  
      java.lang.String toStringType()  
      java.lang.String toStringValue()
      Only put string values other than null into quotes (to be more obvious).
      • Methods inherited from class java.lang.Object

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

      • ConfigPath

        public ConfigPath​(ConfigPath root,
                          java.lang.Class declarationClass,
                          java.lang.Class declaredType,
                          java.lang.Class valueType,
                          java.util.List<java.lang.reflect.Type> declaredTypeGenerics,
                          java.util.List<java.lang.reflect.Type> valueTypeGenerics,
                          java.lang.String path,
                          java.lang.Object value,
                          boolean customType,
                          boolean objectDeclaration,
                          java.lang.annotation.Annotation qualifier)
    • Method Detail

      • getRoot

        public ConfigPath getRoot()
        For example, if current path is "some.long.path" then method returns "some.long" path item.
        Returns:
        parent config level or null for root level
      • getChildren

        public java.util.List<ConfigPath> getChildren()
        For example, if current path is "sub" then returned items would be next level paths: "sub.val1", "sub.val2" etc. Useful for manual config analysis.
        Returns:
        list of child properties
      • getDeclarationClass

        public java.lang.Class getDeclarationClass()
        Note that this would be last path's part (property) declaration class. For example, for path "some.path" it would be class of "some" (sub object of configuration).
        Returns:
        class where property was declared
      • getDeclaredType

        public java.lang.Class getDeclaredType()
        If property is declared as collection implementation then collection interface will be used instead. For example, ArrayList<String> then declaration type would be List<String>.

        Edge case possible: if class declaration is Object and value is not null then actual value would be taken from value. This case should never appear, because it's insane to use Object to declare property type.

        Returns:
        type declaration from class
      • getValueType

        public java.lang.Class getValueType()
        When value is null, type may be still different from getDeclaredType() if declared type was actually some collection implementation.
        Returns:
        actual path value type (from actual instance or declared type, when instance is null)
      • getDeclaredTypeGenerics

        public java.util.List<java.lang.reflect.Type> getDeclaredTypeGenerics()
        For example, if value is List then one parameter will be available with list generic type.

        When actual generics are not set then upper bounds of declared generics will be used. For example, for List it will be [Object] and for class Some<T extends Comparable> - [Comparable].

        Returns:
        binding type generics or empty list if not generified type
        See Also:
        getDeclaredTypeGenericClasses()
      • getValueTypeGenerics

        public java.util.List<java.lang.reflect.Type> getValueTypeGenerics()
        Even when value is null, generics could differ from declared type generics. For example, declaration is ExtraList<String, Integer>, declaration type List<String> (so it's generics just [List]). And type generics would be [String, Integer].
        Returns:
        generics of value type or empty list if not generified type
      • getPath

        public java.lang.String getPath()
        E.g. "some.property.path".
        Returns:
        full yaml path of property
      • getValue

        public java.lang.Object getValue()
        Returns:
        property value (may be null)
      • isCustomType

        public boolean isCustomType()
        Type considered custom when it's not primitive, collection and few other simple types. In essence, this is type which contains (or might contain) sub paths.
        Returns:
        true when value is sub-configuration object, false when value is just a value
      • isObjectDeclaration

        public boolean isObjectDeclaration()
        True means that property declared as Object. In this case type could be resolved from actual value (if it's not null). This should be next to impossible case for sane configurations (who would use Object for configuration property?).

        Indicator might be important because in this case binding would be of Object type when value is null and with value type for not null value.

        Returns:
        true when property is declared as Object in class, false otherwise
      • getQualifier

        public java.lang.annotation.Annotation getQualifier()
        Custom qualifiers might be used to simplify configuration bindings (because @Config qualifier requires the exact yaml path).
        Returns:
        custom qualifier annotation declared on config class or null
      • getDeclaredTypeGenericClasses

        public java.util.List<java.lang.Class> getDeclaredTypeGenericClasses()
        Useful for quick analysis when deeper generic type knowledge is not important (e.g. to know type in list, set or map).
        Returns:
        declared type generics as class or empty map if not generics
        See Also:
        getDeclaredTypeGenerics()
      • getValueTypeGenericClasses

        public java.util.List<java.lang.Class> getValueTypeGenericClasses()
        Useful for quick analysis when deeper generic type knowledge is not important..
        Returns:
        value type generics as class or empty map if not generics
      • getRootDeclarationClass

        public java.lang.Class getRootDeclarationClass()
        Useful to filter out core dropwizard properties (where root type would be Configuration.
        Returns:
        root configuration class where entire path started
      • getDeclaredTypeWithGenerics

        public java.lang.reflect.Type getDeclaredTypeWithGenerics()
        Returns:
        declared type with known generics (parameterized type) or simple class if no generics provided
      • getTypeWithGenerics

        public java.lang.reflect.Type getTypeWithGenerics()
        When value null will be the same as getDeclaredTypeWithGenerics(). If types are different (value not null), then actual type generics will be tracked from known definition generics.
        Returns:
        value type with generics (parameterized type) or simple clas if not generics provided
      • getLastPathLevel

        public java.lang.String getLastPathLevel()
        Returns:
        last path element (e.g. for "some.long.path" return "path")
      • toStringDeclaredType

        public java.lang.String toStringDeclaredType()
        Returns:
        declared type string including generics
      • toStringType

        public java.lang.String toStringType()
        Returns:
        value type string including generics
      • toStringValue

        public java.lang.String toStringValue()
        Only put string values other than null into quotes (to be more obvious).
        Returns:
        value as string
      • toString

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

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object