summaryrefslogtreecommitdiff
path: root/BJC-Utils2
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-10-21 14:14:48 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-10-21 14:14:48 -0400
commit5cf7bcf156970fe72f79e40b8a6e320ea160ac83 (patch)
tree52bba3b684c493c726538194b5965150abb4a786 /BJC-Utils2
parentb0516949d7577b809c75d7267df77bff2cdb078b (diff)
Documentation
Diffstat (limited to 'BJC-Utils2')
-rw-r--r--BJC-Utils2/.classpath1
-rw-r--r--BJC-Utils2/org.eclipse.jdt.annotation_2.1.0.v20160418-1457.jarbin0 -> 25854 bytes
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java17
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java16
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/GenericHelp.java4
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHandler.java1
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/NullHelp.java20
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/package-info.java3
-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
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/BoundLazy.java32
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java55
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/package-info.java1
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java15
16 files changed, 156 insertions, 71 deletions
diff --git a/BJC-Utils2/.classpath b/BJC-Utils2/.classpath
index 17c9f20..fcd665e 100644
--- a/BJC-Utils2/.classpath
+++ b/BJC-Utils2/.classpath
@@ -23,5 +23,6 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
+ <classpathentry kind="lib" path="org.eclipse.jdt.annotation_2.1.0.v20160418-1457.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
diff --git a/BJC-Utils2/org.eclipse.jdt.annotation_2.1.0.v20160418-1457.jar b/BJC-Utils2/org.eclipse.jdt.annotation_2.1.0.v20160418-1457.jar
new file mode 100644
index 0000000..f74f131
--- /dev/null
+++ b/BJC-Utils2/org.eclipse.jdt.annotation_2.1.0.v20160418-1457.jar
Binary files differ
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java
index e73d936..54d2fa0 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java
@@ -1,5 +1,7 @@
package bjc.utils.cli;
+import org.eclipse.jdt.annotation.Nullable;
+
/**
* Generic command implementation
*
@@ -18,19 +20,24 @@ public class GenericCommand implements ICommand {
* @param handler
* The handler to use for the command
* @param description
- * The description of the command
+ * The description of the command. May be null
* @param help
- * The detailed help message for the command
+ * The detailed help message for the command. May be null
*/
- public GenericCommand(ICommandHandler handler, String description,
- String help) {
+ public GenericCommand(ICommandHandler handler, @Nullable String description,
+ @Nullable String help) {
if (handler == null) {
throw new NullPointerException(
"Command handler must not be null");
}
this.handler = handler;
- this.help = new GenericHelp(description, help);
+
+ if (description == null) {
+ this.help = new NullHelp();
+ } else {
+ this.help = new GenericHelp(description, help);
+ }
}
@Override
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java
index 4b3b4fd..4aab8a4 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java
@@ -7,6 +7,8 @@ import java.util.function.Consumer;
import bjc.utils.funcdata.FunctionalMap;
import bjc.utils.funcdata.IMap;
+import org.eclipse.jdt.annotation.Nullable;
+
/**
* A general command mode, with a customizable set of commands
*
@@ -50,6 +52,14 @@ public class GenericCommandMode implements ICommandMode {
*/
public GenericCommandMode(Consumer<String> normalOutput,
Consumer<String> errorOutput) {
+ if (normalOutput == null) {
+ throw new NullPointerException(
+ "Normal output source must be non-null");
+ } else if (errorOutput == null) {
+ throw new NullPointerException(
+ "Error output source must be non-null");
+ }
+
this.normalOutput = normalOutput;
this.errorOutput = errorOutput;
@@ -371,7 +381,7 @@ public class GenericCommandMode implements ICommandMode {
* The custom prompt for this mode, or null to disable the
* custom prompt
*/
- public void setCustomPrompt(String prompt) {
+ public void setCustomPrompt(@Nullable String prompt) {
customPrompt = prompt;
}
@@ -382,7 +392,7 @@ public class GenericCommandMode implements ICommandMode {
* The desired name of this mode, or null to use the default
* name
*/
- public void setModeName(String name) {
+ public void setModeName(@Nullable String name) {
modeName = name;
}
@@ -394,7 +404,7 @@ public class GenericCommandMode implements ICommandMode {
* on unknown commands
*/
public void setUnknownCommandHandler(
- BiConsumer<String, String[]> handler) {
+ @Nullable BiConsumer<String, String[]> handler) {
if (handler == null) {
throw new NullPointerException("Handler must not be null");
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericHelp.java b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericHelp.java
index 8742b5d..2e46202 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericHelp.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericHelp.java
@@ -1,5 +1,7 @@
package bjc.utils.cli;
+import org.eclipse.jdt.annotation.Nullable;
+
/**
* Generic implementation of a help topic
*
@@ -20,7 +22,7 @@ public class GenericHelp implements ICommandHelp {
* The description of this help topic, or null if this help
* topic doesn't have a more detailed description
*/
- public GenericHelp(String summary, String description) {
+ public GenericHelp(String summary, @Nullable String description) {
if (summary == null) {
throw new NullPointerException(
"Help summary must be non-null");
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHandler.java b/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHandler.java
index 3d451a7..33182b3 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHandler.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHandler.java
@@ -8,6 +8,7 @@ import java.util.function.Function;
* @author ben
*
*/
+@FunctionalInterface
public interface ICommandHandler extends Function<String[], ICommandMode> {
/**
* Execute this command
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/NullHelp.java b/BJC-Utils2/src/main/java/bjc/utils/cli/NullHelp.java
new file mode 100644
index 0000000..e150ba6
--- /dev/null
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/NullHelp.java
@@ -0,0 +1,20 @@
+package bjc.utils.cli;
+
+/**
+ * Implementation of a help topic that doesn't exist
+ *
+ * @author ben
+ *
+ */
+public class NullHelp implements ICommandHelp {
+
+ @Override
+ public String getDescription() {
+ return "No description provided";
+ }
+
+ @Override
+ public String getSummary() {
+ return "No summary provided";
+ }
+} \ No newline at end of file
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/package-info.java b/BJC-Utils2/src/main/java/bjc/utils/cli/package-info.java
index a87aa24..1bdfd14 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/package-info.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/package-info.java
@@ -4,4 +4,5 @@
* @author ben
*
*/
-package bjc.utils.cli; \ No newline at end of file
+@org.eclipse.jdt.annotation.NonNullByDefault
+package bjc.utils.cli;
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
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazy.java b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazy.java
index d6f3b1d..b2ae7ce 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazy.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazy.java
@@ -7,7 +7,7 @@ import java.util.function.UnaryOperator;
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.IList;
-/*
+/**
* Implements a lazy holder that has been bound
*/
class BoundLazy<OldType, BoundContainedType>
@@ -35,8 +35,7 @@ class BoundLazy<OldType, BoundContainedType>
/*
* Transformations currently pending on the bound value
*/
- private IList<UnaryOperator<
- BoundContainedType>> actions = new FunctionalList<>();
+ private IList<UnaryOperator<BoundContainedType>> actions = new FunctionalList<>();
/*
* Create a new bound lazy value
@@ -50,11 +49,14 @@ class BoundLazy<OldType, BoundContainedType>
@Override
public <BoundType> IHolder<BoundType> bind(
Function<BoundContainedType, IHolder<BoundType>> bindr) {
+ if (bindr == null) {
+ throw new NullPointerException("Binder must not be null");
+ }
+
/*
* Prepare a list of pending actions
*/
- IList<UnaryOperator<
- BoundContainedType>> pendingActions = new FunctionalList<>();
+ IList<UnaryOperator<BoundContainedType>> pendingActions = new FunctionalList<>();
actions.forEach(pendingActions::add);
/*
@@ -84,6 +86,11 @@ class BoundLazy<OldType, BoundContainedType>
@Override
public <NewType> Function<BoundContainedType, IHolder<NewType>> lift(
Function<BoundContainedType, NewType> func) {
+ if (func == null) {
+ throw new NullPointerException(
+ "Function to lift must not be null");
+ }
+
return (val) -> {
return new Lazy<>(func.apply(val));
};
@@ -92,9 +99,12 @@ class BoundLazy<OldType, BoundContainedType>
@Override
public <MappedType> IHolder<MappedType> map(
Function<BoundContainedType, MappedType> mapper) {
+ if (mapper == null) {
+ throw new NullPointerException("Mapper must not be null");
+ }
+
// Prepare a list of pending actions
- IList<UnaryOperator<
- BoundContainedType>> pendingActions = new FunctionalList<>();
+ IList<UnaryOperator<BoundContainedType>> pendingActions = new FunctionalList<>();
actions.forEach(pendingActions::add);
// Prepare the new supplier
@@ -127,6 +137,10 @@ class BoundLazy<OldType, BoundContainedType>
@Override
public IHolder<BoundContainedType> transform(
UnaryOperator<BoundContainedType> transformer) {
+ if (transformer == null) {
+ throw new NullPointerException("Transformer must not be null");
+ }
+
actions.add(transformer);
return this;
@@ -135,6 +149,10 @@ class BoundLazy<OldType, BoundContainedType>
@Override
public <UnwrappedType> UnwrappedType unwrap(
Function<BoundContainedType, UnwrappedType> unwrapper) {
+ if (unwrapper == null) {
+ throw new NullPointerException("Unwrapper must not be null");
+ }
+
if (!holderBound) {
boundHolder = oldSupplier.get().unwrap(binder::apply);
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java
index 622bd2e..2b3fb29 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java
@@ -4,23 +4,38 @@ import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
+/**
+ * Implements a lazy pair that has been bound
+ */
class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight>
implements IPair<NewLeft, NewRight> {
- private Supplier<
- OldLeft> leftSupplier;
- private Supplier<
- OldRight> rightSupplier;
-
+ /*
+ * The supplier of the left value
+ */
+ private Supplier<OldLeft> leftSupplier;
+ /*
+ * The supplier of the right value
+ */
+ private Supplier<OldRight> rightSupplier;
+
+ /*
+ * The binder to transform values
+ */
private BiFunction<OldLeft, OldRight, IPair<NewLeft, NewRight>> binder;
- private IPair<NewLeft,
- NewRight> boundPair;
+ /*
+ * The bound pair
+ */
+ private IPair<NewLeft, NewRight> boundPair;
+ /*
+ * Whether the pair has been bound yet
+ */
private boolean pairBound;
public BoundLazyPair(Supplier<OldLeft> leftSupp,
- Supplier<OldRight> rightSupp, BiFunction<OldLeft, OldRight,
- IPair<NewLeft, NewRight>> bindr) {
+ Supplier<OldRight> rightSupp,
+ BiFunction<OldLeft, OldRight, IPair<NewLeft, NewRight>> bindr) {
leftSupplier = leftSupp;
rightSupplier = rightSupp;
binder = bindr;
@@ -28,10 +43,13 @@ class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight>
@Override
public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind(
- BiFunction<NewLeft, NewRight,
- IPair<BoundLeft, BoundRight>> bindr) {
- IHolder<IPair<NewLeft,
- NewRight>> newPair = new Identity<>(boundPair);
+ BiFunction<NewLeft, NewRight, IPair<BoundLeft, BoundRight>> bindr) {
+ if (bindr == null) {
+ throw new NullPointerException("Binder must not be null");
+ }
+
+ IHolder<IPair<NewLeft, NewRight>> newPair = new Identity<>(
+ boundPair);
IHolder<Boolean> newPairMade = new Identity<>(pairBound);
Supplier<NewLeft> leftSupp = () -> {
@@ -94,13 +112,10 @@ class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight>
}
@Override
- public <OtherLeft, OtherRight, CombinedLeft,
- CombinedRight> IPair<CombinedLeft, CombinedRight> combine(
- IPair<OtherLeft, OtherRight> otherPair,
- BiFunction<NewLeft, OtherLeft,
- CombinedLeft> leftCombiner,
- BiFunction<NewRight, OtherRight,
- CombinedRight> rightCombiner) {
+ public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine(
+ IPair<OtherLeft, OtherRight> otherPair,
+ BiFunction<NewLeft, OtherLeft, CombinedLeft> leftCombiner,
+ BiFunction<NewRight, OtherRight, CombinedRight> rightCombiner) {
return otherPair.bind((otherLeft, otherRight) -> {
return bind((leftVal, rightVal) -> {
return new LazyPair<>(
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/package-info.java b/BJC-Utils2/src/main/java/bjc/utils/data/package-info.java
index a6f05dd..f5039bc 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/package-info.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/package-info.java
@@ -4,4 +4,5 @@
* @author ben
*
*/
+@org.eclipse.jdt.annotation.NonNullByDefault
package bjc.utils.data; \ No newline at end of file
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java
index 47acf1a..014c298 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java
@@ -28,6 +28,10 @@ public interface IList<ContainedType> {
*/
boolean add(ContainedType item);
+ default boolean addAll(IList<ContainedType> items) {
+ return items.map(this::add).anyMatch((bl) -> bl == false);
+ }
+
/**
* Check if all of the elements of this list match the specified
* predicate.
@@ -62,8 +66,8 @@ public interface IList<ContainedType> {
*/
public default <StateType, ReducedType> ReducedType collect(
Collector<ContainedType, StateType, ReducedType> collector) {
- BiConsumer<StateType,
- ContainedType> accumulator = collector.accumulator();
+ BiConsumer<StateType, ContainedType> accumulator = collector
+ .accumulator();
return reduceAux(collector.supplier().get(), (value, state) -> {
accumulator.accept(state, value);
@@ -92,8 +96,8 @@ public interface IList<ContainedType> {
* @return A new list containing the merged pairs of lists.
*/
<OtherType, CombinedType> IList<CombinedType> combineWith(
- IList<OtherType> rightList, BiFunction<ContainedType,
- OtherType, CombinedType> itemCombiner);
+ IList<OtherType> rightList,
+ BiFunction<ContainedType, OtherType, CombinedType> itemCombiner);
/**
* Check if the list contains the specified item
@@ -261,8 +265,7 @@ public interface IList<ContainedType> {
* its final state.
*/
<StateType, ReducedType> ReducedType reduceAux(StateType initialValue,
- BiFunction<ContainedType, StateType,
- StateType> stateAccumulator,
+ BiFunction<ContainedType, StateType, StateType> stateAccumulator,
Function<StateType, ReducedType> resultTransformer);
/**