1 package org.djutils.eval;
2
3 import org.djutils.metadata.MetaData;
4
5 /**
6 * F2.java. Minimal implementation of two-argument Function with description.
7 * <p>
8 * Copyright (c) 2023-2025 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
9 * for project information <a href="https://djutils.org" target="_blank"> https://djutils.org</a>. The DJUTILS project is
10 * distributed under a three-clause BSD-style license, which can be found at
11 * <a href="https://djutils.org/docs/license.html" target="_blank"> https://djutils.org/docs/license.html</a>.
12 * </p>
13 * @author <a href="https://www.tudelft.nl/pknoppers">Peter Knoppers</a>
14 */
15 class F2 implements Function
16 {
17 /** Id of the function. */
18 final String id;
19
20 /** Type of the parameters of this function (also contains name and description). */
21 final MetaData metaData;
22
23 /** The zero argument function. */
24 final TwoArgumentFunction f2;
25
26 /**
27 * Construct a new two-argument function.
28 * @param id name of the function as it must be written in expressions
29 * @param metaData meta data of the function
30 * @param f2 two argument function
31 */
32 F2(final String id, final MetaData metaData, final TwoArgumentFunction f2)
33 {
34 this.id = id;
35 this.metaData = metaData;
36 this.f2 = f2;
37 }
38
39 @Override
40 public String getId()
41 {
42 return this.id;
43 }
44
45 @Override
46 public MetaData getMetaData()
47 {
48 return this.metaData;
49 }
50
51 @Override
52 public Object function(final Object[] arguments) throws RuntimeException
53 {
54 return this.f2.execute(this, arguments[0], arguments[1]);
55 }
56
57 /**
58 * Interface for two-argument functions.
59 */
60 interface TwoArgumentFunction
61 {
62 /**
63 * Prototype of the two-argument function
64 * @param functionData meta data of the function
65 * @param argument1 the first argument of the function
66 * @param argument2 the second argument of the function
67 * @return the result type of the function
68 */
69 Object execute(Function functionData, Object argument1, Object argument2);
70
71 }
72 }