1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-10-01 10:50:50 -07:00

Remove old reference to the promotion system and the number class map.

This commit is contained in:
Danila Fedorin 2017-08-03 20:50:39 -07:00
parent 7dda1f2fcf
commit 542f062b5e
4 changed files with 0 additions and 181 deletions

View File

@ -1,10 +1,6 @@
package org.nwapw.abacus.function; package org.nwapw.abacus.function;
import org.nwapw.abacus.number.NaiveNumber;
import org.nwapw.abacus.number.NumberInterface; import org.nwapw.abacus.number.NumberInterface;
import org.nwapw.abacus.number.PreciseNumber;
import java.util.HashMap;
/** /**
* A function that operates on one or more * A function that operates on one or more
@ -12,15 +8,6 @@ import java.util.HashMap;
*/ */
public abstract class Function { public abstract class Function {
/**
* A map to correctly promote different number implementations to each other.
*/
private static final HashMap<Class<? extends NumberInterface>, Integer> priorityMap =
new HashMap<Class<? extends NumberInterface>, Integer>() {{
put(NaiveNumber.class, 0);
put(PreciseNumber.class, 1);
}};
/** /**
* Checks whether the given params will work for the given function. * Checks whether the given params will work for the given function.
* *

View File

@ -2,7 +2,6 @@ package org.nwapw.abacus.plugin;
import org.nwapw.abacus.function.Function; import org.nwapw.abacus.function.Function;
import org.nwapw.abacus.function.Operator; import org.nwapw.abacus.function.Operator;
import org.nwapw.abacus.number.NumberInterface;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -25,14 +24,6 @@ public abstract class Plugin {
* A hash map of operators mapped to their string names. * A hash map of operators mapped to their string names.
*/ */
private Map<String, Operator> operators; private Map<String, Operator> operators;
/**
* A hash map of operators mapped to their string names.
*/
private Map<String, Class<? extends NumberInterface>> numbers;
/**
* A hash map of constant providers for each number type.
*/
private Map<Class<?>, java.util.function.Function<String, NumberInterface>> constantProviders;
/** /**
* The plugin manager in which to search for functions * The plugin manager in which to search for functions
* not inside this package, * not inside this package,
@ -55,8 +46,6 @@ public abstract class Plugin {
this.manager = manager; this.manager = manager;
functions = new HashMap<>(); functions = new HashMap<>();
operators = new HashMap<>(); operators = new HashMap<>();
numbers = new HashMap<>();
constantProviders = new HashMap<>();
enabled = false; enabled = false;
} }
@ -78,23 +67,6 @@ public abstract class Plugin {
return operators.keySet(); return operators.keySet();
} }
/**
* Gets the list of all numbers provided by this plugin.
*
* @return the list of registered numbers.
*/
public final Set<String> providedNumbers() {
return numbers.keySet();
}
/**
* Gets the list of all constant providers provided by this plugin.
* @return the list of constant providers.
*/
public final Set<Class<?>> providedConstantProviders() {
return constantProviders.keySet();
}
/** /**
* Gets a function under the given function name. * Gets a function under the given function name.
* *
@ -115,26 +87,6 @@ public abstract class Plugin {
return operators.get(operatorName); 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<? extends NumberInterface> 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<String, NumberInterface> getConstantProvider(Class<?> pluginClass){
return constantProviders.get(pluginClass);
}
/** /**
* Enables the function, loading the necessary instances * Enables the function, loading the necessary instances
* of functions. * of functions.
@ -154,8 +106,6 @@ public abstract class Plugin {
onDisable(); onDisable();
functions.clear(); functions.clear();
operators.clear(); operators.clear();
numbers.clear();
constantProviders.clear();
enabled = false; enabled = false;
} }
@ -182,32 +132,6 @@ public abstract class Plugin {
operators.put(name, operator); 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<? extends NumberInterface> 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<String, NumberInterface> constantProvider) {
constantProviders.put(providerFor, constantProvider);
}
/** /**
* Searches the PluginManager for the given function name. * Searches the PluginManager for the given function name.
* This can be used by the plugins internally in order to call functions * 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); 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<? extends NumberInterface> 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<String, NumberInterface> constantProviderFor(Class<?> forClass){
return manager.constantProviderFor(forClass);
}
/** /**
* Abstract method to be overridden by plugin implementation, in which the plugins * Abstract method to be overridden by plugin implementation, in which the plugins
* are supposed to register the functions they provide and do any other * are supposed to register the functions they provide and do any other

View File

@ -2,7 +2,6 @@ package org.nwapw.abacus.plugin;
import org.nwapw.abacus.function.Function; import org.nwapw.abacus.function.Function;
import org.nwapw.abacus.function.Operator; import org.nwapw.abacus.function.Operator;
import org.nwapw.abacus.number.NumberInterface;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.*; import java.util.*;
@ -31,16 +30,6 @@ public class PluginManager {
* that is, found in a plugin and returned. * that is, found in a plugin and returned.
*/ */
private Map<String, Operator> cachedOperators; private Map<String, Operator> cachedOperators;
/**
* List of registered number implementations that have
* been cached, that is, found in a plugin and returned.
*/
private Map<String, Class<? extends NumberInterface>> cachedNumbers;
/**
* List of registered constant providers for every
* number class.
*/
private Map<Class<?>, java.util.function.Function<String, NumberInterface>> cachedConstantProviders;
/** /**
* List of all functions loaded by the plugins. * List of all functions loaded by the plugins.
*/ */
@ -49,14 +38,6 @@ public class PluginManager {
* List of all operators loaded by the plugins. * List of all operators loaded by the plugins.
*/ */
private Set<String> allOperators; private Set<String> allOperators;
/**
* List of all numbers loaded by the plugins.
*/
private Set<String> allNumbers;
/**
* List of all the constant providers loaded by the plugins.
*/
private Set<Class<?>> allConstantProviders;
/** /**
* The list of plugin listeners attached to this instance. * The list of plugin listeners attached to this instance.
*/ */
@ -70,12 +51,8 @@ public class PluginManager {
plugins = new HashSet<>(); plugins = new HashSet<>();
cachedFunctions = new HashMap<>(); cachedFunctions = new HashMap<>();
cachedOperators = new HashMap<>(); cachedOperators = new HashMap<>();
cachedNumbers = new HashMap<>();
cachedConstantProviders = new HashMap<>();
allFunctions = new HashSet<>(); allFunctions = new HashSet<>();
allOperators = new HashSet<>(); allOperators = new HashSet<>();
allNumbers = new HashSet<>();
allConstantProviders = new HashSet<>();
listeners = new HashSet<>(); listeners = new HashSet<>();
} }
@ -132,25 +109,6 @@ public class PluginManager {
return searchCached(plugins, cachedOperators, Plugin::providedOperators, Plugin::getOperator, name); 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<? extends NumberInterface> 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<String, NumberInterface> constantProviderFor(Class<?> forClass){
return searchCached(plugins, cachedConstantProviders, Plugin::providedConstantProviders, Plugin::getConstantProvider, forClass);
}
/** /**
* Adds an instance of Plugin that already has been instantiated. * Adds an instance of Plugin that already has been instantiated.
* *
@ -185,8 +143,6 @@ public class PluginManager {
for (Plugin plugin : plugins) { for (Plugin plugin : plugins) {
allFunctions.addAll(plugin.providedFunctions()); allFunctions.addAll(plugin.providedFunctions());
allOperators.addAll(plugin.providedOperators()); allOperators.addAll(plugin.providedOperators());
allNumbers.addAll(plugin.providedNumbers());
allConstantProviders.addAll(plugin.providedConstantProviders());
} }
listeners.forEach(e -> e.onLoad(this)); listeners.forEach(e -> e.onLoad(this));
} }
@ -198,8 +154,6 @@ public class PluginManager {
for (Plugin plugin : plugins) plugin.disable(); for (Plugin plugin : plugins) plugin.disable();
allFunctions.clear(); allFunctions.clear();
allOperators.clear(); allOperators.clear();
allNumbers.clear();
allConstantProviders.clear();
listeners.forEach(e -> e.onUnload(this)); listeners.forEach(e -> e.onUnload(this));
} }
@ -229,23 +183,6 @@ public class PluginManager {
return allOperators; return allOperators;
} }
/**
* Gets all the number implementations loaded by the Plugin Manager
*
* @return the set of all implementations that were loaded
*/
public Set<String> 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<Class<?>> getAllConstantProviders() {
return allConstantProviders;
}
/** /**
* Adds a plugin change listener to this plugin manager. * Adds a plugin change listener to this plugin manager.
* *

View File

@ -6,9 +6,7 @@ import org.nwapw.abacus.function.OperatorAssociativity;
import org.nwapw.abacus.function.OperatorType; import org.nwapw.abacus.function.OperatorType;
import org.nwapw.abacus.number.NaiveNumber; import org.nwapw.abacus.number.NaiveNumber;
import org.nwapw.abacus.number.NumberInterface; import org.nwapw.abacus.number.NumberInterface;
import org.nwapw.abacus.number.PreciseNumber;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.function.BiFunction; import java.util.function.BiFunction;
@ -340,9 +338,6 @@ public class StandardPlugin extends Plugin {
@Override @Override
public void onEnable() { public void onEnable() {
registerNumber("naive", NaiveNumber.class);
registerNumber("precise", PreciseNumber.class);
registerOperator("+", OP_ADD); registerOperator("+", OP_ADD);
registerOperator("-", OP_SUBTRACT); registerOperator("-", OP_SUBTRACT);
registerOperator("*", OP_MULTIPLY); registerOperator("*", OP_MULTIPLY);