Class PathTreeWalker
java.lang.Object
org.klojang.path.PathTreeWalker
The PathTreeWalker is functionally the same as the PathWalker class. However, it will
turn the paths you specify through one of the constructors into a tree of path segments. This guarantees
that the PathTreeWalker makes a minimal amount of "movements" through the object from which to
retrieve 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 aPathWalkerfor the specified paths.PathTreeWalker(List<Path> paths) Creates aPathWalkerfor the specified paths.PathTreeWalker(List<Path> paths, boolean suppressExceptions) Creates aPathWalkerfor the specified paths.PathTreeWalker(List<Path> paths, boolean suppressExceptions, PathSegmentDeserializer segmentDeserializer) Creates aPathWalkerfor the specified paths.PathTreeWalker(Path... paths) Creates aPathWalkerfor the specified paths. -
Method Summary
-
Constructor Details
-
PathTreeWalker
Creates aPathWalkerfor the specified paths.- Parameters:
paths- One or more paths representing possibly deeply-nested properties
-
PathTreeWalker
Creates aPathWalkerfor the specified paths.- Parameters:
paths- The paths to walk through the provided host objects
-
PathTreeWalker
-
PathTreeWalker
Creates aPathWalkerfor the specified paths.- Parameters:
paths- The action to take if a path could not be read or writtensuppressExceptions- Iftrue, thereadmethods will returnnullfor paths that could not be read. Thewritemethods will quietly return without having written the value. Iffalse, aDeadEndExceptionwill be thrown detailing the error.
-
PathTreeWalker
public PathTreeWalker(List<Path> paths, boolean suppressExceptions, PathSegmentDeserializer segmentDeserializer) Creates aPathWalkerfor the specified paths.- Parameters:
paths- The paths to walksuppressExceptions- Iftrue, thereadmethods will returnnullfor paths that could not be read. Thewritemethods will quietly return without having written the value. Iffalse, aDeadEndExceptionwill be thrown detailing the error.segmentDeserializer- A function that converts path segments to map keys. You need to provide this when reading from, or writing toMapobjects with a non-String key type.
-
-
Method Details
-
read
Returns the values of all paths specified through the constructor.- Parameters:
host- the object to read the values from- Returns:
- the values of all paths specified through the constructor
- Throws:
DeadEndException- IfsuppressExceptionsis false and thePathWalkerfails to retrieve the values of one or more paths.
-