View Javadoc
1   package org.djutils.eval;
2   
3   import org.djutils.base.Identifiable;
4   import org.djutils.metadata.MetaData;
5   
6   /**
7    * Function.java. Description and implementation of a function that can be registered in and then executed by the Eval evaluator.
8    * <p>
9    * Copyright (c) 2023-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
10   * for project information <a href="https://djutils.org" target="_blank"> https://djutils.org</a>. The DJUTILS project is
11   * distributed under a three-clause BSD-style license, which can be found at
12   * <a href="https://djutils.org/docs/license.html" target="_blank"> https://djutils.org/docs/license.html</a>.
13   * </p>
14   * @author <a href="https://www.tudelft.nl/pknoppers">Peter Knoppers</a>
15   */
16  public interface Function extends Identifiable
17  {   
18      /**
19       * Return the name of the function.
20       * @return String; the name of the function 
21       */
22      default String getName()
23      {
24          return getMetaData().getName();
25      }
26      /**
27       * Return a textual description of the function.
28       * @return String; description of the function (may use html tags).
29       */
30      default String getDescription()
31      {
32          return getMetaData().getDescription();
33      }
34      
35      /**
36       * Specifies the types of the arguments expected by the function.
37       * @return MetaData; specification of the arguments expected by the function
38       */
39      MetaData getMetaData();
40      
41      /**
42       * The function itself.
43       * @param arguments Object[]; the arguments of the function
44       * @return Object; the result of the function (must currently be either some type of DoubleScalar or Boolean).
45       * @throws RuntimeException thrown when the function is unable to produce a result
46       */
47      Object function(Object[] arguments) throws RuntimeException;
48      
49  }