mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-23 07:50:09 -08:00
Add attempt to find the number implementation from the class.
This commit is contained in:
parent
4fd30030f9
commit
b06e9fcbee
|
@ -18,6 +18,18 @@ public abstract class NumberImplementation {
|
||||||
promotionPaths = new HashMap<>();
|
promotionPaths = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final Map<Class<? extends NumberInterface>, Function<NumberInterface, NumberInterface>> getPromotionPaths(){
|
||||||
|
return promotionPaths;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final Class<? extends NumberInterface> getImplementation(){
|
||||||
|
return implementation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final int getPriority(){
|
||||||
|
return priority;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract NumberInterface instanceForString(String string);
|
public abstract NumberInterface instanceForString(String string);
|
||||||
public abstract NumberInterface instanceForPi();
|
public abstract NumberInterface instanceForPi();
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ 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,6 +32,7 @@ public class PluginManager {
|
||||||
*/
|
*/
|
||||||
private Map<String, Operator> cachedOperators;
|
private Map<String, Operator> cachedOperators;
|
||||||
private Map<String, NumberImplementation> cachedNumberImplementations;
|
private Map<String, NumberImplementation> cachedNumberImplementations;
|
||||||
|
private Map<Class<? extends NumberInterface>, NumberImplementation> cachedInterfaceImplementations;
|
||||||
/**
|
/**
|
||||||
* List of all functions loaded by the plugins.
|
* List of all functions loaded by the plugins.
|
||||||
*/
|
*/
|
||||||
|
@ -54,6 +56,7 @@ public class PluginManager {
|
||||||
cachedFunctions = new HashMap<>();
|
cachedFunctions = new HashMap<>();
|
||||||
cachedOperators = new HashMap<>();
|
cachedOperators = new HashMap<>();
|
||||||
cachedNumberImplementations = new HashMap<>();
|
cachedNumberImplementations = new HashMap<>();
|
||||||
|
cachedInterfaceImplementations = new HashMap<>();
|
||||||
allFunctions = new HashSet<>();
|
allFunctions = new HashSet<>();
|
||||||
allOperators = new HashSet<>();
|
allOperators = new HashSet<>();
|
||||||
allNumberImplementations = new HashSet<>();
|
allNumberImplementations = new HashSet<>();
|
||||||
|
@ -117,6 +120,24 @@ public class PluginManager {
|
||||||
return searchCached(plugins, cachedNumberImplementations, Plugin::providedNumberImplementations,
|
return searchCached(plugins, cachedNumberImplementations, Plugin::providedNumberImplementations,
|
||||||
Plugin::getNumberImplementation, name);
|
Plugin::getNumberImplementation, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NumberImplementation interfaceImplementationFor(Class<? extends NumberInterface> name){
|
||||||
|
if(cachedInterfaceImplementations.containsKey(name)) return cachedInterfaceImplementations.get(name);
|
||||||
|
NumberImplementation toReturn = null;
|
||||||
|
outside:
|
||||||
|
for(Plugin plugin : plugins){
|
||||||
|
for(String implementationName : plugin.providedNumberImplementations()){
|
||||||
|
NumberImplementation implementation = plugin.getNumberImplementation(implementationName);
|
||||||
|
if(implementation.getImplementation().equals(name)) {
|
||||||
|
toReturn = implementation;
|
||||||
|
break outside;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cachedInterfaceImplementations.put(name, toReturn);
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an instance of Plugin that already has been instantiated.
|
* Adds an instance of Plugin that already has been instantiated.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user