Class PathMatcher

java.lang.Object
ghidra.trace.model.target.path.PathMatcher
All Implemented Interfaces:
PathFilter

public class PathMatcher extends Object implements PathFilter
  • Field Details

    • WILD_SINGLETON

      protected static final Set<String> WILD_SINGLETON
    • patterns

      protected final Set<PathPattern> patterns
  • Method Details

    • any

      public static PathMatcher any(Stream<PathPattern> patterns)
    • any

      public static PathMatcher any(Collection<PathFilter> filters)
    • any

      public static PathMatcher any(PathFilter... filters)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • or

      public PathFilter or(PathFilter that)
      Specified by:
      or in interface PathFilter
    • anyPattern

      protected boolean anyPattern(Predicate<PathPattern> pred)
      TODO: We could probably do a lot better, esp. for many patterns, by using a trie.
    • matches

      public boolean matches(KeyPath path)
      Description copied from interface: PathFilter
      Check if the entire path passes
      Specified by:
      matches in interface PathFilter
      Parameters:
      path - the path to check
      Returns:
      true if it matches, false otherwise
    • successorCouldMatch

      public boolean successorCouldMatch(KeyPath path, boolean strict)
      Description copied from interface: PathFilter
      Check if the given path could have a matching successor

      This essentially checks if the given path is a viable prefix to the matcher.

      Specified by:
      successorCouldMatch in interface PathFilter
      Parameters:
      path - the path (prefix) to check
      strict - true to exclude the case where PathFilter.matches(KeyPath) would return true
      Returns:
      true if a successor could match, false otherwise
    • ancestorMatches

      public boolean ancestorMatches(KeyPath path, boolean strict)
      Description copied from interface: PathFilter
      Check if the given path has an ancestor that matches
      Specified by:
      ancestorMatches in interface PathFilter
      Parameters:
      path - the path to check
      strict - true to exclude the case where PathFilter.matches(KeyPath) would return true
      Returns:
      true if an ancestor matches, false otherwise
    • ancestorCouldMatchRight

      public boolean ancestorCouldMatchRight(KeyPath path, boolean strict)
      Description copied from interface: PathFilter
      Check if the given path could have a matching ancestor, right to left

      This essentially checks if the given path is a viable postfix to the matcher.

      Specified by:
      ancestorCouldMatchRight in interface PathFilter
      Parameters:
      path - the path (postfix) to check
      strict - true to exclude the case where PathFilter.matches(KeyPath) would return true
      Returns:
      true if an ancestor could match, false otherwise
    • getSingletonPath

      public KeyPath getSingletonPath()
      Description copied from interface: PathFilter
      If this predicate is known to match only one path, i.e., no wildcards, get that path
      Specified by:
      getSingletonPath in interface PathFilter
      Returns:
      the singleton path, or null
    • getSingletonPattern

      public PathPattern getSingletonPattern()
      Description copied from interface: PathFilter
      If this predicate consists of a single pattern, get that pattern
      Specified by:
      getSingletonPattern in interface PathFilter
      Returns:
      the singleton pattern, or null
    • getPatterns

      public Set<PathPattern> getPatterns()
      Description copied from interface: PathFilter
      Get the patterns of this predicate
      Specified by:
      getPatterns in interface PathFilter
      Returns:
      the patterns
    • coalesceWilds

      protected void coalesceWilds(Set<String> result)
    • getNextKeys

      public Set<String> getNextKeys(KeyPath path)
      Description copied from interface: PathFilter
      Get the patterns for the next possible key

      If a successor of the given path cannot match this pattern, the empty set is returned.

      Specified by:
      getNextKeys in interface PathFilter
      Parameters:
      path - the ancestor path
      Returns:
      a set of patterns where indices are enclosed in brackets []
    • getNextNames

      public Set<String> getNextNames(KeyPath path)
      Description copied from interface: PathFilter
      Get the patterns for the next possible name

      If a successor of the given path cannot match this pattern, the empty set is returned. If the pattern could accept a name next, get all patterns describing those names

      Specified by:
      getNextNames in interface PathFilter
      Parameters:
      path - the ancestor path
      Returns:
      a set of patterns
    • getNextIndices

      public Set<String> getNextIndices(KeyPath path)
      Description copied from interface: PathFilter
      Assuming a successor of path could match, get the patterns for the next possible index

      If a successor of the given path cannot match this pattern, the empty set is returned. If the pattern could accept an index next, get all patterns describing those indices

      Specified by:
      getNextIndices in interface PathFilter
      Parameters:
      path - the ancestor path
      Returns:
      a set of patterns, without brackets []
    • getPrevKeys

      public Set<String> getPrevKeys(KeyPath path)
      Description copied from interface: PathFilter
      Get the patterns for the previous possible key (right-to-left matching)

      If an ancestor of the given path cannot match this pattern, the empty set is returned.

      Specified by:
      getPrevKeys in interface PathFilter
      Parameters:
      path - the successor path
      Returns:
      a set of patterns where indices are enclosed in brackets []
    • isNone

      public boolean isNone()
      Description copied from interface: PathFilter
      Test if any patterns are contained here

      Note that the presence of a pattern does not guarantee the presence of a matching object. However, the absence of any pattern does guarantee no object can match.

      Specified by:
      isNone in interface PathFilter
      Returns:
      true if equivalent to PathFilter.NONE
    • applyKeys

      public PathMatcher applyKeys(PathFilter.Align align, List<String> indices)
      Description copied from interface: PathFilter
      Substitute wildcards from left to right for the given list of keys

      Takes each pattern and substitutes its wildcards for the given indices, according to the given alignment. This object is unmodified, and the result is returned.

      If there are fewer wildcards in a pattern than given, only the first keys are taken. If there are fewer keys than wildcards in a pattern, then the remaining wildcards are left in the resulting pattern. In this manner, the left-most wildcards are substituted for the left-most indices, or the right-most wildcards are substituted for the right-most indices, depending on the alignment.

      Specified by:
      applyKeys in interface PathFilter
      Parameters:
      align - the end to align
      indices - the keys to substitute
      Returns:
      the pattern or matcher with the applied substitutions
    • removeRight

      public PathMatcher removeRight(int count)
      Description copied from interface: PathFilter
      Remove count elements from the right
      Specified by:
      removeRight in interface PathFilter
      Parameters:
      count - the number of elements to remove
      Returns:
      the resulting filter