diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-10-21 14:14:48 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-10-21 14:14:48 -0400 |
| commit | 5cf7bcf156970fe72f79e40b8a6e320ea160ac83 (patch) | |
| tree | 52bba3b684c493c726538194b5965150abb4a786 /BJC-Utils2/src/main/java/bjc/utils/data | |
| parent | b0516949d7577b809c75d7267df77bff2cdb078b (diff) | |
Documentation
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/data')
3 files changed, 61 insertions, 27 deletions
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 |
