mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-22 07:20:09 -08:00
Add a Function abstract class and a Function database.
This commit is contained in:
parent
7fdae4285b
commit
8ed2c77fec
16
src/org/nwapw/abacus/number/Function.java
Normal file
16
src/org/nwapw/abacus/number/Function.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
21
src/org/nwapw/abacus/number/FunctionDatabase.java
Normal file
21
src/org/nwapw/abacus/number/FunctionDatabase.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user