1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.core.metapath.cst.path;
7   
8   import java.util.function.Predicate;
9   
10  import dev.metaschema.core.metapath.item.node.IDefinitionNodeItem;
11  import edu.umd.cs.findbugs.annotations.NonNull;
12  
13  /**
14   * A common interface for all wildcard matchers.
15   * <p>
16   * Based on the XPath 3.1
17   * <a href="https://www.w3.org/TR/xpath-31/#node-tests">wildcard node test</a>
18   * syntax.
19   */
20  @FunctionalInterface
21  public interface IWildcardMatcher extends Predicate<IDefinitionNodeItem<?, ?>> {
22    /**
23     * Construct a wildcard matcher that matches the provided local name in any
24     * namespace.
25     *
26     * @param localName
27     *          the name used to match nodes
28     * @return the matcher
29     */
30    @NonNull
31    static IWildcardMatcher anyNamespace(@NonNull String localName) {
32      // the grammar should ensure that localName is not empty
33      assert !localName.isEmpty();
34      return new MatchAnyNamespace(localName);
35    }
36  
37    /**
38     * Construct a wildcard matcher that matches any local name in the provided
39     * namespace.
40     *
41     * @param namespace
42     *          the namespace used to match nodes
43     * @return the matcher
44     */
45    @NonNull
46    static IWildcardMatcher anyLocalName(@NonNull String namespace) {
47      return new MatchAnyLocalName(namespace);
48    }
49  
50    @Override
51    @NonNull
52    String toString();
53  }