mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-23 16:00:09 -08:00
Move the standard functions into a standard plugin.
This commit is contained in:
parent
b3c795e42f
commit
0b5c72d274
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(){
|
@Override
|
||||||
functions.put("+", new Function() {
|
public void load() {
|
||||||
|
registerFunction("+", new Function() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
protected boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length >= 1;
|
return params.length >= 1;
|
||||||
|
@ -23,7 +28,7 @@ public class FunctionDatabase {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
functions.put("-", new Function() {
|
registerFunction("-", new Function() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
protected boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 2;
|
return params.length == 2;
|
||||||
|
@ -35,7 +40,7 @@ public class FunctionDatabase {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
functions.put("*", new Function() {
|
registerFunction("*", new Function() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
protected boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length >= 1;
|
return params.length >= 1;
|
||||||
|
@ -51,7 +56,7 @@ public class FunctionDatabase {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
functions.put("/", new Function() {
|
registerFunction("/", new Function() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
protected boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 2;
|
return params.length == 2;
|
||||||
|
@ -63,7 +68,7 @@ public class FunctionDatabase {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
functions.put("!", new Function() {
|
registerFunction("!", new Function() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
protected boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 1;
|
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