From 989ac80bf44c0312a100a735339ba962f1af74b8 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 25 Jul 2017 21:50:41 -0700 Subject: [PATCH] Move the standard functions into a standard plugin. --- .../StandardPlugin.java} | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) rename src/org/nwapw/abacus/{number/FunctionDatabase.java => plugin/StandardPlugin.java} (80%) mode change 100755 => 100644 diff --git a/src/org/nwapw/abacus/number/FunctionDatabase.java b/src/org/nwapw/abacus/plugin/StandardPlugin.java old mode 100755 new mode 100644 similarity index 80% rename from src/org/nwapw/abacus/number/FunctionDatabase.java rename to src/org/nwapw/abacus/plugin/StandardPlugin.java index 4ec221d..c52b4ff --- a/src/org/nwapw/abacus/number/FunctionDatabase.java +++ b/src/org/nwapw/abacus/plugin/StandardPlugin.java @@ -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 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); - } - }