Package com.pressassociation.pr.match
Class Matcher
- java.lang.Object
-
- com.pressassociation.pr.match.Matcher
-
public abstract class Matcher extends Object implements com.google.common.base.Predicate<Leaf>
Matches leaf nodes against a pattern. This class represents the core abstraction of partial responses. A Matcher is built around a pattern, once built you can query whether certain leaf nodes (or paths) are included in the pattern.- Author:
- Matt Nathan
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Matcherall()Return a matcher that will match all paths.booleanapply(Leaf input)Deprecated.This method exists solely to satisfy the Predicate contract, usematches(Leaf)instead.booleanequals(Object obj)protected AstNodegetAstNode()Get the ast node this matcher represents.inthashCode()abstract booleanmatches(Leaf leaf)Return whether this matcher pattern exactly matches the given leaf.booleanmatches(CharSequence path)Return whether this matcher pattern applies to the given path.booleanmatchesAll()Return whether this matcher should match all paths.abstract booleanmatchesParent(Leaf node)Returns whether any of the leafs that this instancematchesstart with the given node.booleanmatchesParent(CharSequence path)Returns whether any of the leafs that this instancematchesstart with the given node.static Matcherof(CharSequence fields)Get a new Matcher that will match against the given fields string.protected abstract StringpatternString()Get the pattern this Matcher represents.StringtoString()Matchertransform(com.google.common.base.Function<? super String,String> nameTransformer)Transform the words in the given matcher according to the nameTransformer given.
-
-
-
Method Detail
-
all
public static Matcher all()
Return a matcher that will match all paths. Equivalent toMatchers.of("*").- Returns:
- The matcher.
-
of
public static Matcher of(CharSequence fields)
Get a new Matcher that will match against the given fields string. The string should be a valid fields string, something likeitems/name(type,value).- Parameters:
fields- The fields string- Returns:
- The matcher.
-
matchesAll
public boolean matchesAll()
Return whether this matcher should match all paths. This can be used to optimise certain code paths that would do extra work to support matchers when it would not be needed.- Returns:
trueif the matcher should match all paths.
-
matches
public abstract boolean matches(Leaf leaf)
Return whether this matcher pattern exactly matches the given leaf. This will not return true if the leaf represents a node that not explicitly matched. For example a pattern ofmy/propertywill not match the leaf valuemy.- See Also:
matchesParent(Leaf)
-
matches
public boolean matches(CharSequence path)
Return whether this matcher pattern applies to the given path. The path will be split according toLeaf.fromPath(CharSequence).- See Also:
matches(Leaf)
-
matchesParent
public abstract boolean matchesParent(Leaf node)
Returns whether any of the leafs that this instancematchesstart with the given node. For example, given the patternmy/propertythis method will return true for bothmyandmy/property. This method is also aware of wildcards in the pattern such that a pattern ofmy/*/propertywill match any node beginning withmy
-
matchesParent
public boolean matchesParent(CharSequence path)
Returns whether any of the leafs that this instancematchesstart with the given node. The path will be split according toLeaf.fromPath(CharSequence).- See Also:
matchesParent(Leaf)
-
transform
public Matcher transform(com.google.common.base.Function<? super String,String> nameTransformer)
Transform the words in the given matcher according to the nameTransformer given. This can be used to fulfil certain use-cases, for example to expand namespaces in patterns likefoaf:name/foaf:familyNameto their fully-qualified forms.- Parameters:
nameTransformer- The function used to transform the matchers words- Returns:
- The new matcher
-
apply
@Deprecated public boolean apply(@Nullable Leaf input)
Deprecated.This method exists solely to satisfy the Predicate contract, usematches(Leaf)instead.- Specified by:
applyin interfacecom.google.common.base.Predicate<Leaf>
-
patternString
protected abstract String patternString()
Get the pattern this Matcher represents. Used for toString().
-
getAstNode
protected AstNode getAstNode()
Get the ast node this matcher represents.
-
-