/
Function.java
58 lines (52 loc) · 2.13 KB
/
Function.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package net.aufdemrand.denizen.utilities.javaluator;
/** A <a href="http://en.wikipedia.org/wiki/Function_(mathematics)">function</a>.
* @author Jean-Marc Astesana
* @see <a href="../../../license.html">License information</a>
*/
public class Function {
private String name;
private int minArgumentCount;
private int maxArgumentCount;
/** Constructor.
* <br>This constructor builds a function with a fixed arguments count.
* @param name The function's name
* @param argumentCount The function's argument count.
* @throw IllegalArgumentException if argumentCount is lower than 0 or if the function name is null or empty.
*/
public Function(String name, int argumentCount) {
this(name, argumentCount, argumentCount);
}
/** Constructor.
* <br>This constructor builds a function with a variable arguments count.
* <br>For instance, a minimum function may have at least one argument.
* @param name The function's name
* @param minArgumentCount The function's minimum argument count.
* @param maxArgumentCount The function's maximum argument count (Integer.MAX_VALUE to specify no upper limit).
* @throw IllegalArgumentException if minArgumentCount is less than 0 or greater than maxArgumentCount or if the function name is null or empty.
*/
public Function(String name, int minArgumentCount, int maxArgumentCount) {
if ((minArgumentCount<0) || (minArgumentCount>maxArgumentCount)) throw new IllegalArgumentException("Invalid argument count");
if (name==null || name.length()==0) throw new IllegalArgumentException("Invalid function name");
this.name = name;
this.minArgumentCount = minArgumentCount;
this.maxArgumentCount = maxArgumentCount;
}
/** Gets the function's name.
* @return the name of the function
*/
public String getName() {
return this.name;
}
/** Gets the function's minimum argument count.
* @return an integer
*/
public int getMinimumArgumentCount() {
return this.minArgumentCount;
}
/** Gets the function's maximum argument count.
* @return an integer
*/
public int getMaximumArgumentCount() {
return this.maxArgumentCount;
}
}