From 5cf7bcf156970fe72f79e40b8a6e320ea160ac83 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Fri, 21 Oct 2016 14:14:48 -0400 Subject: Documentation --- .../src/main/java/bjc/utils/data/BoundLazy.java | 32 ++++++++++--- .../main/java/bjc/utils/data/BoundLazyPair.java | 55 ++++++++++++++-------- .../src/main/java/bjc/utils/data/package-info.java | 1 + 3 files changed, 61 insertions(+), 27 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/data') 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 @@ -35,8 +35,7 @@ class BoundLazy /* * Transformations currently pending on the bound value */ - private IList> actions = new FunctionalList<>(); + private IList> actions = new FunctionalList<>(); /* * Create a new bound lazy value @@ -50,11 +49,14 @@ class BoundLazy @Override public IHolder bind( Function> bindr) { + if (bindr == null) { + throw new NullPointerException("Binder must not be null"); + } + /* * Prepare a list of pending actions */ - IList> pendingActions = new FunctionalList<>(); + IList> pendingActions = new FunctionalList<>(); actions.forEach(pendingActions::add); /* @@ -84,6 +86,11 @@ class BoundLazy @Override public Function> lift( Function 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 @Override public IHolder map( Function mapper) { + if (mapper == null) { + throw new NullPointerException("Mapper must not be null"); + } + // Prepare a list of pending actions - IList> pendingActions = new FunctionalList<>(); + IList> pendingActions = new FunctionalList<>(); actions.forEach(pendingActions::add); // Prepare the new supplier @@ -127,6 +137,10 @@ class BoundLazy @Override public IHolder transform( UnaryOperator transformer) { + if (transformer == null) { + throw new NullPointerException("Transformer must not be null"); + } + actions.add(transformer); return this; @@ -135,6 +149,10 @@ class BoundLazy @Override public UnwrappedType unwrap( Function 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 implements IPair { - private Supplier< - OldLeft> leftSupplier; - private Supplier< - OldRight> rightSupplier; - + /* + * The supplier of the left value + */ + private Supplier leftSupplier; + /* + * The supplier of the right value + */ + private Supplier rightSupplier; + + /* + * The binder to transform values + */ private BiFunction> binder; - private IPair boundPair; + /* + * The bound pair + */ + private IPair boundPair; + /* + * Whether the pair has been bound yet + */ private boolean pairBound; public BoundLazyPair(Supplier leftSupp, - Supplier rightSupp, BiFunction> bindr) { + Supplier rightSupp, + BiFunction> bindr) { leftSupplier = leftSupp; rightSupplier = rightSupp; binder = bindr; @@ -28,10 +43,13 @@ class BoundLazyPair @Override public IPair bind( - BiFunction> bindr) { - IHolder> newPair = new Identity<>(boundPair); + BiFunction> bindr) { + if (bindr == null) { + throw new NullPointerException("Binder must not be null"); + } + + IHolder> newPair = new Identity<>( + boundPair); IHolder newPairMade = new Identity<>(pairBound); Supplier leftSupp = () -> { @@ -94,13 +112,10 @@ class BoundLazyPair } @Override - public IPair combine( - IPair otherPair, - BiFunction leftCombiner, - BiFunction rightCombiner) { + public IPair combine( + IPair otherPair, + BiFunction leftCombiner, + BiFunction 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 -- cgit v1.2.3