Class PathTreeWalker

java.lang.Object
org.klojang.path.PathTreeWalker

public final class PathTreeWalker extends Object

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:


 person.address.street
 person.address.zipCode
 parson.address.city
 
A 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 Details

    • PathTreeWalker

      public PathTreeWalker(Path... paths)
      Creates a PathWalker for the specified paths.
      Parameters:
      paths - the paths to read or write
    • PathTreeWalker

      public PathTreeWalker(String... paths)
      Creates a PathWalker for the specified paths.
      Parameters:
      paths - the paths to read or write
    • PathTreeWalker

      public PathTreeWalker(List<Path> paths)
      Creates a PathWalker for the specified paths.
      Parameters:
      paths - the paths to read or write
    • PathTreeWalker

      public PathTreeWalker(List<Path> paths, boolean suppressExceptions)
      Creates a PathWalker for the specified paths.
      Parameters:
      paths - the paths to read or write
      suppressExceptions - whether to enable exception suppression
    • PathTreeWalker

      public PathTreeWalker(List<Path> paths, boolean suppressExceptions, PathSegmentDeserializer segmentDeserializer)
      Creates a PathWalker for the specified paths.
      Parameters:
      paths - the paths to read or write
      suppressExceptions - whether to enable exception suppression
      segmentDeserializer - a function that deserializes path segments into non-String map keys
  • Method Details

    • readAll

      public Map<Path, Result<Object>> readAll(Object host) throws DeadEndException
      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 the PathWalker fails to retrieve the values of one or more paths.
    • readIntoMap

      public Map<String, Result<Object>> readIntoMap(Object host) throws DeadEndException
      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 the PathWalker fails to retrieve the values of one or more paths.
    • readIntoList

      public List<Result<Object>> readIntoList(Object host) throws DeadEndException
      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 the PathWalker fails to retrieve the values of one or more paths.