diff --git a/src/main/java/org/nwapw/abacus/plugin/NumberImplementation.java b/src/main/java/org/nwapw/abacus/plugin/NumberImplementation.java index c3827a5..60e02c6 100644 --- a/src/main/java/org/nwapw/abacus/plugin/NumberImplementation.java +++ b/src/main/java/org/nwapw/abacus/plugin/NumberImplementation.java @@ -18,6 +18,18 @@ public abstract class NumberImplementation { promotionPaths = new HashMap<>(); } + public final Map, Function> getPromotionPaths(){ + return promotionPaths; + } + + public final Class getImplementation(){ + return implementation; + } + + public final int getPriority(){ + return priority; + } + public abstract NumberInterface instanceForString(String string); public abstract NumberInterface instanceForPi(); diff --git a/src/main/java/org/nwapw/abacus/plugin/PluginManager.java b/src/main/java/org/nwapw/abacus/plugin/PluginManager.java index 7d837cb..9c98dfd 100644 --- a/src/main/java/org/nwapw/abacus/plugin/PluginManager.java +++ b/src/main/java/org/nwapw/abacus/plugin/PluginManager.java @@ -2,6 +2,7 @@ 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,6 +32,7 @@ public class PluginManager { */ private Map cachedOperators; private Map cachedNumberImplementations; + private Map, NumberImplementation> cachedInterfaceImplementations; /** * List of all functions loaded by the plugins. */ @@ -54,6 +56,7 @@ public class PluginManager { cachedFunctions = new HashMap<>(); cachedOperators = new HashMap<>(); cachedNumberImplementations = new HashMap<>(); + cachedInterfaceImplementations = new HashMap<>(); allFunctions = new HashSet<>(); allOperators = new HashSet<>(); allNumberImplementations = new HashSet<>(); @@ -117,6 +120,24 @@ public class PluginManager { return searchCached(plugins, cachedNumberImplementations, Plugin::providedNumberImplementations, Plugin::getNumberImplementation, name); } + + public NumberImplementation interfaceImplementationFor(Class 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. *