Class Matcher

  • All Implemented Interfaces:
    com.google.common.base.Predicate<Leaf>, Predicate<Leaf>

    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 Detail

      • all

        public static Matcher all()
        Return a matcher that will match all paths. Equivalent to Matchers.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 like items/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:
        true if 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 of my/property will not match the leaf value my.
        See Also:
        matchesParent(Leaf)
      • matchesParent

        public abstract boolean matchesParent​(Leaf node)
        Returns whether any of the leafs that this instance matches start with the given node. For example, given the pattern my/property this method will return true for both my and my/property. This method is also aware of wildcards in the pattern such that a pattern of my/*&#47;property will match any node beginning with my
      • 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 like foaf:name/foaf:familyName to 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, use matches(Leaf) instead.
        Specified by:
        apply in interface com.google.common.base.Predicate<Leaf>
      • patternString

        protected abstract String patternString()
        Get the pattern this Matcher represents. Used for toString().
      • equals

        public boolean equals​(@Nullable
                              Object obj)
        Specified by:
        equals in interface com.google.common.base.Predicate<Leaf>
        Overrides:
        equals in class Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • getAstNode

        protected AstNode getAstNode()
        Get the ast node this matcher represents.