Interface PathMap<T>

  • Type Parameters:
    T - The type of the terminating elements.
    All Superinterfaces:
    Containable, org.refcodes.mixin.DelimiterAccessor, Dictionary<java.lang.String,T>, org.refcodes.mixin.Dumpable, Keys<java.lang.String,T>, org.refcodes.mixin.TypeAccessor<T>
    All Known Subinterfaces:
    CanonicalMap, CanonicalMap.CanonicalMapBuilder, CanonicalMap.MutableCanonicalMap, PathMap.MutablePathMap<T>, PathMap.PathMapBuilder<T>
    All Known Implementing Classes:
    CanonicalMapBuilderImpl, CanonicalMapImpl, PathMapBuilderImpl, PathMapImpl

    public interface PathMap<T>
    extends Dictionary<java.lang.String,T>, org.refcodes.mixin.DelimiterAccessor, org.refcodes.mixin.TypeAccessor<T>, org.refcodes.mixin.Dumpable
    A PathMap is a flat map by which each element is addressed by a path; represented by the PathMap's keys. Each path's elements is separated from each other by the DelimiterAccessor.getDelimiter() character, which, by default, is set to '/'. For the sake of simplicity, we assume a path delimiter of '/' being used when describing the functioning of the PathMap. The PathMap distinguishes between records and directories. A record is reckoned to be the last path element in a path pointing to a value. In contrast a directory is reckoned to be be a path element pointing to a succeeding child path element (sub-directory). Given the example below, "dilbert", "otto", "loki" and "gred" are reckoned to be records whereas "animals", "dogs", "machines" and "robots" are recokned to be records:
    • "/animals/dogs/dilbert"
    • "/animals/dogs/otto"
    • "/animals/loki"
    • "/machines/robots/greg"
    To address an element in a PathMap, an absolute path is to be provided, e.g. the provided path must start with the path delimiter. A valid path would look something alike "/animals/dogs/otto". A path is also defined to be an absolute path if it does not(!) begin with a delimiter, e.g. both paths "/machines/robots/greg" and "machines/robots/greg" point to the same "greg" record. Elements in a PathMap are reckoned to be an array when they belong to the same hierarchy level and when their keys represent integer numbers. Given the below example, the elements below "/animals/dogs" can be represented as an array with five elements (the path is denoted at the left hand side of the assignment ":=" and the value at the right and side accordingly):
    • "/animals/dogs/0" := "ace"
    • "/animals/dogs/1" := "bandit"
    • "/animals/dogs/2" := "radar"
    • "/animals/dogs/3" := "echo"
    • "/animals/dogs/4" := "snoopy"
    The resulting array when calling getArray(String) for the path "/animals/dogs" would contain {"ace", "bandit", "radar", "echo", "snoopy"}. Calling isArray("/animals/dogs") would return true whereas calling isArray("/animals") would return false. Before processing, an implementation of the PathMap should call toNormalizedPath(String) for each path provided, which will remove any trailing path separators and add any missing prefixed delimiter. As all the keys in the PathMap represent paths, we can apply some path specific logic to a PathMap. This is reflected by methods such as PathMap.MutablePathMap.insertFrom(Object, String) and PathMap.MutablePathMap.insertTo(String, Object) or retrieveFrom(String) and retrieveTo(String).
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static interface  PathMap.MutablePathMap<T>
      Extends the PathMap with mutator functionality.
      static interface  PathMap.PathMapBuilder<T>
      Extends the PathMap with mutator functionality.
      • Nested classes/interfaces inherited from interface org.refcodes.mixin.DelimiterAccessor

        org.refcodes.mixin.DelimiterAccessor.DelimiterBuilder<B extends org.refcodes.mixin.DelimiterAccessor.DelimiterBuilder<B>>, org.refcodes.mixin.DelimiterAccessor.DelimiterMutator, org.refcodes.mixin.DelimiterAccessor.DelimiterProperty
      • Nested classes/interfaces inherited from interface org.refcodes.mixin.TypeAccessor

        org.refcodes.mixin.TypeAccessor.TypeMutator<T extends java.lang.Object>, org.refcodes.mixin.TypeAccessor.TypeProperty<T extends java.lang.Object>
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      PathMap<T> childrenOf​(java.lang.String aParentPath)
      Gets the children elements of the provided parent's path, excluding the parent's path.
      default java.util.Set<java.lang.String> directories()
      Applies the directories(String) method for the root path "/".
      default java.util.Set<java.lang.String> directories​(java.lang.String aPath)
      Retrieves the directory names below the given path excluding any entries representing records.
      default java.util.Set<java.lang.String> entries()
      Retrieves the records names excluding from the root path.
      default java.util.Set<java.lang.String> entries​(java.lang.String aPath)
      Retrieves the entry names below the given path including records as well as directories.
      default java.lang.String fromExternalKey​(java.lang.String aKey, char... aDelimiters)
      Converts an external key which uses a different notation from DelimiterAccessor.getDelimiter() for the path delimiter and converts those to the default delimiter.
      default T[] getArray()
      Applies the getArray(String) method for the root path "/".
      default T[] getArray​(java.lang.String aPath)
      Returns the records below the given path in an array.
      default java.lang.String getRootPath()
      Returns the path pointing to the root of this PathMap.
      default boolean hasParentPath​(java.lang.String aPath)
      Tests whether there exists a parent path for the given path.
      default boolean isArray()
      Applies the isArray(String) method for the root path "/".
      default boolean isArray​(java.lang.String aPath)
      Determines as of getArray(String) if the elements below the given path can be seen as an array.
      default boolean isDirectory​(java.lang.String aPath)
      Determines whether the give path points to a directory in terms of directories(String).
      default boolean isEntry​(java.lang.String aPath)
      Determines whether the give path points to an entry in terms of entries(String).
      default boolean isRecord​(java.lang.String aPath)
      Determines whether the give path points to a record in terms of records(String).
      default boolean isRootPath​(java.lang.String aPath)
      Determines whether the given path represents the toor path.
      default java.util.Set<java.lang.String> keySet​(java.lang.String aPath)
      Same as Keys.keySet() with the difference, that only the paths are contained belonging to the given path, excluding the given path.
      default java.util.Set<java.lang.String> paths()
      Same as Keys.keySet() with according semantics in the method name.
      default java.util.Set<java.lang.String> paths​(java.lang.String aPath)
      Same as keySet(String) with according semantics in the method name.
      default java.util.Set<java.lang.String> records()
      Applies the records(String) method for the root path "/".
      default java.util.Set<java.lang.String> records​(java.lang.String aPath)
      Retrieves the records names below the given path excluding any entries representing directories.
      default PathMap<T> retrieve​(java.lang.String aFromPath, java.lang.String aToPath)
      Extracts a new PathMap from the elements of this PathMap found below the "from-path".
      PathMap<T> retrieveFrom​(java.lang.String aFromPath)
      Extracts a new PathMap from the elements of this PathMap found below the "from-path".
      PathMap<T> retrieveTo​(java.lang.String aToPath)
      Extracts a new PathMap from this PathMap's elements with the paths relocated to the provided "to-path".
      default java.lang.Object toDataStructure()
      Applies the toDataStructure(String) method for the root path "/".
      java.lang.Object toDataStructure​(java.lang.String aFromPath)
      Similar to the 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 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.
      default java.lang.String toExternalKey​(java.lang.String aKey, char aDelimiter)
      Converts the given key to an external key by converting the default delimiter DelimiterAccessor.getDelimiter() to the provided delimiter.
      default java.util.Map<java.lang.String,?> toMap()
      Applies the toMap(String) method for the root path "/".
      default java.util.Map<java.lang.String,?> toMap​(java.lang.String aFromPath)
      Creates a nested Map structure from the PathMap's entries below the provided path.
      default java.lang.String toNormalizedPath​(java.lang.String aPath)
      Normalizes a path for it to start with the delimiter (as of DelimiterAccessor.getDelimiter()) and for it not to end with a delimiter.
      default java.lang.String toNormalizedPath​(java.lang.String aParentPath, java.lang.String aChildPath)
      Creates a normalized path for the child path being relative to the given parent path.
      default java.lang.String toParentPath​(java.lang.String aPath)
      Returns the path representing the parent path for the given path.
      default java.lang.String toPath​(java.lang.String... aPathElements)
      Creates a normalized path from the provided path elements by concatenating the elements with the path delimiter DelimiterAccessor.getDelimiter() in between and taking care to avoid duplicate path delimiters.
      • Methods inherited from interface org.refcodes.mixin.DelimiterAccessor

        getDelimiter
      • Methods inherited from interface org.refcodes.mixin.Dumpable

        toDump, toDump
      • Methods inherited from interface org.refcodes.mixin.TypeAccessor

        getType
    • Method Detail

      • isArray

        default boolean isArray​(java.lang.String aPath)
        Determines as of getArray(String) if the elements below the given path can be seen as an array.
        Parameters:
        aPath - the path
        Returns:
        True in case we have an array structure below the path or not.
      • getArray

        default T[] getArray​(java.lang.String aPath)
        Returns the records below the given path in an array. Records in a PathMap are reckoned to be part of an array when they belong to the same hierarchy level and when their keys represent integer numbers. Given the below example, the elements below "/animals/dogs" can be represented as an array with five elements (the path is denoted at the left hand side of the assignment ":=" operator and the value at the right and side accordingly):
        • "/animals/dogs/0" := "ace"
        • "/animals/dogs/1" := "bandit"
        • "/animals/dogs/2" := "radar"
        • "/animals/dogs/3" := "echo"
        • "/animals/dogs/4" := "snoopy"
        The resulting array when calling getArray(String) for the path "/animals/dogs" would contain {"ace", "bandit", "radar", "echo", "snoopy"}. Calling isArray("/animals/dogs") would return true whereas calling isArray("/animals") would return false.
        Parameters:
        aPath - the path
        Returns:
        An array of the records found below the given path.
      • keySet

        default java.util.Set<java.lang.String> keySet​(java.lang.String aPath)
        Same as Keys.keySet() with the difference, that only the paths are contained belonging to the given path, excluding the given path.
        Parameters:
        aPath - The path from which to start retrieving the paths.
        Returns:
        The relative paths starting at the given path (excluding the preceding given path) contained in this PathMap.
      • paths

        default java.util.Set<java.lang.String> paths()
        Same as Keys.keySet() with according semantics in the method name.
        Returns:
        The paths which are assigned to values.
      • paths

        default java.util.Set<java.lang.String> paths​(java.lang.String aPath)
        Same as keySet(String) with according semantics in the method name.
        Parameters:
        aPath - The path from which to start seeking.
        Returns:
        The paths (excluding the preceding given path) which are assigned to values.
      • isEntry

        default boolean isEntry​(java.lang.String aPath)
        Determines whether the give path points to an entry in terms of entries(String).
        Parameters:
        aPath - The path for which to determine whether it points to a entry.
        Returns:
        True in case the given path points to a entry, else false.
      • entries

        default java.util.Set<java.lang.String> entries()
        Retrieves the records names excluding from the root path. Record names point to values and do not represent a sup-path. Also any paths pointing to a value (not being a sub-path) are excluded. Given we have values for paths "/dog/cat" and "/cat/mouse" in the PathMap and we call records(), then the resulting Set will contain the values "dog" and "cat".
        Returns:
        The relative directory names starting at the root path contained in this PathMap.
      • entries

        default java.util.Set<java.lang.String> entries​(java.lang.String aPath)
        Retrieves the entry names below the given path including records as well as directories. A record is reckoned to be the last path element in a path pointing to a value. In contrast a directory is reckoned to be be a path element pointing to a succeeding child path element (sub-directory). Given we have values for paths in our PathMap:
        • "/animals/dogs/dilbert"
        • "/animals/dogs/otto"
        • "/animals/loki"
        • "/machines/robots/greg"
        When we call directories(String) with "/animals", then the resulting Set will just contain "dogs"; calling "/" will retrieve "animals" and "machines".
        Parameters:
        aPath - The path from which to start retrieving the directories.
        Returns:
        The directory names (excluding the preceding given path) of the directories below the given path contained within this PathMap.
      • isDirectory

        default boolean isDirectory​(java.lang.String aPath)
        Determines whether the give path points to a directory in terms of directories(String).
        Parameters:
        aPath - The path for which to determine whether it points to a directory.
        Returns:
        True in case the given path points to a directory, else false.
      • directories

        default java.util.Set<java.lang.String> directories​(java.lang.String aPath)
        Retrieves the directory names below the given path excluding any entries representing records. A record is reckoned to be the last path element in a path pointing to a value. In contrast a directory is reckoned to be be a path element pointing to a succeeding child path element (sub-directory). Given we have values for paths in our PathMap:
        • "/animals/dogs/dilbert"
        • "/animals/dogs/otto"
        • "/animals/loki"
        • "/machines/robots/greg"
        When we call directories(String) with "/animals", then the resulting Set will just contain "dogs"; calling "/" will retrieve "animals" and "machines".
        Parameters:
        aPath - The path from which to start retrieving the directories.
        Returns:
        The directory names (excluding the preceding given path) of the directories below the given path contained within this PathMap.
      • isRecord

        default boolean isRecord​(java.lang.String aPath)
        Determines whether the give path points to a record in terms of records(String).
        Parameters:
        aPath - The path for which to determine whether it points to a record.
        Returns:
        True in case the given path points to a record, else false.
      • records

        default java.util.Set<java.lang.String> records​(java.lang.String aPath)
        Retrieves the records names below the given path excluding any entries representing directories. A record is reckoned to be the last path element in a path pointing to a value. In contrast a directory is reckoned to be be a path element pointing to a succeeding child path element (sub-directory). Given we have values for paths in our PathMap:
        • "/animals/dogs/dilbert"
        • "/animals/dogs/otto"
        • "/animals/loki"
        • "/machines/robots/greg"
        When we call records(String) with "/animals", then the resulting Set will just contain "loki"; calling "/animals/dogs" will retrieve "dilbert" and "otto".
        Parameters:
        aPath - The path from which to start retrieving the records.
        Returns:
        The record names (excluding the preceding given path) of the records below the given path contained within this PathMap.
      • retrieveFrom

        PathMap<T> retrieveFrom​(java.lang.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 retrieveFrom(String) with "/dog", then the resulting PathMap will contain the path "/cat" for that value.
        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.
      • retrieveTo

        PathMap<T> retrieveTo​(java.lang.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 retrieveTo(String) with "/animals", then the resulting PathMap will contain the path "/animals/dog/cat" for that value.
        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.
      • childrenOf

        PathMap<T> childrenOf​(java.lang.String aParentPath)
        Gets the children elements of the provided parent's path, excluding the parent's path.
        Parameters:
        aParentPath - The path from where to retrieve the children.
        Returns:
        The children of the given parent's path.
      • retrieve

        default PathMap<T> retrieve​(java.lang.String aFromPath,
                                    java.lang.String aToPath)
        Extracts a new PathMap from the elements of this PathMap found below the "from-path". The sub-paths will be relocated to the provided "to-path".
        Parameters:
        aFromPath - The path from where to start extracting the paths.
        aToPath - The path where to relocate the extracted paths to.
        Returns:
        The PathMap with the elements below the provided path "from-path" relocated to the given "to-path".
      • toMap

        default java.util.Map<java.lang.String,?> toMap()
                                                 throws java.lang.IllegalStateException
        Applies the toMap(String) method for the root path "/".
        Returns:
        As of toMap(String) applied to the root path.
        Throws:
        java.lang.IllegalStateException - the illegal state exception
      • toMap

        default java.util.Map<java.lang.String,?> toMap​(java.lang.String aFromPath)
                                                 throws java.lang.IllegalStateException
        Creates a nested Map structure from the PathMap's entries below the provided path. Each element of the paths (below the provided path), except of the last (pointing to the path's value) is represented by a Map contained in the preceeding's path element.
        Parameters:
        aFromPath - The path from which to start retrieving the sub-paths which will be the root directories in the returned Map
        Returns:
        The nested Map representing this PathMap starting from the given path.
        Throws:
        java.lang.IllegalStateException - in case the PathMap contains a path which points to a value and which is also part of other paths. Such a state cannot be represented by a nested Map structure as the element would represent a leaf and a node at the same time.
      • toDataStructure

        java.lang.Object toDataStructure​(java.lang.String aFromPath)
        Similar to the 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 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.
        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.
      • toNormalizedPath

        default java.lang.String toNormalizedPath​(java.lang.String aPath)
        Normalizes a path for it to start with the delimiter (as of DelimiterAccessor.getDelimiter()) and for it not to end with a delimiter. This implementation will return in empty String in case the path is an empty String or the path just consists of a delimiter: Any missing prefixed (starting) delimiter is added and any suffixed delimiters are removed, ending up with an empty String
        Parameters:
        aPath - The path to be normalized.
        Returns:
        The normalized path; afterwards (in case the path was not an empty String or just the delimiter itself) it starts with a delimiter and does not end with a delimiter.
      • fromExternalKey

        default java.lang.String fromExternalKey​(java.lang.String aKey,
                                                 char... aDelimiters)
        Converts an external key which uses a different notation from DelimiterAccessor.getDelimiter() for the path delimiter and converts those to the default delimiter.
        Parameters:
        aKey - The key which's delimiters are to be converted to the default DelimiterAccessor.getDelimiter() delimiter.
        aDelimiters - The "external" delimiters in question.
        Returns:
        The converted key using the default delimiter DelimiterAccessor.getDelimiter() instead of the provided delimiters.
      • toExternalKey

        default java.lang.String toExternalKey​(java.lang.String aKey,
                                               char aDelimiter)
        Converts the given key to an external key by converting the default delimiter DelimiterAccessor.getDelimiter() to the provided delimiter. In case we have a provided delimiter different from the commonly used path delimiters "/" or "\", then a prefixed delimiter is removed.
        Parameters:
        aKey - The key which is to be converted to its external representation.
        aDelimiter - The delimiter to be used for the external representation instead if the default delimiter DelimiterAccessor.getDelimiter().
        Returns:
        The external representation of the key as of the provided delimiter.
      • getRootPath

        default java.lang.String getRootPath()
        Returns the path pointing to the root of this PathMap. By default the Root-Path consists just of the one delimiter DelimiterAccessor.getDelimiter() character.
        Returns:
        The path pointing to the root of this PathMap.
      • toPath

        default java.lang.String toPath​(java.lang.String... aPathElements)
        Creates a normalized path from the provided path elements by concatenating the elements with the path delimiter DelimiterAccessor.getDelimiter() in between and taking care to avoid duplicate path delimiters.
        Parameters:
        aPathElements - The elements of the path to be concatenated with the path delimiter.
        Returns:
        The concatenated and normalized path.
      • isRootPath

        default boolean isRootPath​(java.lang.String aPath)
        Determines whether the given path represents the toor path.
        Parameters:
        aPath - The path to be tested.
        Returns:
        True in case we have a root path, else false.
      • toNormalizedPath

        default java.lang.String toNormalizedPath​(java.lang.String aParentPath,
                                                  java.lang.String aChildPath)
        Creates a normalized path for the child path being relative to the given parent path.
        Parameters:
        aParentPath - The path relative to which the child path is interpreted.
        aChildPath - The path relative to the parent's path.
        Returns:
        The accordingly normalized path as of toNormalizedPath(String).
      • hasParentPath

        default boolean hasParentPath​(java.lang.String aPath)
        Tests whether there exists a parent path for the given path. Given we have a path "/animals/dogs/otto", then its parent path is "/animals/dogs".
        Parameters:
        aPath - The path for which to test if it has the parent path.
        Returns:
        True in case the path has a parent, else false.
      • toParentPath

        default java.lang.String toParentPath​(java.lang.String aPath)
        Returns the path representing the parent path for the given path. Given we have a path "/animals/dogs/otto", then its parent path is "/animals/dogs".
        Parameters:
        aPath - The path for which to get the parent's path.
        Returns:
        The parent path.
        Throws:
        java.lang.IllegalArgumentException - thrown in case there is no such parent path for the given path; test beforehand using hasParentPath(String).