From 73075c57b9cc922c156661fb63b0205c65ccf91d Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 25 Aug 2017 17:31:47 -0700 Subject: [PATCH] Add registering TreeValueOperators. --- .../java/org/nwapw/abacus/plugin/Plugin.java | 24 +++++++++++++ .../nwapw/abacus/plugin/PluginManager.java | 36 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/core/src/main/java/org/nwapw/abacus/plugin/Plugin.java b/core/src/main/java/org/nwapw/abacus/plugin/Plugin.java index 229df85..8f0441c 100644 --- a/core/src/main/java/org/nwapw/abacus/plugin/Plugin.java +++ b/core/src/main/java/org/nwapw/abacus/plugin/Plugin.java @@ -89,6 +89,18 @@ public abstract class Plugin { manager.registerOperator(name, operator); } + /** + * To be used in load(). Registers an operator + * with the plugin internally, which makes it accessible + * to the plugin manager. + * + * @param name the name of the tree value operator. + * @param operator the tree value operator to register. + */ + protected final void registerTreeValueOperator(String name, TreeValueOperator operator){ + manager.registerTreeValueOperator(name, operator); + } + /** * To be used in load(). Registers a new number implementation with the plugin. * This makes it accessible to the plugin manager. @@ -146,6 +158,18 @@ public abstract class Plugin { return manager.operatorFor(name); } + /** + * Searches the PluginManager for the given tree value operator name. + * This can be used by the plugins internally in order to call + * operations they do not provide. + * + * @param name the name for which to search. + * @return the resulting tree value operator, or null if none was found for that name. + */ + protected final TreeValueOperator treeValueOperatorFor(String name) { + return manager.treeValueOperatorFor(name); + } + /** * Searches the PluginManager for the given number implementation * name. This can be used by the plugins internally in order to find diff --git a/core/src/main/java/org/nwapw/abacus/plugin/PluginManager.java b/core/src/main/java/org/nwapw/abacus/plugin/PluginManager.java index a6a2a1f..90439fa 100644 --- a/core/src/main/java/org/nwapw/abacus/plugin/PluginManager.java +++ b/core/src/main/java/org/nwapw/abacus/plugin/PluginManager.java @@ -36,6 +36,10 @@ public class PluginManager { * The map of operators registered by the plugins */ private Map registeredOperators; + /** + * The map of tree value operators registered by the plugins. + */ + private Map registeredTreeValueOperators; /** * The map of number implementations registered by the plugins. */ @@ -75,6 +79,7 @@ public class PluginManager { registeredFunctions = new HashMap<>(); registeredTreeValueFunctions = new HashMap<>(); registeredOperators = new HashMap<>(); + registeredTreeValueOperators = new HashMap<>(); registeredNumberImplementations = new HashMap<>(); registeredDocumentation = new HashSet<>(); cachedInterfaceImplementations = new HashMap<>(); @@ -112,6 +117,16 @@ public class PluginManager { registeredOperators.put(name, operator); } + /** + * Registers a tree value operator under the given name. + * + * @param name the name of the tree value operator. + * @param operator the tree value operator to register. + */ + public void registerTreeValueOperator(String name, TreeValueOperator operator){ + registeredTreeValueOperators.put(name, operator); + } + /** * Registers a number implementation under the given name. * @@ -162,6 +177,16 @@ public class PluginManager { return registeredOperators.get(name); } + /** + * Gets the tree value operator registered under the given name. + * + * @param name the name of the tree value operator. + * @return the operator, or null if it was not found. + */ + public TreeValueOperator treeValueOperatorFor(String name) { + return registeredTreeValueOperators.get(name); + } + /** * Gets the number implementation registered under the given name. * @@ -299,7 +324,9 @@ public class PluginManager { plugin.disable(); } registeredFunctions.clear(); + registeredTreeValueFunctions.clear(); registeredOperators.clear(); + registeredTreeValueOperators.clear(); registeredNumberImplementations.clear(); registeredDocumentation.clear(); cachedInterfaceImplementations.clear(); @@ -342,6 +369,15 @@ public class PluginManager { return registeredOperators.keySet(); } + /** + * Gets all the tree value operators loaded by the PluginManager. + * + * @return the set of all tree value operators that were loaded. + */ + public Set getAllTreeValueOperators(){ + return registeredTreeValueOperators.keySet(); + } + /** * Gets all the number implementations loaded by the Plugin Manager. *