From 27bf571d6413c3cc6a5d664b5bddd38d21d7b1cd Mon Sep 17 00:00:00 2001 From: EVE Date: Mon, 13 Mar 2017 16:42:21 -0400 Subject: Formatting --- .../bjc/utils/components/ComponentDescription.java | 35 ++++----- .../components/ComponentDescriptionFileParser.java | 29 +++----- .../components/ComponentDescriptionState.java | 19 +++-- .../utils/components/FileComponentRepository.java | 85 ++++++++++------------ .../bjc/utils/components/IComponentRepository.java | 11 ++- .../bjc/utils/components/IDescribedComponent.java | 4 +- 6 files changed, 81 insertions(+), 102 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 1ec5b80..c473150 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java @@ -7,50 +7,47 @@ package bjc.utils.components; * */ public class ComponentDescription implements IDescribedComponent { - private static void sanityCheckArgs(String name, String author, - String description, int version) { + private static void sanityCheckArgs(String name, String author, String description, int version) { 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"); + 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 */ - private int version; + private int version; /** * Create a new component description * * @param name - * The name of the component + * The name of the component * @param author - * The author of the component + * The author of the component * @param description - * The description of the component + * The description of the component * @param version - * The version of the component + * The version of the component * @throws IllegalArgumentException - * thrown if version is less than 1 + * thrown if version is less than 1 */ - public ComponentDescription(String name, String author, - String description, int version) { + public ComponentDescription(String name, String author, String description, int version) { sanityCheckArgs(name, author, description, version); this.name = name; @@ -61,19 +58,19 @@ public class ComponentDescription implements IDescribedComponent { @Override public String getAuthor() { - if(author == null) { + if (author == null) { return IDescribedComponent.super.getAuthor(); } - + return author; } @Override public String getDescription() { - if(description == null) { + 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 ad5e1a2..22221d2 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java @@ -19,7 +19,8 @@ public class ComponentDescriptionFileParser { // Initialize the reader and its pragmas static { - // This reader works entirely off of pragmas, so no need to handle + // This reader works entirely off of pragmas, so no need to + // handle // rules reader = new RuleBasedConfigReader<>((tokenizer, statePair) -> { // Don't need to do anything on rule start @@ -36,17 +37,15 @@ public class ComponentDescriptionFileParser { * Parse a component description from a stream * * @param inputSource - * The stream to parse from + * The stream to parse from * @return The description parsed from the stream */ - public static ComponentDescription fromStream( - InputStream inputSource) { - if(inputSource == null) { + public static ComponentDescription fromStream(InputStream inputSource) { + if (inputSource == null) { throw new NullPointerException("Input source must not be null"); } - - ComponentDescriptionState readState = reader - .fromStream(inputSource, new ComponentDescriptionState()); + + ComponentDescriptionState readState = reader.fromStream(inputSource, new ComponentDescriptionState()); return readState.toDescription(); } @@ -55,17 +54,13 @@ public class ComponentDescriptionFileParser { * Create all the pragmas the reader needs to function */ private static void setupReaderPragmas() { - reader.addPragma("name", buildStringCollapser("name", - (name, state) -> state.setName(name))); + reader.addPragma("name", buildStringCollapser("name", (name, state) -> state.setName(name))); - reader.addPragma("author", buildStringCollapser("author", - (author, state) -> state.setAuthor(author))); + reader.addPragma("author", buildStringCollapser("author", (author, state) -> state.setAuthor(author))); - reader.addPragma("description", - buildStringCollapser("description", (description, - state) -> state.setDescription(description))); + reader.addPragma("description", buildStringCollapser("description", + (description, state) -> state.setDescription(description))); - reader.addPragma("version", buildInteger("version", - (version, state) -> state.setVersion(version))); + reader.addPragma("version", buildInteger("version", (version, state) -> state.setVersion(version))); } } 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 a17a70b..70f308b 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionState.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionState.java @@ -8,22 +8,22 @@ package bjc.utils.components; */ public class ComponentDescriptionState { // Tentative name of this component - private String name; + private String name; // Tentative description of this componet - private String description; + private String description; // Tentative author of this component - private String author; + private String author; // Tentative version of this component - private int version; + private int version; /** * Set the author of this component * * @param author - * The author of this component + * The author of this component */ public void setAuthor(String author) { this.author = author; @@ -33,7 +33,7 @@ public class ComponentDescriptionState { * Set the description of this component * * @param description - * The description of this component + * The description of this component */ public void setDescription(String description) { this.description = description; @@ -43,7 +43,7 @@ public class ComponentDescriptionState { * Set the name of this component * * @param name - * The name of this component + * The name of this component */ public void setName(String name) { this.name = name; @@ -53,7 +53,7 @@ public class ComponentDescriptionState { * Set the version of this component * * @param version - * The version of this component + * The version of this component */ public void setVersion(int version) { this.version = version; @@ -65,7 +65,6 @@ public class ComponentDescriptionState { * @return The description represented by this state */ public ComponentDescription toDescription() { - return new ComponentDescription(name, author, description, - version); + 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 e98c06b..7aa7c07 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java @@ -17,51 +17,45 @@ import bjc.utils.funcdata.IMap; import bjc.utils.funcutils.FileUtils; /** - * A component repository that loads its components from files in a - * directory + * A component repository that loads its components from files in a directory * * @author ben * * @param - * The type of component being read in + * The type of component being read in */ public class FileComponentRepository implements IComponentRepository { // The logger to use for storing data about this class - private static final Logger CLASS_LOGGER = Logger - .getLogger("FileComponentRepository"); + private static final Logger CLASS_LOGGER = Logger.getLogger("FileComponentRepository"); // The internal storage of components - private IMap components; + private IMap components; // The path that all the components came from - private Path sourceDirectory; + private Path sourceDirectory; /** - * Create a new component repository sourcing components from files in - * a directory + * 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. + * 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 + * The directory to read component files from * @param componentReader - * The function to use to convert files to components + * The function to use to convert files to components */ - public FileComponentRepository(File directory, - Function componentReader) { + public FileComponentRepository(File directory, Function componentReader) { // Make sure we have valid arguments if (directory == null) { throw new NullPointerException("Directory must not be null"); } else if (!directory.isDirectory()) { - throw new IllegalArgumentException("File " + directory - + " is not a directory.\n" + 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"); + throw new NullPointerException("Component reader must not be null"); } // Initialize our fields @@ -71,20 +65,21 @@ public class FileComponentRepository // Marker for making sure we don't skip the parent IHolder isFirstDir = new Identity<>(true); - // Predicate to use to traverse all the files in a directory, but + // Predicate to use to traverse all the files in a directory, + // but // not recurse into sub-directories - BiPredicate firstLevelTraverser = (pth, - attr) -> { + BiPredicate firstLevelTraverser = (pth, attr) -> { if (attr.isDirectory() && !isFirstDir.getValue()) { /* - * Skip directories, they probably have component support - * files. + * Skip directories, they probably have + * component support files. */ return false; } /* - * Don't skip the first directory, that's the parent directory + * Don't skip the first directory, that's the parent + * directory */ isFirstDir.replace(false); @@ -93,16 +88,15 @@ public class FileComponentRepository // Try reading components try { - FileUtils.traverseDirectory(sourceDirectory, - firstLevelTraverser, (pth, attr) -> { - loadComponent(componentReader, pth); + FileUtils.traverseDirectory(sourceDirectory, firstLevelTraverser, (pth, attr) -> { + loadComponent(componentReader, pth); - // Keep loading components, even if this one failed - return true; - }); + // Keep loading components, even if this one + // failed + return true; + }); } catch (IOException ioex) { - CLASS_LOGGER.log(Level.WARNING, ioex, - () -> "Error found reading component from file."); + CLASS_LOGGER.log(Level.WARNING, ioex, () -> "Error found reading component from file."); } } @@ -129,20 +123,17 @@ public class FileComponentRepository /* * Load a component from a file */ - private void loadComponent( - Function componentReader, - Path pth) { + private void loadComponent(Function componentReader, Path pth) { try { // Try to load the component ComponentType component = componentReader.apply(pth.toFile()); if (component == null) { - throw new NullPointerException( - "Component reader read null component"); + throw new NullPointerException("Component reader read null component"); } else if (!components.containsKey(component.getName())) { - // We only care about the latest version of a component - ComponentType oldComponent = components - .put(component.getName(), component); + // We only care about the latest version of a + // component + ComponentType oldComponent = components.put(component.getName(), component); if (oldComponent.getVersion() > component.getVersion()) { components.put(oldComponent.getName(), oldComponent); @@ -150,14 +141,12 @@ public class FileComponentRepository } else { CLASS_LOGGER.warning("Found a duplicate component.\n" + "Multiple versions of the same component are not currently supported.\n" - + "Only the latest version of the component" - + component + " will be registered ."); + + "Only the latest version of the component" + component + + " will be registered ."); } } catch (Exception ex) { - CLASS_LOGGER.log(Level.WARNING, ex, - () -> "Error found reading component from file " - + pth.toString() - + ". This component will not be loaded"); + CLASS_LOGGER.log(Level.WARNING, ex, () -> "Error found reading component from file " + + pth.toString() + ". This component will not be loaded"); } } } \ 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 a4dbfde..f3aab76 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java @@ -10,15 +10,14 @@ import bjc.utils.funcdata.IMap; * @author ben * * @param - * The type of components contained in this repository + * The type of components contained in this repository */ -public interface IComponentRepository< - ComponentType extends IDescribedComponent> { +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 + * @return A map from component name to component, containing all of the + * components in the repositories */ public IMap getAll(); @@ -26,7 +25,7 @@ public interface IComponentRepository< * Get a component with a specific name * * @param name - * The name of the component to retrieve + * The name of the component to retrieve * @return The named component, or null if no component with that name * exists */ 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 c3576a3..6b87ba7 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/IDescribedComponent.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/IDescribedComponent.java @@ -1,8 +1,8 @@ package bjc.utils.components; /** - * Represents a optional component that has status information associated - * with it + * Represents a optional component that has status information associated with + * it * * @author ben * -- cgit v1.2.3