Add tree value functions to plugins.

This commit is contained in:
Danila Fedorin 2017-08-25 00:59:39 -07:00
parent 00462281fe
commit 40c80db914
2 changed files with 59 additions and 8 deletions

View File

@ -1,9 +1,6 @@
package org.nwapw.abacus.plugin;
import org.nwapw.abacus.function.Documentation;
import org.nwapw.abacus.function.DocumentationType;
import org.nwapw.abacus.function.Function;
import org.nwapw.abacus.function.Operator;
import org.nwapw.abacus.function.*;
import org.nwapw.abacus.number.NumberInterface;
/**
@ -69,6 +66,17 @@ public abstract class Plugin {
manager.registerFunction(name, toRegister);
}
/**
* To be used in load(). Registers a tree value function abstract class
* with the plugin internally, which makes it accessible to the plugin manager.
*
* @param name the name to register by.
* @param toRegister the tree value function implementation.
*/
protected final void registerTreeValueFunction(String name, TreeValueFunction toRegister) {
manager.registerTreeValueFunction(name, toRegister);
}
/**
* To be used in load(). Registers an operator abstract class
* with the plugin internally, which makes it accessible to
@ -114,6 +122,18 @@ public abstract class Plugin {
return manager.functionFor(name);
}
/**
* Searches the PluginManager for the given function name.
* This can be used by the plugins internally in order to call functions
* they do not provide.
*
* @param name the name for which to search.
* @return the resulting tree value function, or null if none was found for that name.
*/
protected final TreeValueFunction treeValueFunctionFor(String name){
return manager.treeValueFunctionFor(name);
}
/**
* Searches the PluginManager for the given operator name.
* This can be used by the plugins internally in order to call

View File

@ -1,10 +1,7 @@
package org.nwapw.abacus.plugin;
import org.nwapw.abacus.Abacus;
import org.nwapw.abacus.function.Documentation;
import org.nwapw.abacus.function.DocumentationType;
import org.nwapw.abacus.function.Function;
import org.nwapw.abacus.function.Operator;
import org.nwapw.abacus.function.*;
import org.nwapw.abacus.number.NumberInterface;
import java.lang.reflect.InvocationTargetException;
@ -31,6 +28,10 @@ public class PluginManager {
* The map of functions registered by the plugins.
*/
private Map<String, Function> registeredFunctions;
/**
* The map of tree value functions regstered by the plugins.
*/
private Map<String, TreeValueFunction> registeredTreeValueFunctions;
/**
* The map of operators registered by the plugins
*/
@ -72,6 +73,7 @@ public class PluginManager {
loadedPluginClasses = new HashSet<>();
plugins = new HashSet<>();
registeredFunctions = new HashMap<>();
registeredTreeValueFunctions = new HashMap<>();
registeredOperators = new HashMap<>();
registeredNumberImplementations = new HashMap<>();
registeredDocumentation = new HashSet<>();
@ -90,6 +92,16 @@ public class PluginManager {
registeredFunctions.put(name, function);
}
/**
* Registers a tree value function under the given name.
*
* @param name the name of the function.
* @param function the function to register.
*/
public void registerTreeValueFunction(String name, TreeValueFunction function) {
registeredTreeValueFunctions.put(name, function);
}
/**
* Registers an operator under the given name.
*
@ -130,6 +142,16 @@ public class PluginManager {
return registeredFunctions.get(name);
}
/**
* Gets the tree value function registered under the given name.
*
* @param name the name of the function.
* @return the function, or null if it was not found.
*/
public TreeValueFunction treeValueFunctionFor(String name){
return registeredTreeValueFunctions.get(name);
}
/**
* Gets the operator registered under the given name.
*
@ -302,6 +324,15 @@ public class PluginManager {
return registeredFunctions.keySet();
}
/**
* Gets all the tree vlaue functions loaded by the PluginManager.
*
* @return the set of all the tree value functions that were loaded.
*/
public Set<String> getAllTreeValueFunctions() {
return registeredTreeValueFunctions.keySet();
}
/**
* Gets all the operators loaded by the Plugin Manager.
*