summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/components
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/components')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java14
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java4
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java43
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/components/package-info.java1
4 files changed, 34 insertions, 28 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 ab48c9b..1ec5b80 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java
@@ -11,12 +11,6 @@ public class ComponentDescription implements IDescribedComponent {
String description, int version) {
if (name == null) {
throw new NullPointerException("Component name can't be null");
- } else if (author == null) {
- throw new NullPointerException(
- "Component author can't be null");
- } else if (description == null) {
- throw new NullPointerException(
- "Component description can't be null");
} else if (version <= 0) {
throw new IllegalArgumentException(
"Component version must be greater than 0");
@@ -67,11 +61,19 @@ public class ComponentDescription implements IDescribedComponent {
@Override
public String getAuthor() {
+ if(author == null) {
+ return IDescribedComponent.super.getAuthor();
+ }
+
return author;
}
@Override
public String 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 ef8f8b6..ad5e1a2 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java
@@ -41,6 +41,10 @@ public class ComponentDescriptionFileParser {
*/
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());
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 6c1bb71..e98c06b 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java
@@ -25,8 +25,7 @@ import bjc.utils.funcutils.FileUtils;
* @param <ComponentType>
* The type of component being read in
*/
-public class FileComponentRepository<
- ComponentType extends IDescribedComponent>
+public class FileComponentRepository<ComponentType extends IDescribedComponent>
implements IComponentRepository<ComponentType> {
// The logger to use for storing data about this class
private static final Logger CLASS_LOGGER = Logger
@@ -54,7 +53,9 @@ public class FileComponentRepository<
public FileComponentRepository(File directory,
Function<File, ? extends ComponentType> componentReader) {
// Make sure we have valid arguments
- if (!directory.isDirectory()) {
+ 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"
+ "Components can only be read from a directory");
@@ -72,25 +73,23 @@ public class FileComponentRepository<
// Predicate to use to traverse all the files in a directory, 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.
- */
- return false;
- }
-
- /*
- * Don't skip the first directory, that's the parent
- * directory
- */
- isFirstDir.replace(false);
-
- return true;
- };
+ BiPredicate<Path, BasicFileAttributes> firstLevelTraverser = (pth,
+ attr) -> {
+ 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 directory
+ */
+ isFirstDir.replace(false);
+
+ return true;
+ };
// Try reading components
try {
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 5ed7777..14a852a 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
@@ -4,4 +4,5 @@
* @author ben
*
*/
+@org.eclipse.jdt.annotation.NonNullByDefault
package bjc.utils.components; \ No newline at end of file