Class PathMapBuilderImpl<T>

java.lang.Object
org.refcodes.struct.PathMapBuilderImpl<T>
Type Parameters:
T - the generic type of the elements to be contained herein.
All Implemented Interfaces:
Serializable, Map<String,T>, org.refcodes.mixin.AnnotatorAccessor, org.refcodes.mixin.Clearable, org.refcodes.mixin.DelimiterAccessor, org.refcodes.mixin.Dumpable, org.refcodes.mixin.EmptyAccessor, org.refcodes.mixin.TypeAccessor<T>, Containable, Dictionary<String,T>, Dictionary.MutableDictionary<String,T>, Dictionary.MutableDictionary.DictionaryBuilder<String,T,PathMap.PathMapBuilder<T>>, Keys<String,T>, Keys.MutableKeys<String,T>, Keys.MutableValues<String,T>, PathMap<T>, PathMap.MutablePathMap<T>, PathMap.PathMapBuilder<T>
Direct Known Subclasses:
CanonicalMapBuilderImpl, ClassStructMapBuilderImpl, SimpleTypeMapBuilderImpl

public class PathMapBuilderImpl<T> extends Object implements PathMap.PathMapBuilder<T>, Serializable
The Class PathMapBuilderImpl.
See Also:
  • Field Details

    • _backingMap

      protected Map<String,T> _backingMap
  • Constructor Details

    • PathMapBuilderImpl

      public PathMapBuilderImpl(Class<T> aType)
      Create an empty PathMap.PathMapBuilder instance using the default path delimiter "/" (Delimiter.PATH) for the path declarations.
      Parameters:
      aType - The type of the values being referenced by the paths.
    • PathMapBuilderImpl

      public PathMapBuilderImpl(char aDelimiter, Class<T> aType)
      Create a PathMap.PathMapBuilder instance using the provided path delimiter for the path declarations.
      Parameters:
      aDelimiter - The path delimiter to be used for the path declarations.
      aType - The type of the values being referenced by the paths.
    • PathMapBuilderImpl

      public PathMapBuilderImpl(Object aObj, Class<T> aType)
      Create a PathMap.PathMapBuilder instance containing the elements as of PathMap.MutablePathMap.insert(Object) using the default path delimiter "/" (Delimiter.PATH) for the path declarations.
      Parameters:
      aObj - The object from which the elements are to be added.
      aType - The type of the values being referenced by the paths.
    • PathMapBuilderImpl

      public PathMapBuilderImpl(String aToPath, Object aObj, Class<T> aType)
      Create a PathMap.PathMapBuilder instance containing the elements as of PathMap.MutablePathMap.insert(Object) using the default path delimiter "/" (Delimiter.PATH) for the path declarations.
      Parameters:
      aToPath - The sub-path where to insert the object's introspected values to.
      aObj - The object from which the elements are to be added.
      aType - The type of the values being referenced by the paths.
    • PathMapBuilderImpl

      public PathMapBuilderImpl(Object aObj, String aFromPath, Class<T> aType)
      Creates a PathMap.PathMapBuilder instance containing the elements as of PathMap.MutablePathMap.insert(Object) using the default path delimiter "/" (Delimiter.PATH) for the path declarations.
      Parameters:
      aObj - The object from which the elements are to be added.
      aFromPath - The path from where to start adding elements of the provided object.
      aType - The type of the values being referenced by the paths.
    • PathMapBuilderImpl

      public PathMapBuilderImpl(String aToPath, Object aObj, String aFromPath, Class<T> aType)
      Creates a PathMap.PathMapBuilder instance containing the elements as of PathMap.MutablePathMap.insert(Object) using the default path delimiter "/" (Delimiter.PATH for the path declarations.
      Parameters:
      aToPath - The sub-path where to insert the object's introspected values to.
      aObj - The object from which the elements are to be added.
      aFromPath - The path from where to start adding elements of the provided object.
      aType - The type of the values being referenced by the paths.
    • PathMapBuilderImpl

      public PathMapBuilderImpl(Object aObj, char aDelimiter, Class<T> aType)
      Creates a PathMap.PathMapBuilder instance containing the elements as of PathMap.MutablePathMap.insert(Object).
      Parameters:
      aObj - The object from which the elements are to be added.
      aDelimiter - The path delimiter to be used for the path declarations.
      aType - The type of the values being referenced by the paths.
    • PathMapBuilderImpl

      public PathMapBuilderImpl(String aToPath, Object aObj, char aDelimiter, Class<T> aType)
      Creates a PathMap.PathMapBuilder instance containing the elements as of PathMap.MutablePathMap.insert(Object).
      Parameters:
      aToPath - The sub-path where to insert the object's introspected values to.
      aObj - The object from which the elements are to be added.
      aDelimiter - The path delimiter to be used for the path declarations.
      aType - The type of the values being referenced by the paths.
    • PathMapBuilderImpl

      public PathMapBuilderImpl(Object aObj, String aFromPath, char aDelimiter, Class<T> aType)
      Creates a PathMap.PathMapBuilder instance containing the elements as of PathMap.MutablePathMap.insert(Object).
      Parameters:
      aObj - The object from which the elements are to be added.
      aFromPath - The path from where to start adding elements of the provided object.
      aDelimiter - The path delimiter to be used for the path declarations.
      aType - The type of the values being referenced by the paths.
    • PathMapBuilderImpl

      public PathMapBuilderImpl(String aToPath, Object aObj, String aFromPath, char aDelimiter, Class<T> aType)
      Create a PathMap.PathMapBuilder instance containing the elements as of PathMap.MutablePathMap.insert(Object).
      Parameters:
      aToPath - The sub-path where to insert the object's introspected values to.
      aObj - The object from which the elements are to be added.
      aFromPath - The path from where to start adding elements of the provided object.
      aDelimiter - The path delimiter to be used for the path declarations.
      aType - The type of the values being referenced by the paths.
  • Method Details

    • containsKey

      public boolean containsKey(Object aPath)
      Tests whether there is an element with the given key.
      Specified by:
      containsKey in interface Keys<String,T>
      Specified by:
      containsKey in interface Map<String,T>
      Parameters:
      aPath - The key for which to test whether there is an element.
      Returns:
      True in case there is an element for the given key.
    • get

      public T get(Object aPath)
      Retrieves the element assigned to the given key.
      Specified by:
      get in interface Keys<String,T>
      Specified by:
      get in interface Map<String,T>
      Parameters:
      aPath - The key for which to get the element.
      Returns:
      The value for the key in question or null if there is none such value.
    • put

      public T put(String aPath, T aValue)
      Puts an element identified by the given key.
      Specified by:
      put in interface Keys.MutableValues<String,T>
      Specified by:
      put in interface Map<String,T>
      Parameters:
      aPath - The key which's element is to be put.
      aValue - the value
      Returns:
      The value being overwritten.
    • remove

      public T remove(Object aPath)
      Specified by:
      remove in interface Map<String,T>
    • getOrDefault

      public T getOrDefault(Object aPath, T publicValue)
      Specified by:
      getOrDefault in interface Map<String,T>
    • putIfAbsent

      public T putIfAbsent(String aPath, T value)
      Specified by:
      putIfAbsent in interface Map<String,T>
    • remove

      public boolean remove(Object aPath, Object value)
      Specified by:
      remove in interface Map<String,T>
    • replace

      public boolean replace(String aPath, T oldValue, T newValue)
      Specified by:
      replace in interface Map<String,T>
    • replace

      public T replace(String aPath, T value)
      Specified by:
      replace in interface Map<String,T>
    • computeIfAbsent

      public T computeIfAbsent(String aPath, Function<? super String,? extends T> mappingFunction)
      Specified by:
      computeIfAbsent in interface Map<String,T>
    • computeIfPresent

      public T computeIfPresent(String aPath, BiFunction<? super String,? super T,? extends T> remappingFunction)
      Specified by:
      computeIfPresent in interface Map<String,T>
    • compute

      public T compute(String aPath, BiFunction<? super String,? super T,? extends T> remappingFunction)
      Specified by:
      compute in interface Map<String,T>
    • merge

      public T merge(String aPath, T value, BiFunction<? super T,? super T,? extends T> remappingFunction)
      Specified by:
      merge in interface Map<String,T>
    • retrieveTo

      public PathMap<T> retrieveTo(String aToPath)
      Extracts a new PathMap from this PathMap's elements with the paths relocated to the provided "to-path". Given we have a value for path "/dog/cat" in the PathMap and we call PathMap.retrieveTo(String) with "/animals", then the resulting PathMap will contain the path "/animals/dog/cat" for that value.
      Specified by:
      retrieveTo in interface PathMap<T>
      Parameters:
      aToPath - The path where to relocate the paths of this PathMap to.
      Returns:
      The PathMap with the elements from the provided PathMap with accordingly relocated paths.
    • retrieveFrom

      public PathMap<T> retrieveFrom(String aFromPath)
      Extracts a new PathMap from the elements of this PathMap found below the "from-path". The sub-paths will be the root paths for the new PathMap. Given we have a value for path "/dog/cat" in the PathMap and we call PathMap.retrieveFrom(String) with "/dog", then the resulting PathMap will contain the path "/cat" for that value.
      Specified by:
      retrieveFrom in interface PathMap<T>
      Parameters:
      aFromPath - The path from where to start extracting the paths.
      Returns:
      The PathMap with the elements below the provided path which are root elements in the new PathMap.
    • getDelimiter

      public char getDelimiter()
      Specified by:
      getDelimiter in interface org.refcodes.mixin.DelimiterAccessor
    • getAnnotator

      public char getAnnotator()
      Specified by:
      getAnnotator in interface org.refcodes.mixin.AnnotatorAccessor
    • getType

      public Class<T> getType()
      Specified by:
      getType in interface org.refcodes.mixin.TypeAccessor<T>
    • toDataStructure

      public Object toDataStructure(String aFromPath)
      Similar to the PathMap.toMap(String) method, though in case all the keys of a nested Map instance (applicable to the root Map as well) represent an array (as of PathMap.getArray(String)), then an array is generated where the index of each value in the Map is represented by the number representation of the Map's key for that value. The result is a data structure consisting of Map instances and arrays.
      Specified by:
      toDataStructure in interface PathMap<T>
      Parameters:
      aFromPath - The path below which the PathMap to be converted into a data structure.
      Returns:
      A data structure being a mixture of Map instances and arrays representing the data below the given path.
    • insert

      public void insert(Object aFrom)
      Inspects the given object and adds all elements found in the given object. Elements of type Map, Collection and arrays are identified and handled as of their type: The path for each value in a Map is appended with its according key. The path for each value in a Collection or array is appended with its according index of occurrence (in case of a List or an array, its actual index). In case of reflection, the path for each member is appended with its according mamber's name. All elements (e.g. the members and values) are inspected recursively which results in the according paths of the terminating values.
      Specified by:
      insert in interface PathMap.MutablePathMap<T>
      Parameters:
      aFrom - The object which is to be inspected with the therein contained values being added with their according determined paths.
    • insertBetween

      public void insertBetween(String aToPath, Object aFrom, String aFromPath)
      Same as PathMap.MutablePathMap.insert(Object) though starting insertion of object's introspected values at the given "to-path" and starting object introspection at the given "from-path", e.g. ignoring all paths not starting with the given path during the introspection process. The resulting paths do not start with the "from-path" path, them start with the given "to-path".
      Specified by:
      insertBetween in interface PathMap.MutablePathMap<T>
      Parameters:
      aToPath - The sub-path where to insert the object's introspected values to.
      aFrom - The object which is to be inspected with the therein contained values being added with their according determined paths.
      aFromPath - The path from where to start adding elements of the provided object.
    • insertFrom

      public void insertFrom(Object aFrom, String aFromPath)
      Same as PathMap.MutablePathMap.insert(Object) though starting object introspection at the given "path", e.g. ignoring all paths not starting with the given path during the introspection process. The resulting paths do not start with the provided path.
      Specified by:
      insertFrom in interface PathMap.MutablePathMap<T>
      Parameters:
      aFrom - The object which is to be inspected with the therein contained values being added with their according determined paths.
      aFromPath - The path from where to start adding elements of the provided object.
    • insertTo

      public void insertTo(String aToPath, Object aFrom)
      Same as PathMap.MutablePathMap.insert(Object) though starting insertion of object's introspected values at the given "path".
      Specified by:
      insertTo in interface PathMap.MutablePathMap<T>
      Parameters:
      aToPath - The sub-path where to insert the object's introspected values to.
      aFrom - The object which is to be inspected with the therein contained values being added with their according determined paths.
    • merge

      public void merge(Object aFrom)
      Inspects the given object and adds all elements found in the given object in case the targeted path does not exist or points to a null value. E.g. existing path/value pairs are not overwritten. Elements of type Map, Collection and arrays are identified and handled as of their type: The path for each value in a Map is appended with its according key. The path for each value in a Collection or array is appended with its according index of occurrence (in case of a List or an array, its actual index). In case of reflection, the path for each member is appended with its according mamber's name. All elements (e.g. the members and values) are inspected recursively which results in the according paths of the terminating values.
      Specified by:
      merge in interface PathMap.MutablePathMap<T>
      Parameters:
      aFrom - The object which is to be inspected with the therein contained values being added with their according determined paths.
    • mergeBetween

      public void mergeBetween(String aToPath, Object aFrom, String aFromPath)
      Same as PathMap.MutablePathMap.merge(Object) though starting merging of object's introspected values at the given "to-path" and starting object introspection at the given "from-path", e.g. ignoring all paths not starting with the given path during the introspection process. The resulting paths do not start with the "from-path" path, them start with the given "to-path".
      Specified by:
      mergeBetween in interface PathMap.MutablePathMap<T>
      Parameters:
      aToPath - The sub-path where to merge the object's introspected values to.
      aFrom - The object which is to be inspected with the therein contained values being added with their according determined paths.
      aFromPath - The path from where to start adding elements of the provided object.
    • mergeFrom

      public void mergeFrom(Object aFrom, String aFromPath)
      Same as PathMap.MutablePathMap.merge(Object) though starting object introspection at the given "path", e.g. ignoring all paths not starting with the given path during the introspection process. The resulting paths do not start with the provided path.
      Specified by:
      mergeFrom in interface PathMap.MutablePathMap<T>
      Parameters:
      aFrom - The object which is to be inspected with the therein contained values being added with their according determined paths.
      aFromPath - The path from where to start adding elements of the provided object.
    • mergeTo

      public void mergeTo(String aToPath, Object aFrom)
      Same as PathMap.MutablePathMap.merge(Object) though starting merging of object's introspected values at the given "path".
      Specified by:
      mergeTo in interface PathMap.MutablePathMap<T>
      Parameters:
      aToPath - The sub-path where to merge the object's introspected values to.
      aFrom - The object which is to be inspected with the therein contained values being added with their according determined paths.
    • withPut

      public PathMap.PathMapBuilder<T> withPut(String aKey, T aValue)
      Specified by:
      withPut in interface Dictionary.MutableDictionary.DictionaryBuilder<String,T,PathMap.PathMapBuilder<T>>
      Parameters:
      aKey - the key for the property to be put.
      aValue - the value for the property to be put.
      Returns:
      The implementing instance as of the builder pattern.
    • size

      public int size()
      Returns the number of data elements contained in the collection.
      Specified by:
      size in interface Containable
      Specified by:
      size in interface Map<String,T>
      Returns:
      An integer representing the number of items stored in the accumulation.
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface org.refcodes.mixin.EmptyAccessor
      Specified by:
      isEmpty in interface Map<String,T>
    • containsValue

      public boolean containsValue(Object value)
      This method is defined for the sake of Map conformity. Tests whether the provided value has a key assigned.
      Specified by:
      containsValue in interface Keys<String,T>
      Specified by:
      containsValue in interface Map<String,T>
      Parameters:
      value - The value to test if a key references this value.
      Returns:
      True in case the given value is referenced by a key.
    • putAll

      public void putAll(Map<? extends String,? extends T> m)
      Specified by:
      putAll in interface Map<String,T>
    • clear

      public void clear()
      Specified by:
      clear in interface org.refcodes.mixin.Clearable
      Specified by:
      clear in interface Map<String,T>
    • keySet

      public Set<String> keySet()
      Retrieves a collection containing all the keys found in the elements of this collection.
      Specified by:
      keySet in interface Keys<String,T>
      Specified by:
      keySet in interface Map<String,T>
      Returns:
      A collection with key objects being the keys of all elements in this collection.
    • values

      public Collection<T> values()
      Returns a Collection view of the values related to the contained keys.
      Specified by:
      values in interface Keys<String,T>
      Specified by:
      values in interface Map<String,T>
      Returns:
      A Collection view of the values related to the contained keys.
    • entrySet

      public Set<Map.Entry<String,T>> entrySet()
      Specified by:
      entrySet in interface Map<String,T>
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Map<String,T>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Map<String,T>
      Overrides:
      hashCode in class Object
    • forEach

      public void forEach(BiConsumer<? super String,? super T> action)
      Specified by:
      forEach in interface Map<String,T>
    • replaceAll

      public void replaceAll(BiFunction<? super String,? super T,? extends T> function)
      Specified by:
      replaceAll in interface Map<String,T>
    • toType

      public <TYPE> TYPE toType(String aFromPath, Class<TYPE> aType)
      Creates an instance of the given type filled with this PathMap's data.
      Specified by:
      toType in interface PathMap<T>
      Type Parameters:
      TYPE - the generic type if which to create an instance.
      Parameters:
      aFromPath - The path representing the root from which to take the data for the instance.
      aType - the type if the instance to be filled with the herein contained data.
      Returns:
      the instance initialized with the herein contained data.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • fromValue

      protected void fromValue(String aToPath, Object aValue, Set<Object> aVisited)
    • fromValue

      protected void fromValue(String aToPath, Object aObj)
      Hook method for intercepting or modifying the process of object introspection.
      Parameters:
      aToPath - The sub-path where to insert the object's introspected values to.
      aObj - The object from which the elements are to be added.
    • fromObject

      protected PathMap<T> fromObject(Object aFrom)
      Hook method when internally creating PathMap sub-types in the according PathMap sub-type implementations.
      Parameters:
      aFrom - The Object from which to create a PathMap (sub-type) instance.
      Returns:
      The according PathMap (sub-type) instance.
    • fromInstance

      protected T fromInstance(Object aValue)
      Hook method when introspecting an object to help conversion of that object to the target types. By default this methods just tests for assignment conformity as of Class.isAssignableFrom(Class) with the type retrieved by getType().
      Parameters:
      aValue - The value which is to be transformed to the expected type as of getType().
      Returns:
      The converted type or null if conversion is not possible.
    • toInstance

      protected <TYPE> TYPE toInstance(T aValue, Class<TYPE> aType)
      Hook method when reconstructing an object, opposite of fromInstance(Object), tries to convert the given value to the desired type.
      Type Parameters:
      TYPE - The type to which to convert to.
      Parameters:
      aValue - The value to by converted from this instance's type as of getType() to the desired type.
      aType - The type to which to convert to.
      Returns:
      The converted type or null if conversion is not possible.
    • createBackingMap

      protected Map<String,T> createBackingMap()
      Hook for creating an individual backing Map to be used by the PathMapBuilderImpl.
      Returns:
      The backing Map to be used.