From 504ca816530efdff06bc202e0432ebd354aec304 Mon Sep 17 00:00:00 2001 From: EVE Date: Tue, 14 Mar 2017 12:07:14 -0400 Subject: Cleanup --- .../utils/components/FileComponentRepository.java | 51 +++++++++++----------- 1 file changed, 25 insertions(+), 26 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java') 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"); } -- cgit v1.2.3