From 504ca816530efdff06bc202e0432ebd354aec304 Mon Sep 17 00:00:00 2001 From: EVE Date: Tue, 14 Mar 2017 12:07:14 -0400 Subject: Cleanup --- .../bjc/utils/components/ComponentDescription.java | 24 ++++------ .../components/ComponentDescriptionFileParser.java | 14 +++--- .../components/ComponentDescriptionState.java | 12 ++--- .../utils/components/FileComponentRepository.java | 51 +++++++++++----------- .../bjc/utils/components/IComponentRepository.java | 10 ++--- .../bjc/utils/components/IDescribedComponent.java | 18 ++++---- .../java/bjc/utils/components/package-info.java | 2 +- 7 files changed, 61 insertions(+), 70 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/components') 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 c473150..13132ed 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java @@ -2,31 +2,29 @@ package bjc.utils.components; /** * Generic implementation of a description for a component - * + * * @author ben * */ public class ComponentDescription implements IDescribedComponent { private static void sanityCheckArgs(String name, String author, String description, int version) { - if (name == null) { + if(name == null) throw new NullPointerException("Component name can't be null"); - } else if (version <= 0) { - throw new IllegalArgumentException("Component version must be greater than 0"); - } + else if(version <= 0) throw new IllegalArgumentException("Component version must be greater than 0"); } /** * The author of the component */ - private String author; + private String author; /** * The description of the component */ - private String description; + private String description; /** * The name of the component */ - private String name; + private String name; /** * The version of the component @@ -35,7 +33,7 @@ public class ComponentDescription implements IDescribedComponent { /** * Create a new component description - * + * * @param name * The name of the component * @param author @@ -58,18 +56,14 @@ public class ComponentDescription implements IDescribedComponent { @Override public String getAuthor() { - if (author == null) { - return IDescribedComponent.super.getAuthor(); - } + if(author == null) return IDescribedComponent.super.getAuthor(); return author; } @Override public String getDescription() { - if (description == null) { - return IDescribedComponent.super.getDescription(); - } + if(description == null) return IDescribedComponent.super.getDescription(); return description; } 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 22221d2..c939708 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java @@ -1,15 +1,15 @@ package bjc.utils.components; -import static bjc.utils.parserutils.RuleBasedReaderPragmas.buildInteger; -import static bjc.utils.parserutils.RuleBasedReaderPragmas.buildStringCollapser; +import bjc.utils.parserutils.RuleBasedConfigReader; import java.io.InputStream; -import bjc.utils.parserutils.RuleBasedConfigReader; +import static bjc.utils.parserutils.RuleBasedReaderPragmas.buildInteger; +import static bjc.utils.parserutils.RuleBasedReaderPragmas.buildStringCollapser; /** * Read a component description from a file - * + * * @author ben * */ @@ -35,15 +35,13 @@ public class ComponentDescriptionFileParser { /** * 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) { - if (inputSource == null) { - throw new NullPointerException("Input source must not be null"); - } + if(inputSource == null) throw new NullPointerException("Input source must not be null"); ComponentDescriptionState readState = reader.fromStream(inputSource, new ComponentDescriptionState()); 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 70f308b..02e003a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionState.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionState.java @@ -2,7 +2,7 @@ package bjc.utils.components; /** * Internal state of component description parser - * + * * @author ben * */ @@ -21,7 +21,7 @@ public class ComponentDescriptionState { /** * Set the author of this component - * + * * @param author * The author of this component */ @@ -31,7 +31,7 @@ public class ComponentDescriptionState { /** * Set the description of this component - * + * * @param description * The description of this component */ @@ -41,7 +41,7 @@ public class ComponentDescriptionState { /** * Set the name of this component - * + * * @param name * The name of this component */ @@ -51,7 +51,7 @@ public class ComponentDescriptionState { /** * Set the version of this component - * + * * @param version * The version of this component */ @@ -61,7 +61,7 @@ public class ComponentDescriptionState { /** * Convert this state into the description it represents - * + * * @return The description represented by this state */ public ComponentDescription toDescription() { 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 7aa7c07..d69b794 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java @@ -1,5 +1,12 @@ package bjc.utils.components; +import bjc.utils.data.IHolder; +import bjc.utils.data.Identity; +import bjc.utils.funcdata.FunctionalMap; +import bjc.utils.funcdata.IList; +import bjc.utils.funcdata.IMap; +import bjc.utils.funcutils.FileUtils; + import java.io.File; import java.io.IOException; import java.nio.file.Path; @@ -9,16 +16,9 @@ import java.util.function.Function; import java.util.logging.Level; import java.util.logging.Logger; -import bjc.utils.data.IHolder; -import bjc.utils.data.Identity; -import bjc.utils.funcdata.FunctionalMap; -import bjc.utils.funcdata.IList; -import bjc.utils.funcdata.IMap; -import bjc.utils.funcutils.FileUtils; - /** * A component repository that loads its components from files in a directory - * + * * @author ben * * @param @@ -38,10 +38,10 @@ public class FileComponentRepository /** * Create a new component repository sourcing components from files in a * directory - * + * * An exception thrown during the loading of a component will only cause * the loading of that component to fail, but a warning will be logged. - * + * * @param directory * The directory to read component files from * @param componentReader @@ -49,14 +49,12 @@ public class FileComponentRepository */ public FileComponentRepository(File directory, Function componentReader) { // Make sure we have valid arguments - if (directory == null) { + if(directory == null) throw new NullPointerException("Directory must not be null"); - } else if (!directory.isDirectory()) { + else if(!directory.isDirectory()) throw new IllegalArgumentException("File " + directory + " is not a directory.\n" + "Components can only be read from a directory"); - } else if (componentReader == null) { - throw new NullPointerException("Component reader must not be null"); - } + else if(componentReader == null) throw new NullPointerException("Component reader must not be null"); // Initialize our fields components = new FunctionalMap<>(); @@ -69,13 +67,14 @@ public class FileComponentRepository // but // not recurse into sub-directories BiPredicate firstLevelTraverser = (pth, attr) -> { - if (attr.isDirectory() && !isFirstDir.getValue()) { - /* - * Skip directories, they probably have - * component support files. - */ + if(attr.isDirectory() && !isFirstDir + .getValue()) /* + * Skip directories, + * they probably have + * component support + * files. + */ return false; - } /* * Don't skip the first directory, that's the parent @@ -95,7 +94,7 @@ public class FileComponentRepository // failed return true; }); - } catch (IOException ioex) { + } catch(IOException ioex) { CLASS_LOGGER.log(Level.WARNING, ioex, () -> "Error found reading component from file."); } } @@ -128,14 +127,14 @@ public class FileComponentRepository // Try to load the component ComponentType component = componentReader.apply(pth.toFile()); - if (component == null) { + if(component == null) throw new NullPointerException("Component reader read null component"); - } else if (!components.containsKey(component.getName())) { + else if(!components.containsKey(component.getName())) { // We only care about the latest version of a // component ComponentType oldComponent = components.put(component.getName(), component); - if (oldComponent.getVersion() > component.getVersion()) { + if(oldComponent.getVersion() > component.getVersion()) { components.put(oldComponent.getName(), oldComponent); } } else { @@ -144,7 +143,7 @@ public class FileComponentRepository + "Only the latest version of the component" + component + " will be registered ."); } - } catch (Exception ex) { + } catch(Exception ex) { CLASS_LOGGER.log(Level.WARNING, ex, () -> "Error found reading component from file " + pth.toString() + ". This component will not be loaded"); } 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 f3aab76..5ef65ee 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java @@ -6,7 +6,7 @@ import bjc.utils.funcdata.IMap; /** * A collection of implementations of a particular type of * {@link IDescribedComponent} - * + * * @author ben * * @param @@ -15,7 +15,7 @@ import bjc.utils.funcdata.IMap; public interface IComponentRepository { /** * Get all of the components this repository knows about - * + * * @return A map from component name to component, containing all of the * components in the repositories */ @@ -23,7 +23,7 @@ public interface IComponentRepository /** * 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 @@ -33,7 +33,7 @@ public interface IComponentRepository /** * Get a list of all the registered componets - * + * * @return A list of all the registered components */ public default IList getList() { @@ -42,7 +42,7 @@ public interface IComponentRepository /** * Get the source from which these components came - * + * * @return The source from which these components came */ public String getSource(); diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/IDescribedComponent.java b/BJC-Utils2/src/main/java/bjc/utils/components/IDescribedComponent.java index 6b87ba7..a397bbc 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/IDescribedComponent.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/IDescribedComponent.java @@ -3,16 +3,16 @@ package bjc.utils.components; /** * Represents a optional component that has status information associated with * it - * + * * @author ben * */ public interface IDescribedComponent { /** * Get the author of this component - * + * * Providing this is optional, with "Anonymous" as the default author - * + * * @return The author of the component */ public default String getAuthor() { @@ -21,10 +21,10 @@ public interface IDescribedComponent { /** * Get the description of this component - * + * * Providing this is optional, with the default being a note that no * description was provided - * + * * @return The description of the component */ public default String getDescription() { @@ -33,18 +33,18 @@ public interface IDescribedComponent { /** * Get the name of this component. - * + * * This is the only thing required of all components - * + * * @return The name of the component */ public String getName(); /** * Get the version of this component - * + * * Providing this is optional, with "1" as the default version - * + * * @return The version of this component */ public default int getVersion() { diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/package-info.java b/BJC-Utils2/src/main/java/bjc/utils/components/package-info.java index 9f83fb0..37a9e84 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/package-info.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/package-info.java @@ -1,6 +1,6 @@ /** * This package contains utilities for components - * + * * @author ben * */ -- cgit v1.2.3