From 542f062b5e5f30620c58fd529923eca1f1ad7772 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 3 Aug 2017 20:50:39 -0700 Subject: [PATCH] Remove old reference to the promotion system and the number class map. --- .../org/nwapw/abacus/function/Function.java | 13 --- .../java/org/nwapw/abacus/plugin/Plugin.java | 100 ------------------ .../nwapw/abacus/plugin/PluginManager.java | 63 ----------- .../nwapw/abacus/plugin/StandardPlugin.java | 5 - 4 files changed, 181 deletions(-) diff --git a/src/main/java/org/nwapw/abacus/function/Function.java b/src/main/java/org/nwapw/abacus/function/Function.java index 62a0e7d..bd5af72 100755 --- a/src/main/java/org/nwapw/abacus/function/Function.java +++ b/src/main/java/org/nwapw/abacus/function/Function.java @@ -1,10 +1,6 @@ package org.nwapw.abacus.function; -import org.nwapw.abacus.number.NaiveNumber; import org.nwapw.abacus.number.NumberInterface; -import org.nwapw.abacus.number.PreciseNumber; - -import java.util.HashMap; /** * A function that operates on one or more @@ -12,15 +8,6 @@ import java.util.HashMap; */ public abstract class Function { - /** - * A map to correctly promote different number implementations to each other. - */ - private static final HashMap, Integer> priorityMap = - new HashMap, Integer>() {{ - put(NaiveNumber.class, 0); - put(PreciseNumber.class, 1); - }}; - /** * Checks whether the given params will work for the given function. * diff --git a/src/main/java/org/nwapw/abacus/plugin/Plugin.java b/src/main/java/org/nwapw/abacus/plugin/Plugin.java index 96c6104..2757841 100644 --- a/src/main/java/org/nwapw/abacus/plugin/Plugin.java +++ b/src/main/java/org/nwapw/abacus/plugin/Plugin.java @@ -2,7 +2,6 @@ package org.nwapw.abacus.plugin; import org.nwapw.abacus.function.Function; import org.nwapw.abacus.function.Operator; -import org.nwapw.abacus.number.NumberInterface; import java.util.HashMap; import java.util.Map; @@ -25,14 +24,6 @@ public abstract class Plugin { * A hash map of operators mapped to their string names. */ private Map operators; - /** - * A hash map of operators mapped to their string names. - */ - private Map> numbers; - /** - * A hash map of constant providers for each number type. - */ - private Map, java.util.function.Function> constantProviders; /** * The plugin manager in which to search for functions * not inside this package, @@ -55,8 +46,6 @@ public abstract class Plugin { this.manager = manager; functions = new HashMap<>(); operators = new HashMap<>(); - numbers = new HashMap<>(); - constantProviders = new HashMap<>(); enabled = false; } @@ -78,23 +67,6 @@ public abstract class Plugin { return operators.keySet(); } - /** - * Gets the list of all numbers provided by this plugin. - * - * @return the list of registered numbers. - */ - public final Set providedNumbers() { - return numbers.keySet(); - } - - /** - * Gets the list of all constant providers provided by this plugin. - * @return the list of constant providers. - */ - public final Set> providedConstantProviders() { - return constantProviders.keySet(); - } - /** * Gets a function under the given function name. * @@ -115,26 +87,6 @@ public abstract class Plugin { return operators.get(operatorName); } - /** - * Gets the class under the given name. - * - * @param numberName the name of the class. - * @return the class, or null if the plugin doesn't provide it. - */ - public final Class getNumber(String numberName) { - return numbers.get(numberName); - } - - /** - * Gets the constant provider for the given class. - * - * @param pluginClass the class for which to provide constants. - * @return the provider, or null, if the plugin doesn't provide it. - */ - public final java.util.function.Function getConstantProvider(Class pluginClass){ - return constantProviders.get(pluginClass); - } - /** * Enables the function, loading the necessary instances * of functions. @@ -154,8 +106,6 @@ public abstract class Plugin { onDisable(); functions.clear(); operators.clear(); - numbers.clear(); - constantProviders.clear(); enabled = false; } @@ -182,32 +132,6 @@ public abstract class Plugin { operators.put(name, operator); } - /** - * To be used in load(). Registers a number class - * with the plugin internally, which makes it possible - * for the user to select it as an "implementation" for the - * number that they would like to use. - * - * @param name the name to register it under. - * @param toRegister the class to register. - */ - protected final void registerNumber(String name, Class toRegister) { - numbers.put(name, toRegister); - } - - /** - * To be used in load(). Registers a constant provider - * with the plugin internally, which makes it possible - * for the calculations to look up constants for each different - * number type. - * @param providerFor the class the provider works with. - * @param constantProvider the provider to register. - */ - protected final void registerConstantProvider(Class providerFor, - java.util.function.Function constantProvider) { - constantProviders.put(providerFor, constantProvider); - } - /** * Searches the PluginManager for the given function name. * This can be used by the plugins internally in order to call functions @@ -232,30 +156,6 @@ public abstract class Plugin { return manager.operatorFor(name); } - /** - * Searches the PluginManager for the given number implementation. - * This can be used by the plugins internally in order to - * find classes by name that they do not provide. - * - * @param name the name for which to search - * @return the resulting number class. - */ - protected final Class numberFor(String name) { - return manager.numberFor(name); - } - - /** - * Searches the PluginManager for the given constant provider. - * This can be used by the plugins internally in order - * to find constant providers for number provider they do not provide. - * - * @param forClass the class for which to get a generator for. - * @return the resulting generator - */ - protected final java.util.function.Function constantProviderFor(Class forClass){ - return manager.constantProviderFor(forClass); - } - /** * Abstract method to be overridden by plugin implementation, in which the plugins * are supposed to register the functions they provide and do any other diff --git a/src/main/java/org/nwapw/abacus/plugin/PluginManager.java b/src/main/java/org/nwapw/abacus/plugin/PluginManager.java index 213fc65..1f61a56 100644 --- a/src/main/java/org/nwapw/abacus/plugin/PluginManager.java +++ b/src/main/java/org/nwapw/abacus/plugin/PluginManager.java @@ -2,7 +2,6 @@ package org.nwapw.abacus.plugin; import org.nwapw.abacus.function.Function; import org.nwapw.abacus.function.Operator; -import org.nwapw.abacus.number.NumberInterface; import java.lang.reflect.InvocationTargetException; import java.util.*; @@ -31,16 +30,6 @@ public class PluginManager { * that is, found in a plugin and returned. */ private Map cachedOperators; - /** - * List of registered number implementations that have - * been cached, that is, found in a plugin and returned. - */ - private Map> cachedNumbers; - /** - * List of registered constant providers for every - * number class. - */ - private Map, java.util.function.Function> cachedConstantProviders; /** * List of all functions loaded by the plugins. */ @@ -49,14 +38,6 @@ public class PluginManager { * List of all operators loaded by the plugins. */ private Set allOperators; - /** - * List of all numbers loaded by the plugins. - */ - private Set allNumbers; - /** - * List of all the constant providers loaded by the plugins. - */ - private Set> allConstantProviders; /** * The list of plugin listeners attached to this instance. */ @@ -70,12 +51,8 @@ public class PluginManager { plugins = new HashSet<>(); cachedFunctions = new HashMap<>(); cachedOperators = new HashMap<>(); - cachedNumbers = new HashMap<>(); - cachedConstantProviders = new HashMap<>(); allFunctions = new HashSet<>(); allOperators = new HashSet<>(); - allNumbers = new HashSet<>(); - allConstantProviders = new HashSet<>(); listeners = new HashSet<>(); } @@ -132,25 +109,6 @@ public class PluginManager { return searchCached(plugins, cachedOperators, Plugin::providedOperators, Plugin::getOperator, name); } - /** - * Gets a numer implementation under the given name. - * - * @param name the name of the implementation. - * @return the implementation class - */ - public Class numberFor(String name) { - return searchCached(plugins, cachedNumbers, Plugin::providedNumbers, Plugin::getNumber, name); - } - - /** - * Gets the constant provider for the given class. - * @param forClass the class to get the provider for. - * @return the provider. - */ - public java.util.function.Function constantProviderFor(Class forClass){ - return searchCached(plugins, cachedConstantProviders, Plugin::providedConstantProviders, Plugin::getConstantProvider, forClass); - } - /** * Adds an instance of Plugin that already has been instantiated. * @@ -185,8 +143,6 @@ public class PluginManager { for (Plugin plugin : plugins) { allFunctions.addAll(plugin.providedFunctions()); allOperators.addAll(plugin.providedOperators()); - allNumbers.addAll(plugin.providedNumbers()); - allConstantProviders.addAll(plugin.providedConstantProviders()); } listeners.forEach(e -> e.onLoad(this)); } @@ -198,8 +154,6 @@ public class PluginManager { for (Plugin plugin : plugins) plugin.disable(); allFunctions.clear(); allOperators.clear(); - allNumbers.clear(); - allConstantProviders.clear(); listeners.forEach(e -> e.onUnload(this)); } @@ -229,23 +183,6 @@ public class PluginManager { return allOperators; } - /** - * Gets all the number implementations loaded by the Plugin Manager - * - * @return the set of all implementations that were loaded - */ - public Set getAllNumbers() { - return allNumbers; - } - - /** - * Gets all the constant providers loaded by the Plugin Manager. - * @return the set of all constant providers that were loaded. - */ - public Set> getAllConstantProviders() { - return allConstantProviders; - } - /** * Adds a plugin change listener to this plugin manager. * diff --git a/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java b/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java index c916c7c..be6b3e8 100755 --- a/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java +++ b/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java @@ -6,9 +6,7 @@ import org.nwapw.abacus.function.OperatorAssociativity; import org.nwapw.abacus.function.OperatorType; import org.nwapw.abacus.number.NaiveNumber; import org.nwapw.abacus.number.NumberInterface; -import org.nwapw.abacus.number.PreciseNumber; -import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.HashMap; import java.util.function.BiFunction; @@ -340,9 +338,6 @@ public class StandardPlugin extends Plugin { @Override public void onEnable() { - registerNumber("naive", NaiveNumber.class); - registerNumber("precise", PreciseNumber.class); - registerOperator("+", OP_ADD); registerOperator("-", OP_SUBTRACT); registerOperator("*", OP_MULTIPLY);