Add a Function abstract class and a Function database.

This commit is contained in:
Danila Fedorin 2017-07-24 13:44:38 -07:00
parent 7fdae4285b
commit 8ed2c77fec
2 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,16 @@
package org.nwapw.abacus.number;
public abstract class Function {
public int arity;
protected abstract Number applyInternal(Number...params);
public Number apply(Number...params) throws IllegalArgumentException {
if(params.length != arity)
throw new IllegalArgumentException("Invalid number of arguments: Function takes "
+ arity + ", " + params.length + " provided.");
return applyInternal(params);
}
}

View File

@ -0,0 +1,21 @@
package org.nwapw.abacus.number;
import java.util.HashMap;
public class FunctionDatabase {
private HashMap<String, Function> functions;
private void registerDefault(){
}
public FunctionDatabase(){
functions = new HashMap<>();
}
public Function getFunction(String name){
return functions.get(name);
}
}