mirror of
https://github.com/DanilaFe/abacus
synced 2024-11-04 18:08:31 -08:00
Move the standard functions into a standard plugin.
This commit is contained in:
parent
3cf4f958b0
commit
989ac80bf4
34
src/org/nwapw/abacus/number/FunctionDatabase.java → src/org/nwapw/abacus/plugin/StandardPlugin.java
Executable file → Normal file
34
src/org/nwapw/abacus/number/FunctionDatabase.java → src/org/nwapw/abacus/plugin/StandardPlugin.java
Executable file → Normal file
|
@ -1,13 +1,18 @@
|
|||
package org.nwapw.abacus.number;
|
||||
package org.nwapw.abacus.plugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import org.nwapw.abacus.number.Function;
|
||||
import org.nwapw.abacus.number.NaiveNumber;
|
||||
import org.nwapw.abacus.number.NumberInterface;
|
||||
|
||||
public class FunctionDatabase {
|
||||
public class StandardPlugin extends Plugin {
|
||||
|
||||
private HashMap<String, Function> functions;
|
||||
public StandardPlugin(PluginManager manager) {
|
||||
super(manager);
|
||||
}
|
||||
|
||||
private void registerDefault(){
|
||||
functions.put("+", new Function() {
|
||||
@Override
|
||||
public void load() {
|
||||
registerFunction("+", new Function() {
|
||||
@Override
|
||||
protected boolean matchesParams(NumberInterface[] params) {
|
||||
return params.length >= 1;
|
||||
|
@ -23,7 +28,7 @@ public class FunctionDatabase {
|
|||
}
|
||||
});
|
||||
|
||||
functions.put("-", new Function() {
|
||||
registerFunction("-", new Function() {
|
||||
@Override
|
||||
protected boolean matchesParams(NumberInterface[] params) {
|
||||
return params.length == 2;
|
||||
|
@ -35,7 +40,7 @@ public class FunctionDatabase {
|
|||
}
|
||||
});
|
||||
|
||||
functions.put("*", new Function() {
|
||||
registerFunction("*", new Function() {
|
||||
@Override
|
||||
protected boolean matchesParams(NumberInterface[] params) {
|
||||
return params.length >= 1;
|
||||
|
@ -51,7 +56,7 @@ public class FunctionDatabase {
|
|||
}
|
||||
});
|
||||
|
||||
functions.put("/", new Function() {
|
||||
registerFunction("/", new Function() {
|
||||
@Override
|
||||
protected boolean matchesParams(NumberInterface[] params) {
|
||||
return params.length == 2;
|
||||
|
@ -63,7 +68,7 @@ public class FunctionDatabase {
|
|||
}
|
||||
});
|
||||
|
||||
functions.put("!", new Function() {
|
||||
registerFunction("!", new Function() {
|
||||
@Override
|
||||
protected boolean matchesParams(NumberInterface[] params) {
|
||||
return params.length == 1;
|
||||
|
@ -82,13 +87,4 @@ public class FunctionDatabase {
|
|||
});
|
||||
}
|
||||
|
||||
public FunctionDatabase(){
|
||||
functions = new HashMap<>();
|
||||
registerDefault();
|
||||
}
|
||||
|
||||
public Function getFunction(String name){
|
||||
return functions.get(name);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user