From 61f40c72aa7823591ba5660e71002fd0972e88ad Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 8 Aug 2017 11:09:46 -0700 Subject: [PATCH] Add a registered documentation set. --- .../nwapw/abacus/plugin/PluginManager.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/java/org/nwapw/abacus/plugin/PluginManager.java b/src/main/java/org/nwapw/abacus/plugin/PluginManager.java index 9ec48b4..e6d4953 100644 --- a/src/main/java/org/nwapw/abacus/plugin/PluginManager.java +++ b/src/main/java/org/nwapw/abacus/plugin/PluginManager.java @@ -1,6 +1,8 @@ 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.number.NumberInterface; @@ -34,6 +36,10 @@ public class PluginManager { * The map of number implementations registered by the plugins. */ private Map registeredNumberImplementations; + /** + * The map of documentation for functions registered by the plugins. + */ + private Set registeredDocumentation; /** * The list of number implementations that have been * found by their implementation class. @@ -65,6 +71,7 @@ public class PluginManager { registeredFunctions = new HashMap<>(); registeredOperators = new HashMap<>(); registeredNumberImplementations = new HashMap<>(); + registeredDocumentation = new HashSet<>(); cachedInterfaceImplementations = new HashMap<>(); cachedPi = new HashMap<>(); listeners = new HashSet<>(); @@ -97,6 +104,15 @@ public class PluginManager { registeredNumberImplementations.put(name, implementation); } + /** + * Registers the given documentation with the plugin manager, + * making it accessible to the plugin manager etc. + * @param documentation the documentation to register. + */ + public void registerDocumentation(Documentation documentation){ + registeredDocumentation.add(documentation); + } + /** * Gets the function registered under the given name. * @param name the name of the function. @@ -124,6 +140,19 @@ public class PluginManager { return registeredNumberImplementations.get(name); } + /** + * Gets the documentation for the given entity of the given type. + * @param name the name of the entity to search for. + * @param type the type that this entity is, to filter out similarly named documentation. + * @return the documentation object. + */ + public Documentation documentationFor(String name, DocumentationType type){ + for(Documentation entry : registeredDocumentation){ + if(entry.getCodeName().equals(name) && entry.getType() == type) return entry; + } + return null; + } + /** * Gets the number implementation for the given implementation class. * @@ -212,6 +241,7 @@ public class PluginManager { registeredFunctions.clear(); registeredOperators.clear(); registeredNumberImplementations.clear(); + registeredDocumentation.clear(); cachedInterfaceImplementations.clear(); cachedPi.clear(); listeners.forEach(e -> e.onUnload(this));