Package org.refcodes.structure
Class PathMapImpl<T>
- java.lang.Object
-
- org.refcodes.structure.PathMapImpl<T>
-
- Type Parameters:
T
- the generic type
- All Implemented Interfaces:
org.refcodes.mixin.DelimiterAccessor
,org.refcodes.mixin.Dumpable
,org.refcodes.mixin.TypeAccessor<T>
,Containable
,Dictionary<java.lang.String,T>
,Keys<java.lang.String,T>
,PathMap<T>
public class PathMapImpl<T> extends java.lang.Object implements PathMap<T>
The Class PathMapImpl.
-
-
Nested Class Summary
-
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>
-
Nested classes/interfaces inherited from interface org.refcodes.structure.PathMap
PathMap.MutablePathMap<T>, PathMap.PathMapBuilder<T>
-
-
Constructor Summary
Constructors Modifier Constructor Description PathMapImpl(char aDelimiter, java.lang.Class<T> aType)
Create aPathMap
instance using the provided path delimiter for the path declarations.PathMapImpl(java.lang.Object aObj, char aDelimiter, java.lang.Class<T> aType)
Creates aPathMap
instance containing the elements as ofPathMap.MutablePathMap.insert(Object)
.PathMapImpl(java.lang.Object aObj, java.lang.Class<T> aType)
Create aPathMap
instance containing the elements as ofPathMap.MutablePathMap.insert(Object)
using the default path delimiter "/" (Delimiter.PATH
) for the path declarations.PathMapImpl(java.lang.Object aObj, java.lang.String aFromPath, char aDelimiter, java.lang.Class<T> aType)
Creates aPathMap
instance containing the elements as ofPathMap.MutablePathMap.insert(Object)
.PathMapImpl(java.lang.Object aObj, java.lang.String aFromPath, java.lang.Class<T> aType)
Creates aPathMap
instance containing the elements as ofPathMap.MutablePathMap.insert(Object)
using the default path delimiter "/" (Delimiter.PATH
) for the path declarations.PathMapImpl(java.lang.String aToPath, java.lang.Object aObj, char aDelimiter, java.lang.Class<T> aType)
Creates aPathMap
instance containing the elements as ofPathMap.MutablePathMap.insert(Object)
.PathMapImpl(java.lang.String aToPath, java.lang.Object aObj, java.lang.Class<T> aType)
Create aPathMap
instance containing the elements as ofPathMap.MutablePathMap.insert(Object)
using the default path delimiter "/" (Delimiter.PATH
) for the path declarations.PathMapImpl(java.lang.String aToPath, java.lang.Object aObj, java.lang.String aFromPath, char aDelimiter, java.lang.Class<T> aType)
Create aPathMap
instance containing the elements as ofPathMap.MutablePathMap.insert(Object)
.PathMapImpl(java.lang.String aToPath, java.lang.Object aObj, java.lang.String aFromPath, java.lang.Class<T> aType)
Creates aPathMap
instance containing the elements as ofPathMap.MutablePathMap.insert(Object)
using the default path delimiter "/" (Delimiter.PATH
for the path declarations.protected
PathMapImpl(PathMap<T> aPathMap)
Create aPathMap
instance from the providedPathMap
instance containing the elements as ofPathMap.MutablePathMap.insert(Object)
using thePathMap
's path delimiter for the path declarations the the type of thePathMap
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete 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.static <T> void
childrenOf(PathMap<T> aFromPathMap, java.lang.String aParentPath, PathMap.PathMapBuilder<T> aToPathMap)
Hook method for implementing thePathMap.childrenOf(String)
method.boolean
containsKey(java.lang.Object aKey)
Tests whether there is an element with the given key.boolean
containsValue(java.lang.Object aValue)
This method is defined for the sake ofMap
conformity.T
get(java.lang.Object aKey)
Retrieves the element assigned to the given key.char
getDelimiter()
java.lang.Class<T>
getType()
boolean
isEmpty()
Tests whether the accumulation is empty or not.java.util.Set<java.lang.String>
keySet()
Retrieves a collection containing all the keys found in the elements of this collection.PathMap<T>
retrieveFrom(java.lang.String aFromPath)
static <T> void
retrieveFrom(PathMap<T> aFromPathMap, java.lang.String aFromPath, PathMap.PathMapBuilder<T> aToPathMap)
Hook method for implementing thePathMap.retrieveFrom(String)
method.PathMap<T>
retrieveTo(java.lang.String aToPath)
static <T> void
retrieveTo(PathMap<T> aFromPathMap, java.lang.String aToPath, PathMap.PathMapBuilder<T> aToPathMap)
Hook method for implementing thePathMap.retrieveTo(String)
method.int
size()
Returns the number of data elements contained in the collection.protected static java.lang.Object
toArray(java.util.Map<java.lang.String,?> aMap)
java.lang.Object
toDataStructure(java.lang.String aFromPath)
Similar to thePathMap.toMap(String)
method, though in case all the keys of a nestedMap
instance (applicable to the rootMap
as well) represent an array (as ofPathMap.getArray( 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.static java.lang.Object
toDataStructure(PathMap<?> aPathMap, java.lang.String aFromPath)
Hook method for implementing thePathMap.toDataStructure()
method.protected static java.util.Map<java.lang.String,?>
toMap(java.util.Map<java.lang.String,?> aMap)
protected static java.lang.Object
toValue(java.lang.Object aObj)
java.util.Collection<T>
values()
Returns aCollection
view of the values related to the contained keys.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.refcodes.structure.PathMap
directories, directories, entries, entries, fromExternalKey, get, get, getArray, getArray, getIndexed, getIndexed, getIndexes, getIndexes, getRootPath, hasIndexed, hasIndexed, hasParentPath, isArray, isArray, isDirectory, isEntry, isIndexed, isIndexed, isPath, isRecord, isRootPath, keySet, paths, paths, records, records, retrieve, toDataStructure, toExternalKey, toMap, toMap, toNormalizedPath, toNormalizedPath, toParentPath, toPath, toPath
-
-
-
-
Constructor Detail
-
PathMapImpl
protected PathMapImpl(PathMap<T> aPathMap)
Create aPathMap
instance from the providedPathMap
instance containing the elements as ofPathMap.MutablePathMap.insert(Object)
using thePathMap
's path delimiter for the path declarations the the type of thePathMap
.- Parameters:
aPathMap
- ThePathMap
from which the elements are to be added.
-
PathMapImpl
public PathMapImpl(char aDelimiter, java.lang.Class<T> aType)
Create aPathMap
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.
-
PathMapImpl
public PathMapImpl(java.lang.Object aObj, java.lang.Class<T> aType)
Create aPathMap
instance containing the elements as ofPathMap.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.
-
PathMapImpl
public PathMapImpl(java.lang.String aToPath, java.lang.Object aObj, java.lang.Class<T> aType)
Create aPathMap
instance containing the elements as ofPathMap.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.
-
PathMapImpl
public PathMapImpl(java.lang.Object aObj, java.lang.String aFromPath, java.lang.Class<T> aType)
Creates aPathMap
instance containing the elements as ofPathMap.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.
-
PathMapImpl
public PathMapImpl(java.lang.String aToPath, java.lang.Object aObj, java.lang.String aFromPath, java.lang.Class<T> aType)
Creates aPathMap
instance containing the elements as ofPathMap.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.
-
PathMapImpl
public PathMapImpl(java.lang.Object aObj, char aDelimiter, java.lang.Class<T> aType)
Creates aPathMap
instance containing the elements as ofPathMap.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.
-
PathMapImpl
public PathMapImpl(java.lang.String aToPath, java.lang.Object aObj, char aDelimiter, java.lang.Class<T> aType)
Creates aPathMap
instance containing the elements as ofPathMap.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.
-
PathMapImpl
public PathMapImpl(java.lang.Object aObj, java.lang.String aFromPath, char aDelimiter, java.lang.Class<T> aType)
Creates aPathMap
instance containing the elements as ofPathMap.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.
-
PathMapImpl
public PathMapImpl(java.lang.String aToPath, java.lang.Object aObj, java.lang.String aFromPath, char aDelimiter, java.lang.Class<T> aType)
Create aPathMap
instance containing the elements as ofPathMap.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 Detail
-
containsKey
public boolean containsKey(java.lang.Object aKey)
Tests whether there is an element with the given key.- Specified by:
containsKey
in interfaceKeys<java.lang.String,T>
- Parameters:
aKey
- The key for which to test whether there is an element.- Returns:
- True in case there is an element for the given key.
-
containsValue
public boolean containsValue(java.lang.Object aValue)
This method is defined for the sake ofMap
conformity. Tests whether the provided value has a key assigned.- Specified by:
containsValue
in interfaceKeys<java.lang.String,T>
- Parameters:
aValue
- The value to test if a key references this value.- Returns:
- True in case the given value is referenced by a key.
-
get
public T get(java.lang.Object aKey)
Retrieves the element assigned to the given key.
-
keySet
public java.util.Set<java.lang.String> keySet()
Retrieves a collection containing all the keys found in the elements of this collection.
-
values
public java.util.Collection<T> values()
Returns aCollection
view of the values related to the contained keys.
-
size
public int size()
Returns the number of data elements contained in the collection.- Specified by:
size
in interfaceContainable
- Returns:
- An integer representing the number of items stored in the accumulation.
-
isEmpty
public boolean isEmpty()
Tests whether the accumulation is empty or not. Returns true if the accumulation is empty, else false is returned.- Specified by:
isEmpty
in interfaceContainable
- Returns:
- True if no element is contained in the accumulation - else false is returned.
-
getDelimiter
public char getDelimiter()
- Specified by:
getDelimiter
in interfaceorg.refcodes.mixin.DelimiterAccessor
-
retrieveFrom
public 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 callPathMap.retrieveFrom(String)
with "/dog", then the resultingPathMap
will contain the path "/cat" for that value.- Specified by:
retrieveFrom
in interfacePathMap<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 newPathMap
.
-
retrieveTo
public 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 callPathMap.retrieveTo(String)
with "/animals", then the resultingPathMap
will contain the path "/animals/dog/cat" for that value.
-
childrenOf
public PathMap<T> childrenOf(java.lang.String aParentPath)
Gets the children elements of the provided parent's path, excluding the parent's path.- Specified by:
childrenOf
in interfacePathMap<T>
- Parameters:
aParentPath
- The path from where to retrieve the children.- Returns:
- The children of the given parent's path.
-
getType
public java.lang.Class<T> getType()
- Specified by:
getType
in interfaceorg.refcodes.mixin.TypeAccessor<T>
-
toDataStructure
public java.lang.Object toDataStructure(java.lang.String aFromPath)
Similar to thePathMap.toMap(String)
method, though in case all the keys of a nestedMap
instance (applicable to the rootMap
as well) represent an array (as ofPathMap.getArray( 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.- Specified by:
toDataStructure
in interfacePathMap<T>
- 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.
-
toDataStructure
public static java.lang.Object toDataStructure(PathMap<?> aPathMap, java.lang.String aFromPath)
Hook method for implementing thePathMap.toDataStructure()
method.
-
retrieveFrom
public static <T> void retrieveFrom(PathMap<T> aFromPathMap, java.lang.String aFromPath, PathMap.PathMapBuilder<T> aToPathMap)
Hook method for implementing thePathMap.retrieveFrom(String)
method.- Type Parameters:
T
- The type of thePathMap
the functionality is to be applied to.- Parameters:
aFromPathMap
- ThePathMap
from which to retrieve.aFromPath
- The path from where to start extracting the paths.aToPathMap
- ThePathMap.PathMapBuilder
which to put the result in.
-
retrieveTo
public static <T> void retrieveTo(PathMap<T> aFromPathMap, java.lang.String aToPath, PathMap.PathMapBuilder<T> aToPathMap)
Hook method for implementing thePathMap.retrieveTo(String)
method.- Type Parameters:
T
- The type of thePathMap
the functionality is to be applied to.- Parameters:
aFromPathMap
- ThePathMap
from which to retrieve.aToPath
- The path where to relocate the paths of thisPathMap
to.aToPathMap
- ThePathMap.PathMapBuilder
which to put the result in.
-
childrenOf
public static <T> void childrenOf(PathMap<T> aFromPathMap, java.lang.String aParentPath, PathMap.PathMapBuilder<T> aToPathMap)
Hook method for implementing thePathMap.childrenOf(String)
method.- Type Parameters:
T
- The type of thePathMap
the functionality is to be applied to.- Parameters:
aFromPathMap
- ThePathMap
from which to retrieve.aParentPath
- The path from where to retrieve the children.aToPathMap
- ThePathMap.PathMapBuilder
which to put the result in.
-
toArray
protected static java.lang.Object toArray(java.util.Map<java.lang.String,?> aMap)
-
toMap
protected static java.util.Map<java.lang.String,?> toMap(java.util.Map<java.lang.String,?> aMap)
-
toValue
protected static java.lang.Object toValue(java.lang.Object aObj)
-
-