summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/data
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-11-10 19:44:22 -0500
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-11-10 19:44:22 -0500
commitba9cf27de7e9f31dfa97a7266979f300101d67f9 (patch)
treedbf938e02d647e1be519808f8a14c6e954cab732 /BJC-Utils2/src/main/java/bjc/utils/data
parent5cf7bcf156970fe72f79e40b8a6e320ea160ac83 (diff)
Doc updates
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/data')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java31
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/BoundListHolder.java26
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Either.java61
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java21
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/package-info.java3
5 files changed, 112 insertions, 30 deletions
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 2b3fb29..c7eb965 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java
@@ -80,6 +80,10 @@ class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight>
@Override
public <BoundLeft> IPair<BoundLeft, NewRight> bindLeft(
Function<NewLeft, IPair<BoundLeft, NewRight>> leftBinder) {
+ if (leftBinder == null) {
+ throw new NullPointerException("Left binder must not be null");
+ }
+
Supplier<NewLeft> leftSupp = () -> {
IPair<NewLeft, NewRight> newPair = boundPair;
@@ -97,6 +101,11 @@ class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight>
@Override
public <BoundRight> IPair<NewLeft, BoundRight> bindRight(
Function<NewRight, IPair<NewLeft, BoundRight>> rightBinder) {
+ if (rightBinder == null) {
+ throw new NullPointerException(
+ "Right binder must not be null");
+ }
+
Supplier<NewRight> rightSupp = () -> {
IPair<NewLeft, NewRight> newPair = boundPair;
@@ -116,6 +125,16 @@ class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight>
IPair<OtherLeft, OtherRight> otherPair,
BiFunction<NewLeft, OtherLeft, CombinedLeft> leftCombiner,
BiFunction<NewRight, OtherRight, CombinedRight> rightCombiner) {
+ if (otherPair == null) {
+ throw new NullPointerException("Other pair must not be null");
+ } else if (leftCombiner == null) {
+ throw new NullPointerException(
+ "Left combiner must not be null");
+ } else if (rightCombiner == null) {
+ throw new NullPointerException(
+ "Right combiner must not be null");
+ }
+
return otherPair.bind((otherLeft, otherRight) -> {
return bind((leftVal, rightVal) -> {
return new LazyPair<>(
@@ -128,6 +147,10 @@ class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight>
@Override
public <NewLeftType> IPair<NewLeftType, NewRight> mapLeft(
Function<NewLeft, NewLeftType> mapper) {
+ if (mapper == null) {
+ throw new NullPointerException("Mapper must not be null");
+ }
+
Supplier<NewLeftType> leftSupp = () -> {
if (!pairBound) {
NewLeft leftVal = binder
@@ -156,6 +179,10 @@ class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight>
@Override
public <NewRightType> IPair<NewLeft, NewRightType> mapRight(
Function<NewRight, NewRightType> mapper) {
+ if (mapper == null) {
+ throw new NullPointerException("Mapper must not be null");
+ }
+
Supplier<NewLeft> leftSupp = () -> {
if (!pairBound) {
return binder
@@ -184,6 +211,10 @@ class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight>
@Override
public <MergedType> MergedType merge(
BiFunction<NewLeft, NewRight, MergedType> merger) {
+ if (merger == null) {
+ throw new NullPointerException("Merger must not be null");
+ }
+
if (!pairBound) {
boundPair = binder.apply(leftSupplier.get(),
rightSupplier.get());
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/BoundListHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/BoundListHolder.java
index fe47dcc..a967383 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/BoundListHolder.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/BoundListHolder.java
@@ -5,6 +5,9 @@ import java.util.function.UnaryOperator;
import bjc.utils.funcdata.IList;
+/*
+ * Holds a list, converted into a holder
+ */
class BoundListHolder<ContainedType> implements IHolder<ContainedType> {
private IList<IHolder<ContainedType>> heldHolders;
@@ -15,6 +18,10 @@ class BoundListHolder<ContainedType> implements IHolder<ContainedType> {
@Override
public <BoundType> IHolder<BoundType> bind(
Function<ContainedType, IHolder<BoundType>> binder) {
+ if (binder == null) {
+ throw new NullPointerException("Binder must not be null");
+ }
+
IList<IHolder<BoundType>> boundHolders = heldHolders
.map((containedHolder) -> {
return containedHolder.bind(binder);
@@ -26,6 +33,11 @@ class BoundListHolder<ContainedType> implements IHolder<ContainedType> {
@Override
public <NewType> Function<ContainedType, IHolder<NewType>> lift(
Function<ContainedType, NewType> func) {
+ if (func == null) {
+ throw new NullPointerException(
+ "Function to lift must not be null");
+ }
+
return (val) -> {
return new ListHolder<>(func.apply(val));
};
@@ -34,6 +46,10 @@ class BoundListHolder<ContainedType> implements IHolder<ContainedType> {
@Override
public <MappedType> IHolder<MappedType> map(
Function<ContainedType, MappedType> mapper) {
+ if (mapper == null) {
+ throw new NullPointerException("Mapper must not be null");
+ }
+
IList<IHolder<MappedType>> mappedHolders = heldHolders
.map((containedHolder) -> {
return containedHolder.map(mapper);
@@ -45,6 +61,10 @@ class BoundListHolder<ContainedType> implements IHolder<ContainedType> {
@Override
public IHolder<ContainedType> transform(
UnaryOperator<ContainedType> transformer) {
+ if (transformer == null) {
+ throw new NullPointerException("Transformer must not be null");
+ }
+
heldHolders.forEach((containedHolder) -> {
containedHolder.transform(transformer);
});
@@ -55,6 +75,10 @@ class BoundListHolder<ContainedType> implements IHolder<ContainedType> {
@Override
public <UnwrappedType> UnwrappedType unwrap(
Function<ContainedType, UnwrappedType> unwrapper) {
+ if (unwrapper == null) {
+ throw new NullPointerException("Unwrapper must not be null");
+ }
+
return heldHolders.randItem().unwrap(unwrapper);
}
-}
+} \ No newline at end of file
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Either.java b/BJC-Utils2/src/main/java/bjc/utils/data/Either.java
index aa38959..3ab4c00 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Either.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Either.java
@@ -26,9 +26,8 @@ public class Either<LeftType, RightType>
* The value to put on the left
* @return An either with the left side occupied
*/
- public static <LeftType,
- RightType> Either<LeftType, RightType> fromLeft(
- LeftType left) {
+ public static <LeftType, RightType> Either<LeftType, RightType> fromLeft(
+ LeftType left) {
return new Either<>(left, null);
}
@@ -43,9 +42,8 @@ public class Either<LeftType, RightType>
* The value to put on the right
* @return An either with the right side occupied
*/
- public static <LeftType,
- RightType> Either<LeftType, RightType> fromRight(
- RightType right) {
+ public static <LeftType, RightType> Either<LeftType, RightType> fromRight(
+ RightType right) {
return new Either<>(null, right);
}
@@ -55,7 +53,7 @@ public class Either<LeftType, RightType>
private boolean isLeft;
- private Either(LeftType left, RightType right) {
+ private Either( LeftType left, RightType right) {
if (left == null) {
rightVal = right;
} else {
@@ -67,14 +65,21 @@ public class Either<LeftType, RightType>
@Override
public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind(
- BiFunction<LeftType, RightType,
- IPair<BoundLeft, BoundRight>> binder) {
+ BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder) {
+ if (binder == null) {
+ throw new NullPointerException("Binder must not be null");
+ }
+
return binder.apply(leftVal, rightVal);
}
@Override
public <BoundLeft> IPair<BoundLeft, RightType> bindLeft(
Function<LeftType, IPair<BoundLeft, RightType>> leftBinder) {
+ if (leftBinder == null) {
+ throw new NullPointerException("Left binder must not be null");
+ }
+
if (isLeft) {
return leftBinder.apply(leftVal);
}
@@ -85,6 +90,11 @@ public class Either<LeftType, RightType>
@Override
public <BoundRight> IPair<LeftType, BoundRight> bindRight(
Function<RightType, IPair<LeftType, BoundRight>> rightBinder) {
+ if (rightBinder == null) {
+ throw new NullPointerException(
+ "Right binder must not be null");
+ }
+
if (isLeft) {
return new Either<>(leftVal, null);
}
@@ -93,13 +103,20 @@ public class Either<LeftType, RightType>
}
@Override
- public <OtherLeft, OtherRight, CombinedLeft,
- CombinedRight> IPair<CombinedLeft, CombinedRight> combine(
- IPair<OtherLeft, OtherRight> otherPair,
- BiFunction<LeftType, OtherLeft,
- CombinedLeft> leftCombiner,
- BiFunction<RightType, OtherRight,
- CombinedRight> rightCombiner) {
+ public <OtherLeft, OtherRight, CombinedLeft, CombinedRight> IPair<CombinedLeft, CombinedRight> combine(
+ IPair<OtherLeft, OtherRight> otherPair,
+ BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner,
+ BiFunction<RightType, OtherRight, CombinedRight> rightCombiner) {
+ if (otherPair == null) {
+ throw new NullPointerException("Other pair must not be null");
+ } else if (leftCombiner == null) {
+ throw new NullPointerException(
+ "Left combiner must not be null");
+ } else if (rightCombiner == null) {
+ throw new NullPointerException(
+ "Right combiner must not be null");
+ }
+
if (isLeft) {
return otherPair.bind((otherLeft, otherRight) -> {
return new Either<>(leftCombiner.apply(leftVal, otherLeft),
@@ -116,6 +133,10 @@ public class Either<LeftType, RightType>
@Override
public <NewLeft> IPair<NewLeft, RightType> mapLeft(
Function<LeftType, NewLeft> mapper) {
+ if (mapper == null) {
+ throw new NullPointerException("Mapper must not be null");
+ }
+
if (isLeft) {
return new Either<>(mapper.apply(leftVal), null);
}
@@ -126,6 +147,10 @@ public class Either<LeftType, RightType>
@Override
public <NewRight> IPair<LeftType, NewRight> mapRight(
Function<RightType, NewRight> mapper) {
+ if (mapper == null) {
+ throw new NullPointerException("Mapper must not be null");
+ }
+
if (isLeft) {
return new Either<>(leftVal, null);
}
@@ -136,6 +161,10 @@ public class Either<LeftType, RightType>
@Override
public <MergedType> MergedType merge(
BiFunction<LeftType, RightType, MergedType> merger) {
+ if (merger == null) {
+ throw new NullPointerException("Merger must not be null");
+ }
+
return merger.apply(leftVal, rightVal);
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java
index 72c0bdf..58c375b 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java
@@ -4,6 +4,9 @@ import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
+/*
+ * A lazy pair, with only one side bound
+ */
class HalfBoundLazyPair<OldType, NewLeft, NewRight>
implements IPair<NewLeft, NewRight> {
private Supplier<OldType> oldSupplier;
@@ -21,10 +24,9 @@ class HalfBoundLazyPair<OldType, 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) {
+ IHolder<IPair<NewLeft, NewRight>> newPair = new Identity<>(
+ boundPair);
IHolder<Boolean> newPairMade = new Identity<>(pairBound);
Supplier<NewLeft> leftSupp = () -> {
@@ -81,13 +83,10 @@ class HalfBoundLazyPair<OldType, 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 f5039bc..7b97a72 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,5 +4,4 @@
* @author ben
*
*/
-@org.eclipse.jdt.annotation.NonNullByDefault
-package bjc.utils.data; \ No newline at end of file
+package bjc.utils.data;