Class PathTreeWalker
java.lang.Object
org.klojang.path.PathTreeWalker
The PathTreeWalker
is functionally equivalent to the PathWalker
class. However, a
PathTreeWalker
will turn the paths specified through the constructors into a tree of path segments.
This enables a PathTreeWalker
to make a minimal amount of "movements" through the object from which
it retrieves the values. For example, say you have specified the following paths:
Aperson.address.street person.address.zipCode parson.address.city
PathWalker
would perform 9 read operations as it retrieves the values for street
,
zipCode
, and city
. The PathTreeWalker
on the other hand performs only 5 read
operations, because it retrieves the values for person
and address
just once. Thus the
PathTreeWalker
is likely to be more performant when reading a relatively large number of paths
that, together, constitute a somewhat flat hierarchy.- Author:
- Ayco Holleman
-
Constructor Summary
ConstructorsConstructorDescriptionPathTreeWalker
(String... paths) Creates aPathWalker
for the specified paths.PathTreeWalker
(List<Path> paths) Creates aPathWalker
for the specified paths.PathTreeWalker
(List<Path> paths, boolean suppressExceptions) Creates aPathWalker
for the specified paths.PathTreeWalker
(List<Path> paths, boolean suppressExceptions, PathSegmentDeserializer segmentDeserializer) Creates aPathWalker
for the specified paths.PathTreeWalker
(Path... paths) Creates aPathWalker
for the specified paths. -
Method Summary
Modifier and TypeMethodDescriptionReturns the values of the paths specified through the constructor.readIntoList
(Object host) Returns the values of the paths specified through the constructor.readIntoMap
(Object host) Returns the values of the paths specified through the constructor.
-
Constructor Details
-
PathTreeWalker
Creates aPathWalker
for the specified paths.- Parameters:
paths
- the paths to read or write
-
PathTreeWalker
Creates aPathWalker
for the specified paths.- Parameters:
paths
- the paths to read or write
-
PathTreeWalker
-
PathTreeWalker
-
PathTreeWalker
public PathTreeWalker(List<Path> paths, boolean suppressExceptions, PathSegmentDeserializer segmentDeserializer) Creates aPathWalker
for the specified paths.- Parameters:
paths
- the paths to read or writesuppressExceptions
- whether to enable exception suppressionsegmentDeserializer
- a function that deserializes path segments into non-String map keys
-
-
Method Details
-
readAll
Returns the values of the paths specified through the constructor. The returned map maps the paths to their values.- Parameters:
host
- the object to read the values from- Returns:
- the values of all paths specified through the constructor
- Throws:
DeadEndException
- if exception suppression is disabled and thePathWalker
fails to retrieve the values of one or more paths.
-
readIntoMap
Returns the values of the paths specified through the constructor. The returned map maps the path strings to their values.- Parameters:
host
- the object to read the values from- Returns:
- the values of all paths specified through the constructor
- Throws:
DeadEndException
- if exception suppression is disabled and thePathWalker
fails to retrieve the values of one or more paths.
-
readIntoList
Returns the values of the paths specified through the constructor. The values are returned in the same order as the paths.- Parameters:
host
- the object to read the values from- Returns:
- the values of the paths specified through the constructor
- Throws:
DeadEndException
- if exception suppression is disabled and thePathWalker
fails to retrieve the values of one or more paths.
-