diff options
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/components')
5 files changed, 99 insertions, 99 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java index a946cae..9429dde 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java @@ -7,6 +7,22 @@ package bjc.utils.components; * */ public class ComponentDescription implements IDescribedComponent { + private static void sanityCheckArgs(String name, String author, + String description, int version) { + if (name == null) { + throw new IllegalArgumentException( + "Component name can't be null"); + } else if (author == null) { + throw new IllegalArgumentException( + "Component author can't be null"); + } else if (description == null) { + throw new IllegalArgumentException( + "Component description can't be null"); + } else if (version < 0) { + throw new IllegalArgumentException( + "Component version must be greater than 0"); + } + } /** * The author of the component */ @@ -19,6 +35,7 @@ public class ComponentDescription implements IDescribedComponent { * The name of the component */ private String name; + /** * The version of the component */ @@ -49,23 +66,6 @@ public class ComponentDescription implements IDescribedComponent { this.version = version; } - private static void sanityCheckArgs(String name, String author, - String description, int version) { - if (name == null) { - throw new IllegalArgumentException( - "Component name can't be null"); - } else if (author == null) { - throw new IllegalArgumentException( - "Component author can't be null"); - } else if (description == null) { - throw new IllegalArgumentException( - "Component description can't be null"); - } else if (version < 0) { - throw new IllegalArgumentException( - "Component version must be greater than 0"); - } - } - @Override public String getAuthor() { return author; diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java index 52ab0b3..be0a65b 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java @@ -31,6 +31,34 @@ public class ComponentDescriptionFileParser { setupReaderPragmas(); } + private static BiConsumer<FunctionalStringTokenizer, ComponentDescriptionState> buildStringCollapserPragma( + String pragmaName) { + return (tokenizer, state) -> { + if (!tokenizer.hasMoreTokens()) { + throw new PragmaFormatException("Pragma " + pragmaName + + " requires one string argument"); + } + + state.setName(ListUtils + .collapseTokens(tokenizer.toList((strang) -> strang))); + }; + } + + /** + * Parse a component description from a stream + * + * @param inputSource + * The stream to parse from + * @return The description parsed from the stream + */ + public static ComponentDescription fromStream( + InputStream inputSource) { + ComponentDescriptionState readState = reader + .fromStream(inputSource, new ComponentDescriptionState()); + + return readState.toDescription(); + } + private static void setupReaderPragmas() { reader.addPragma("name", buildStringCollapserPragma("name")); @@ -61,32 +89,4 @@ public class ComponentDescriptionFileParser { } }); } - - private static BiConsumer<FunctionalStringTokenizer, ComponentDescriptionState> buildStringCollapserPragma( - String pragmaName) { - return (tokenizer, state) -> { - if (!tokenizer.hasMoreTokens()) { - throw new PragmaFormatException("Pragma " + pragmaName - + " requires one string argument"); - } - - state.setName(ListUtils - .collapseTokens(tokenizer.toList((strang) -> strang))); - }; - } - - /** - * Parse a component description from a stream - * - * @param inputSource - * The stream to parse from - * @return The description parsed from the stream - */ - public static ComponentDescription fromStream( - InputStream inputSource) { - ComponentDescriptionState readState = reader - .fromStream(inputSource, new ComponentDescriptionState()); - - return readState.toDescription(); - } } diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionState.java b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionState.java index 7d91c84..199009c 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionState.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionState.java @@ -16,23 +16,13 @@ public class ComponentDescriptionState { private int version; /** - * Convert this state into the description it represents - * - * @return The description represented by this state - */ - public ComponentDescription toDescription() { - return new ComponentDescription(name, author, description, - version); - } - - /** - * Set the name of this component + * Set the author of this component * - * @param name - * The name of this component + * @param author + * The author of this component */ - public void setName(String name) { - this.name = name; + public void setAuthor(String author) { + this.author = author; } /** @@ -46,13 +36,13 @@ public class ComponentDescriptionState { } /** - * Set the author of this component + * Set the name of this component * - * @param author - * The author of this component + * @param name + * The name of this component */ - public void setAuthor(String author) { - this.author = author; + public void setName(String name) { + this.name = name; } /** @@ -64,4 +54,14 @@ public class ComponentDescriptionState { public void setVersion(int version) { this.version = version; } + + /** + * Convert this state into the description it represents + * + * @return The description represented by this state + */ + public ComponentDescription toDescription() { + return new ComponentDescription(name, author, description, + version); + } } diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java b/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java index 8b0d303..bc1b990 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java @@ -98,27 +98,9 @@ public class FileComponentRepository<E extends IDescribedComponent> } } - private void loadComponent(Function<File, E> componentReader, - Path pth) { - try { - E component = componentReader.apply(pth.toFile()); - - if (component == null) { - throw new NullPointerException( - "Component reader read null component"); - } else if (!components.containsKey(component.getName())) { - components.put(component.getName(), component); - } else { - CLASS_LOGGER.warn("Found a duplicate component.\n" - + "Multiple versions of the same component are not currently supported.\n" - + "The component" + component - + " will not be registered ."); - } - } catch (Exception ex) { - CLASS_LOGGER.warn("Error found reading component from file " - + pth.toString() - + ". This component will not be loaded", ex); - } + @Override + public E getComponentByName(String name) { + return components.get(name); } @Override @@ -141,8 +123,26 @@ public class FileComponentRepository<E extends IDescribedComponent> return "Components read from directory " + sourceDirectory + "."; } - @Override - public E getComponentByName(String name) { - return components.get(name); + private void loadComponent(Function<File, E> componentReader, + Path pth) { + try { + E component = componentReader.apply(pth.toFile()); + + if (component == null) { + throw new NullPointerException( + "Component reader read null component"); + } else if (!components.containsKey(component.getName())) { + components.put(component.getName(), component); + } else { + CLASS_LOGGER.warn("Found a duplicate component.\n" + + "Multiple versions of the same component are not currently supported.\n" + + "The component" + component + + " will not be registered ."); + } + } catch (Exception ex) { + CLASS_LOGGER.warn("Error found reading component from file " + + pth.toString() + + ". This component will not be loaded", ex); + } } }
\ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java b/BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java index 348be3e..6780f2e 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java @@ -13,6 +13,16 @@ import bjc.utils.funcdata.IFunctionalMap; */ public interface IComponentRepository<E extends IDescribedComponent> { /** + * Get a component with a specific name + * + * @param name + * The name of the component to retrieve + * @return The named component, or null if no component with that name + * exists + */ + public E getComponentByName(String name); + + /** * Get a list of all the registered componets * * @return A list of all the registered components @@ -30,16 +40,6 @@ public interface IComponentRepository<E extends IDescribedComponent> { public IFunctionalMap<String, E> getComponents(); /** - * Get a component with a specific name - * - * @param name - * The name of the component to retrieve - * @return The named component, or null if no component with that name - * exists - */ - public E getComponentByName(String name); - - /** * Get the source from which these components came * * @return The source from which these components came |
