diff options
| author | EVE <EVE@EVE-PC> | 2017-03-14 12:07:14 -0400 |
|---|---|---|
| committer | EVE <EVE@EVE-PC> | 2017-03-14 12:07:14 -0400 |
| commit | 504ca816530efdff06bc202e0432ebd354aec304 (patch) | |
| tree | 4836932fb81d1d625470502c78c94d202c9a7420 /BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java | |
| parent | 5c1163df17c46f7d3e15b6c7949c38843ec56146 (diff) | |
Cleanup
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java | 51 |
1 files changed, 25 insertions, 26 deletions
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 <ComponentType> @@ -38,10 +38,10 @@ public class FileComponentRepository<ComponentType extends IDescribedComponent> /** * 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<ComponentType extends IDescribedComponent> */ public FileComponentRepository(File directory, Function<File, ? extends ComponentType> 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<ComponentType extends IDescribedComponent> // but // not recurse into sub-directories BiPredicate<Path, BasicFileAttributes> 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<ComponentType extends IDescribedComponent> // 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<ComponentType extends IDescribedComponent> // 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<ComponentType extends IDescribedComponent> + "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"); } |
