1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.core.metapath.function;
7   
8   import java.util.stream.Stream;
9   
10  import dev.metaschema.core.qname.IEnhancedQName;
11  import edu.umd.cs.findbugs.annotations.NonNull;
12  
13  /**
14   * Provides access to a collection of Metapath function signatures.
15   */
16  public interface IFunctionLibrary {
17  
18    /**
19     * Retrieve the collection of function signatures in this library as a stream.
20     *
21     * @return a stream of function signatures
22     */
23    @NonNull
24    Stream<IFunction> stream();
25  
26    /**
27     * Determine if there is a function with the provided namespace qualified name
28     * that supports the signature of the provided {@code arity}.
29     *
30     * @param name
31     *          the namespace qualified name of a group of functions
32     * @param arity
33     *          the count of arguments for use in determining an argument signature
34     *          match
35     * @return {@code true} if a function signature matches or {@code false}
36     *         otherwise
37     */
38    default boolean hasFunction(@NonNull IEnhancedQName name, int arity) {
39      return getFunction(name, arity) != null;
40    }
41  
42    /**
43     * Retrieve the function with the provided namespace qualified name that
44     * supports the signature of the provided {@code arity}, if such a function
45     * exists.
46     *
47     * @param name
48     *          the namespace qualified name of a group of functions
49     * @param arity
50     *          the count of arguments for use in determining an argument signature
51     *          match
52     * @return the matching function or {@code null} if no match exists
53     */
54    IFunction getFunction(@NonNull IEnhancedQName name, int arity);
55  }