Package org.refcodes.structure
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
APathMap
is a flat map by which each element is addressed by a path; represented by thePathMap
's keys. Each path's elements is separated from each other by theDelimiterAccessor.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 thePathMap
. ThePathMap
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"
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 aPathMap
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"
getArray(String)
for the path "/animals/dogs" would contain {"ace", "bandit", "radar", "echo", "snoopy"}. CallingisArray("/animals/dogs")
would returntrue
whereas callingisArray("/animals")
would return false. Before processing, an implementation of thePathMap
should calltoNormalizedPath(String)
for each path provided, which will remove any trailing path separators and add any missing prefixed delimiter. As all the keys in thePathMap
represent paths, we can apply some path specific logic to aPathMap
. This is reflected by methods such asPathMap.MutablePathMap.insertFrom(Object, String)
andPathMap.MutablePathMap.insertTo(String, Object)
orretrieveFrom(String)
andretrieveTo(String)
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
PathMap.MutablePathMap<T>
Extends thePathMap
with mutator functionality.static interface
PathMap.PathMapBuilder<T>
Extends thePathMap
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.structure.Dictionary
Dictionary.MutableDictionary<K,V>
-
Nested classes/interfaces inherited from interface org.refcodes.structure.Keys
Keys.MutableKeys<K,V>, Keys.MutableValues<K,V>
-
-
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 thedirectories(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 fromDelimiterAccessor.getDelimiter()
for the path delimiter and converts those to the default delimiter.default T
get(java.lang.Object... aPathElements)
Experimental convenience method: Applies theKeys.get(Object)
method for the provided path elements by first converting them to aString
(if not being aString
already) and then concatenating the elements with the path delimiterDelimiterAccessor.getDelimiter()
in between and taking care to avoid duplicate path delimiters.default T
get(java.lang.String... aPathElements)
Experimental convenience method: Applies theKeys.get(Object)
method for the provided path elements by concatenating the elements with the path delimiterDelimiterAccessor.getDelimiter()
in between and taking care to avoid duplicate path delimiters.default T[]
getArray()
Applies thegetArray(String)
method for the root path "/".default T[]
getArray(java.lang.String aPath)
Returns the records below the given path in an array.default PathMap<T>
getIndexed(int aIndex)
Returns the accordingly indexed Elements of the root "array" path.default PathMap<T>
getIndexed(java.lang.String aPath, int aIndex)
Returns the accordingly indexed Elements of the root "array" path.default int[]
getIndexes()
Returns the indexes pointing to elements of the root "array" path.default int[]
getIndexes(java.lang.String aPath)
Returns the indexes pointing to elements of the given "array" path.default java.lang.String
getRootPath()
Returns the path pointing to the root of thisPathMap
.default boolean
hasIndexed(int aIndex)
Determines whether the index points to an index root "array" path.default boolean
hasIndexed(java.lang.String aPath, int aIndex)
Determines whether the index points to an index root "array" path.default boolean
hasParentPath(java.lang.String aPath)
Tests whether there exists a parent path for the given path.default boolean
isArray()
Applies theisArray(String)
method for the root path "/".default boolean
isArray(java.lang.String aPath)
Determines as ofgetArray(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 ofdirectories(String)
.default boolean
isEntry(java.lang.String aPath)
Determines whether the give path points to an entry in terms ofentries(String)
.default boolean
isIndexed()
Determines whether the root path represents an "array" path with indexes within the givenPathMap
.default boolean
isIndexed(java.lang.String aPath)
Determines whether the provided path represents an "array" path with indexes within the givenPathMap
.default boolean
isPath(java.lang.String aPath)
Determines whether the provided path represents a path within the givenPathMap
.default boolean
isRecord(java.lang.String aPath)
Determines whether the give path points to a record in terms ofrecords(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 asKeys.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 asKeys.keySet()
with according semantics in the method name.default java.util.Set<java.lang.String>
paths(java.lang.String aPath)
Same askeySet(String)
with according semantics in the method name.default java.util.Set<java.lang.String>
records()
Applies therecords(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)
PathMap<T>
retrieveFrom(java.lang.String aFromPath)
PathMap<T>
retrieveTo(java.lang.String aToPath)
default java.lang.Object
toDataStructure()
Applies thetoDataStructure(String)
method for the root path "/".java.lang.Object
toDataStructure(java.lang.String aFromPath)
Similar to thetoMap(String)
method, though in case all the keys of a nestedMap
instance (applicable to the rootMap
as well) represent an array (as ofgetArray( String)
), then an array is generated where the index of each value in theMap
is represented by the number representation of theMap
'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 delimiterDelimiterAccessor.getDelimiter()
to the provided delimiter.default java.util.Map<java.lang.String,?>
toMap()
Applies thetoMap(String)
method for the root path "/".default java.util.Map<java.lang.String,?>
toMap(java.lang.String aFromPath)
Creates a nestedMap
structure from thePathMap
'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 ofDelimiterAccessor.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.Object... aPathElements)
Creates a normalized path from the provided path elements by first converting them to aString
(if not being aString
already) and then concatenating the elements with the path delimiterDelimiterAccessor.getDelimiter()
in between and taking care to avoid duplicate path delimiters.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 delimiterDelimiterAccessor.getDelimiter()
in between and taking care to avoid duplicate path delimiters.-
Methods inherited from interface org.refcodes.structure.Containable
isEmpty, size
-
Methods inherited from interface org.refcodes.structure.Keys
containsKey, containsValue, get, keySet, use, values
-
-
-
-
Method Detail
-
get
default T get(java.lang.Object... aPathElements)
Experimental convenience method: Applies theKeys.get(Object)
method for the provided path elements by first converting them to aString
(if not being aString
already) and then concatenating the elements with the path delimiterDelimiterAccessor.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:
- As of
Keys.get(Object)
applied path the path elements. - See Also:
Keys.get(Object)
-
get
default T get(java.lang.String... aPathElements)
Experimental convenience method: Applies theKeys.get(Object)
method for the provided path elements by concatenating the elements with the path delimiterDelimiterAccessor.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:
- As of
Keys.get(Object)
applied path the path elements. - See Also:
Keys.get(Object)
-
isPath
default boolean isPath(java.lang.String aPath)
Determines whether the provided path represents a path within the givenPathMap
. The path not necessarily points to a leaf in terms of being a record or a directory. UseisEntry(String)
(isRecord(String)
orisDirectory(String)
) if we have a leaf.- Parameters:
aPath
- The path to be tested.- Returns:
- True in case we have a path being contained in the given
PathMap
, else false.
-
isIndexed
default boolean isIndexed()
Determines whether the root path represents an "array" path with indexes within the givenPathMap
. The path not necessarily points to a leaf in terms of being a record or a directory. UseisEntry(String)
(isRecord(String)
orisDirectory(String)
) if we have a leaf. Given the following paths:/0/0aaa /0/0bbb /0/0bbb /1/1aaa /1/1bbb /1/1bbb
The root path points to an index path with the two indexes "0" and "1".- Returns:
- True in case we have a path points to an array being contained in
the given
PathMap
, else false.
-
isIndexed
default boolean isIndexed(java.lang.String aPath)
Determines whether the provided path represents an "array" path with indexes within the givenPathMap
. The path not necessarily points to a leaf in terms of being a record or a directory. UseisEntry(String)
(isRecord(String)
orisDirectory(String)
) if we have a leaf. Given the following paths:/root/child/0/0aaa /root/child/0/0bbb /root/child/0/0bbb /root/child/1/1aaa /root/child/1/1bbb /root/child/1/1bbb
The path "/root/child" points to an index path with the two indexes "0" and "1".- Parameters:
aPath
- The path to be tested.- Returns:
- True in case we have a path points to an array being contained in
the given
PathMap
, else false.
-
getIndexes
default int[] getIndexes()
Returns the indexes pointing to elements of the root "array" path. You may use the method "retrieveFrom( toPath( aIndex) )" to address the sub-maps at the given index. Given the following paths:/0/0aaa /0/0bbb /0/0bbb /1/1aaa /1/1bbb /1/1bbb
The root path points to an index path with the two indexes "0" and "1".- Returns:
- The indexes which can be used
-
getIndexes
default int[] getIndexes(java.lang.String aPath)
Returns the indexes pointing to elements of the given "array" path. You may use the method "retrieveFrom( toPath( aPath, aIndex) )" to address the sub-maps at the given index. Given the following paths:/root/child/0/0aaa /root/child/0/0bbb /root/child/0/0bbb /root/child/1/1aaa /root/child/1/1bbb /root/child/1/1bbb
The path "/root/child" points to an index path with the two indexes "0" and "1".- Parameters:
aPath
- The path for which to get the indexes.- Returns:
- The indexes which can be used
-
getIndexed
default PathMap<T> getIndexed(int aIndex)
Returns the accordingly indexed Elements of the root "array" path. Given the following paths and index = 1:/0/0aaa /0/0bbb /0/0bbb /1/1aaa /1/1bbb /1/1bbb
You will get a result containing all the elements which's keys begin with "/1/".- Parameters:
aIndex
- The index which to use.- Returns:
- The indexed elements without the index in the paths.
-
getIndexed
default PathMap<T> getIndexed(java.lang.String aPath, int aIndex)
Returns the accordingly indexed Elements of the root "array" path. Given the following paths and index = 1 with a queried path "/root/child":/root/child/0/0aaa /root/child/0/0bbb /root/child/0/0bbb /root/child/1/1aaa /root/child/1/1bbb /root/child/1/1bbb
You will get a result containing all the elements which's keys begin with "/root/child/1/".- Parameters:
aIndex
- The index which to use.aPath
- The path from which to get the indexed elements.- Returns:
- The indexed elements without the index in the paths.
-
hasIndexed
default boolean hasIndexed(int aIndex)
Determines whether the index points to an index root "array" path. Given the following paths:/0/0aaa /0/0bbb /0/0bbb /1/1aaa /1/1bbb /1/1bbb
For indexes 0 and 1 you will get true, for all others you will get false.- Parameters:
aIndex
- The index which to use.- Returns:
- True if the index points to an index root "array" path.
-
hasIndexed
default boolean hasIndexed(java.lang.String aPath, int aIndex)
Determines whether the index points to an index root "array" path. Given the following paths:/root/child/0/0aaa /root/child/0/0bbb /root/child/0/0bbb /root/child/1/1aaa /root/child/1/1bbb /root/child/1/1bbb
For path "/root/child" and indexes 0 and 1 you will get true, for all others you will get false.- Parameters:
aIndex
- The index which to use.aPath
- The path for which to test.- Returns:
- True if the index points to an index root "array" path.
-
isArray
default boolean isArray()
Applies theisArray(String)
method for the root path "/".- Returns:
- As of
isArray(String)
applied to the root path. - See Also:
isArray(String)
-
isArray
default boolean isArray(java.lang.String aPath)
Determines as ofgetArray(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()
Applies thegetArray(String)
method for the root path "/".- Returns:
- As of
getArray(String)
applied to the root path. - See Also:
getArray(String)
-
getArray
default T[] getArray(java.lang.String aPath)
Returns the records below the given path in an array. Records in aPathMap
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"
getArray(String)
for the path "/animals/dogs" would contain {"ace", "bandit", "radar", "echo", "snoopy"}. CallingisArray("/animals/dogs")
would returntrue
whereas callingisArray("/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 asKeys.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 asKeys.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 askeySet(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 ofentries(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 thePathMap
and we callrecords()
, then the resultingSet
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 ourPathMap
:- "/animals/dogs/dilbert"
- "/animals/dogs/otto"
- "/animals/loki"
- "/machines/robots/greg"
directories(String)
with "/animals", then the resultingSet
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 ofdirectories(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()
Applies thedirectories(String)
method for the root path "/".- Returns:
- As of
directories(String)
applied to the root path. - See Also:
directories(String)
-
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 ourPathMap
:- "/animals/dogs/dilbert"
- "/animals/dogs/otto"
- "/animals/loki"
- "/machines/robots/greg"
directories(String)
with "/animals", then the resultingSet
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 ofrecords(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()
Applies therecords(String)
method for the root path "/".- Returns:
- As of
records(String)
applied to the root path. - See Also:
records(String)
-
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 ourPathMap
:- "/animals/dogs/dilbert"
- "/animals/dogs/otto"
- "/animals/loki"
- "/machines/robots/greg"
records(String)
with "/animals", then the resultingSet
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 newPathMap
from the elements of thisPathMap
found below the "from-path". The sub-paths will be the root paths for the newPathMap
. Given we have a value for path "/dog/cat" in thePathMap
and we callretrieveFrom(String)
with "/dog", then the resultingPathMap
will contain the path "/cat" for that value.
-
retrieveTo
PathMap<T> retrieveTo(java.lang.String aToPath)
Extracts a newPathMap
from thisPathMap
's elements with the paths relocated to the provided "to-path". Given we have a value for path "/dog/cat" in thePathMap
and we callretrieveTo(String)
with "/animals", then the resultingPathMap
will contain the path "/animals/dog/cat" for that value.
-
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 newPathMap
from the elements of thisPathMap
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 thetoMap(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 nestedMap
structure from thePathMap
'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 aMap
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 returnedMap
- Returns:
- The nested Map representing this
PathMap
starting from the given path. - Throws:
java.lang.IllegalStateException
- in case thePathMap
contains a path which points to a value and which is also part of other paths. Such a state cannot be represented by a nestedMap
structure as the element would represent a leaf and a node at the same time.
-
toDataStructure
default java.lang.Object toDataStructure()
Applies thetoDataStructure(String)
method for the root path "/".- Returns:
- As of
toDataStructure(String)
applied to the root path. - See Also:
toDataStructure(String)
-
toDataStructure
java.lang.Object toDataStructure(java.lang.String aFromPath)
Similar to thetoMap(String)
method, though in case all the keys of a nestedMap
instance (applicable to the rootMap
as well) represent an array (as ofgetArray( String)
), then an array is generated where the index of each value in theMap
is represented by the number representation of theMap
's key for that value. The result is a data structure consisting ofMap
instances and arrays.- Parameters:
aFromPath
- The path below which thePathMap
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 ofDelimiterAccessor.getDelimiter()
) and for it not to end with a delimiter. This implementation will return in emptyString
in case the path is an emptyString
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 emptyString
- 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 fromDelimiterAccessor.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 defaultDelimiterAccessor.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 delimiterDelimiterAccessor.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 delimiterDelimiterAccessor.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 thisPathMap
. By default the Root-Path consists just of the one delimiterDelimiterAccessor.getDelimiter()
character.- Returns:
- The path pointing to the root of this
PathMap
.
-
toPath
default java.lang.String toPath(java.lang.Object... aPathElements)
Creates a normalized path from the provided path elements by first converting them to aString
(if not being aString
already) and then concatenating the elements with the path delimiterDelimiterAccessor.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.
-
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 delimiterDelimiterAccessor.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 usinghasParentPath(String)
.
-
-