summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/data/internals
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/internals')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazy.java38
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazyPair.java66
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundListHolder.java26
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java38
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedLazy.java6
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedOption.java22
6 files changed, 69 insertions, 127 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazy.java b/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazy.java
index 57bf006..0ec69f0 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazy.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazy.java
@@ -1,14 +1,14 @@
package bjc.utils.data.internals;
-import java.util.function.Function;
-import java.util.function.Supplier;
-import java.util.function.UnaryOperator;
-
import bjc.utils.data.IHolder;
import bjc.utils.data.Lazy;
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.IList;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import java.util.function.UnaryOperator;
+
/**
* Implements a lazy holder that has been bound
*/
@@ -48,9 +48,7 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
@Override
public <BoundType> IHolder<BoundType> bind(Function<BoundContainedType, IHolder<BoundType>> bindr) {
- if (bindr == null) {
- throw new NullPointerException("Binder must not be null");
- }
+ if(bindr == null) throw new NullPointerException("Binder must not be null");
/*
* Prepare a list of pending actions
@@ -67,7 +65,7 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
/*
* Bind the value if it hasn't been bound before
*/
- if (!holderBound) {
+ if(!holderBound) {
oldHolder = oldSupplier.get().unwrap(binder);
}
@@ -85,9 +83,7 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
@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");
- }
+ if(func == null) throw new NullPointerException("Function to lift must not be null");
return (val) -> {
return new Lazy<>(func.apply(val));
@@ -96,9 +92,7 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
@Override
public <MappedType> IHolder<MappedType> map(Function<BoundContainedType, MappedType> mapper) {
- if (mapper == null) {
- throw new NullPointerException("Mapper must not be null");
- }
+ if(mapper == null) throw new NullPointerException("Mapper must not be null");
// Prepare a list of pending actions
IList<UnaryOperator<BoundContainedType>> pendingActions = new FunctionalList<>();
@@ -109,7 +103,7 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
IHolder<BoundContainedType> oldHolder = boundHolder;
// Bound the value if it hasn't been bound
- if (!holderBound) {
+ if(!holderBound) {
oldHolder = oldSupplier.get().unwrap(binder);
}
@@ -123,18 +117,14 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
@Override
public String toString() {
- if (holderBound) {
- return boundHolder.toString();
- }
+ if(holderBound) return boundHolder.toString();
return "(unmaterialized)";
}
@Override
public IHolder<BoundContainedType> transform(UnaryOperator<BoundContainedType> transformer) {
- if (transformer == null) {
- throw new NullPointerException("Transformer must not be null");
- }
+ if(transformer == null) throw new NullPointerException("Transformer must not be null");
actions.add(transformer);
@@ -143,11 +133,9 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
@Override
public <UnwrappedType> UnwrappedType unwrap(Function<BoundContainedType, UnwrappedType> unwrapper) {
- if (unwrapper == null) {
- throw new NullPointerException("Unwrapper must not be null");
- }
+ if(unwrapper == null) throw new NullPointerException("Unwrapper must not be null");
- if (!holderBound) {
+ if(!holderBound) {
boundHolder = oldSupplier.get().unwrap(binder::apply);
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazyPair.java
index d425d99..6ab8121 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazyPair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazyPair.java
@@ -1,14 +1,14 @@
package bjc.utils.data.internals;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import java.util.function.Supplier;
-
import bjc.utils.data.IHolder;
import bjc.utils.data.IPair;
import bjc.utils.data.Identity;
import bjc.utils.data.LazyPair;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import java.util.function.Supplier;
+
/**
* Implements a lazy pair that has been bound
*/
@@ -47,15 +47,13 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
@Override
public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind(
BiFunction<NewLeft, NewRight, IPair<BoundLeft, BoundRight>> bindr) {
- if (bindr == null) {
- throw new NullPointerException("Binder must not be null");
- }
+ 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 = () -> {
- if (!newPairMade.getValue()) {
+ if(!newPairMade.getValue()) {
newPair.replace(binder.apply(leftSupplier.get(), rightSupplier.get()));
newPairMade.replace(true);
@@ -65,7 +63,7 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
};
Supplier<NewRight> rightSupp = () -> {
- if (!newPairMade.getValue()) {
+ if(!newPairMade.getValue()) {
newPair.replace(binder.apply(leftSupplier.get(), rightSupplier.get()));
newPairMade.replace(true);
@@ -80,14 +78,12 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
@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");
- }
+ if(leftBinder == null) throw new NullPointerException("Left binder must not be null");
Supplier<NewLeft> leftSupp = () -> {
IPair<NewLeft, NewRight> newPair = boundPair;
- if (!pairBound) {
+ if(!pairBound) {
newPair = binder.apply(leftSupplier.get(), rightSupplier.get());
}
@@ -100,14 +96,12 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
@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");
- }
+ if(rightBinder == null) throw new NullPointerException("Right binder must not be null");
Supplier<NewRight> rightSupp = () -> {
IPair<NewLeft, NewRight> newPair = boundPair;
- if (!pairBound) {
+ if(!pairBound) {
newPair = binder.apply(leftSupplier.get(), rightSupplier.get());
}
@@ -122,13 +116,11 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
IPair<OtherLeft, OtherRight> otherPair,
BiFunction<NewLeft, OtherLeft, CombinedLeft> leftCombiner,
BiFunction<NewRight, OtherRight, CombinedRight> rightCombiner) {
- if (otherPair == null) {
+ if(otherPair == null)
throw new NullPointerException("Other pair must not be null");
- } else if (leftCombiner == 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");
- }
+ else if(rightCombiner == null) throw new NullPointerException("Right combiner must not be null");
return otherPair.bind((otherLeft, otherRight) -> {
return bind((leftVal, rightVal) -> {
@@ -140,12 +132,10 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
@Override
public <NewLeftType> IPair<NewLeftType, NewRight> mapLeft(Function<NewLeft, NewLeftType> mapper) {
- if (mapper == null) {
- throw new NullPointerException("Mapper must not be null");
- }
+ if(mapper == null) throw new NullPointerException("Mapper must not be null");
Supplier<NewLeftType> leftSupp = () -> {
- if (!pairBound) {
+ if(!pairBound) {
NewLeft leftVal = binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft();
return mapper.apply(leftVal);
@@ -155,9 +145,7 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
};
Supplier<NewRight> rightSupp = () -> {
- if (!pairBound) {
- return binder.apply(leftSupplier.get(), rightSupplier.get()).getRight();
- }
+ if(!pairBound) return binder.apply(leftSupplier.get(), rightSupplier.get()).getRight();
return boundPair.getRight();
};
@@ -167,20 +155,16 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
@Override
public <NewRightType> IPair<NewLeft, NewRightType> mapRight(Function<NewRight, NewRightType> mapper) {
- if (mapper == null) {
- throw new NullPointerException("Mapper must not be null");
- }
+ if(mapper == null) throw new NullPointerException("Mapper must not be null");
Supplier<NewLeft> leftSupp = () -> {
- if (!pairBound) {
- return binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft();
- }
+ if(!pairBound) return binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft();
return boundPair.getLeft();
};
Supplier<NewRightType> rightSupp = () -> {
- if (!pairBound) {
+ if(!pairBound) {
NewRight rightVal = binder.apply(leftSupplier.get(), rightSupplier.get()).getRight();
return mapper.apply(rightVal);
@@ -194,11 +178,9 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
@Override
public <MergedType> MergedType merge(BiFunction<NewLeft, NewRight, MergedType> merger) {
- if (merger == null) {
- throw new NullPointerException("Merger must not be null");
- }
+ if(merger == null) throw new NullPointerException("Merger must not be null");
- if (!pairBound) {
+ if(!pairBound) {
boundPair = binder.apply(leftSupplier.get(), rightSupplier.get());
pairBound = true;
@@ -209,9 +191,7 @@ public class BoundLazyPair<OldLeft, OldRight, NewLeft, NewRight> implements IPai
@Override
public String toString() {
- if (pairBound) {
- return boundPair.toString();
- }
+ if(pairBound) return boundPair.toString();
return "(un-materialized)";
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundListHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundListHolder.java
index f363b7e..467d55d 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundListHolder.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundListHolder.java
@@ -1,12 +1,12 @@
package bjc.utils.data.internals;
-import java.util.function.Function;
-import java.util.function.UnaryOperator;
-
import bjc.utils.data.IHolder;
import bjc.utils.data.ListHolder;
import bjc.utils.funcdata.IList;
+import java.util.function.Function;
+import java.util.function.UnaryOperator;
+
/*
* Holds a list, converted into a holder
*/
@@ -19,9 +19,7 @@ public 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");
- }
+ if(binder == null) throw new NullPointerException("Binder must not be null");
IList<IHolder<BoundType>> boundHolders = heldHolders.map((containedHolder) -> {
return containedHolder.bind(binder);
@@ -32,9 +30,7 @@ public 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");
- }
+ if(func == null) throw new NullPointerException("Function to lift must not be null");
return (val) -> {
return new ListHolder<>(func.apply(val));
@@ -43,9 +39,7 @@ public 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");
- }
+ if(mapper == null) throw new NullPointerException("Mapper must not be null");
IList<IHolder<MappedType>> mappedHolders = heldHolders.map((containedHolder) -> {
return containedHolder.map(mapper);
@@ -56,9 +50,7 @@ public 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");
- }
+ if(transformer == null) throw new NullPointerException("Transformer must not be null");
heldHolders.forEach((containedHolder) -> {
containedHolder.transform(transformer);
@@ -69,9 +61,7 @@ public 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");
- }
+ if(unwrapper == null) throw new NullPointerException("Unwrapper must not be null");
return heldHolders.randItem().unwrap(unwrapper);
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java
index a8bdb6a..c5e9c9f 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java
@@ -1,14 +1,14 @@
package bjc.utils.data.internals;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import java.util.function.Supplier;
-
import bjc.utils.data.IHolder;
import bjc.utils.data.IPair;
import bjc.utils.data.Identity;
import bjc.utils.data.LazyPair;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import java.util.function.Supplier;
+
/*
* A lazy pair, with only one side bound
*/
@@ -17,8 +17,8 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
private Function<OldType, IPair<NewLeft, NewRight>> binder;
- private IPair<NewLeft, NewRight> boundPair;
- private boolean pairBound;
+ private IPair<NewLeft, NewRight> boundPair;
+ private boolean pairBound;
public HalfBoundLazyPair(Supplier<OldType> oldSupp, Function<OldType, IPair<NewLeft, NewRight>> bindr) {
oldSupplier = oldSupp;
@@ -32,7 +32,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
IHolder<Boolean> newPairMade = new Identity<>(pairBound);
Supplier<NewLeft> leftSupp = () -> {
- if (!newPairMade.getValue()) {
+ if(!newPairMade.getValue()) {
newPair.replace(binder.apply(oldSupplier.get()));
newPairMade.replace(true);
}
@@ -41,7 +41,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
};
Supplier<NewRight> rightSupp = () -> {
- if (!newPairMade.getValue()) {
+ if(!newPairMade.getValue()) {
newPair.replace(binder.apply(oldSupplier.get()));
newPairMade.replace(true);
}
@@ -58,7 +58,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
Supplier<NewLeft> leftSupp = () -> {
IPair<NewLeft, NewRight> newPair = boundPair;
- if (!pairBound) {
+ if(!pairBound) {
newPair = binder.apply(oldSupplier.get());
}
@@ -74,7 +74,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
Supplier<NewRight> rightSupp = () -> {
IPair<NewLeft, NewRight> newPair = boundPair;
- if (!pairBound) {
+ if(!pairBound) {
newPair = binder.apply(oldSupplier.get());
}
@@ -100,9 +100,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
@Override
public <NewLeftType> IPair<NewLeftType, NewRight> mapLeft(Function<NewLeft, NewLeftType> mapper) {
Supplier<NewLeftType> leftSupp = () -> {
- if (pairBound) {
- return mapper.apply(boundPair.getLeft());
- }
+ if(pairBound) return mapper.apply(boundPair.getLeft());
NewLeft leftVal = binder.apply(oldSupplier.get()).getLeft();
@@ -110,9 +108,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
};
Supplier<NewRight> rightSupp = () -> {
- if (pairBound) {
- return boundPair.getRight();
- }
+ if(pairBound) return boundPair.getRight();
return binder.apply(oldSupplier.get()).getRight();
};
@@ -123,17 +119,13 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
@Override
public <NewRightType> IPair<NewLeft, NewRightType> mapRight(Function<NewRight, NewRightType> mapper) {
Supplier<NewLeft> leftSupp = () -> {
- if (pairBound) {
- return boundPair.getLeft();
- }
+ if(pairBound) return boundPair.getLeft();
return binder.apply(oldSupplier.get()).getLeft();
};
Supplier<NewRightType> rightSupp = () -> {
- if (pairBound) {
- return mapper.apply(boundPair.getRight());
- }
+ if(pairBound) return mapper.apply(boundPair.getRight());
NewRight rightVal = binder.apply(oldSupplier.get()).getRight();
@@ -145,7 +137,7 @@ public class HalfBoundLazyPair<OldType, NewLeft, NewRight> implements IPair<NewL
@Override
public <MergedType> MergedType merge(BiFunction<NewLeft, NewRight, MergedType> merger) {
- if (!pairBound) {
+ if(!pairBound) {
boundPair = binder.apply(oldSupplier.get());
pairBound = true;
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedLazy.java b/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedLazy.java
index 7f0b8db..f400345 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedLazy.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedLazy.java
@@ -1,11 +1,11 @@
package bjc.utils.data.internals;
-import java.util.function.Function;
-import java.util.function.UnaryOperator;
-
import bjc.utils.data.IHolder;
import bjc.utils.data.Lazy;
+import java.util.function.Function;
+import java.util.function.UnaryOperator;
+
public class WrappedLazy<ContainedType> implements IHolder<ContainedType> {
private IHolder<IHolder<ContainedType>> held;
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedOption.java b/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedOption.java
index 2b03f62..1639351 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedOption.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedOption.java
@@ -1,11 +1,11 @@
package bjc.utils.data.internals;
-import java.util.function.Function;
-import java.util.function.UnaryOperator;
-
import bjc.utils.data.IHolder;
import bjc.utils.data.Option;
+import java.util.function.Function;
+import java.util.function.UnaryOperator;
+
public class WrappedOption<ContainedType> implements IHolder<ContainedType> {
private IHolder<IHolder<ContainedType>> held;
@@ -21,9 +21,7 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> {
public <BoundType> IHolder<BoundType> bind(Function<ContainedType, IHolder<BoundType>> binder) {
IHolder<IHolder<BoundType>> newHolder = held.map((containedHolder) -> {
return containedHolder.bind((containedValue) -> {
- if (containedValue == null) {
- return new Option<>(null);
- }
+ if(containedValue == null) return new Option<>(null);
return binder.apply(containedValue);
});
@@ -43,9 +41,7 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> {
public <MappedType> IHolder<MappedType> map(Function<ContainedType, MappedType> mapper) {
IHolder<IHolder<MappedType>> newHolder = held.map((containedHolder) -> {
return containedHolder.map((containedValue) -> {
- if (containedValue == null) {
- return null;
- }
+ if(containedValue == null) return null;
return mapper.apply(containedValue);
});
@@ -58,9 +54,7 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> {
public IHolder<ContainedType> transform(UnaryOperator<ContainedType> transformer) {
held.transform((containedHolder) -> {
return containedHolder.transform((containedValue) -> {
- if (containedValue == null) {
- return null;
- }
+ if(containedValue == null) return null;
return transformer.apply(containedValue);
});
@@ -73,9 +67,7 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> {
public <UnwrappedType> UnwrappedType unwrap(Function<ContainedType, UnwrappedType> unwrapper) {
return held.unwrap((containedHolder) -> {
return containedHolder.unwrap((containedValue) -> {
- if (containedValue == null) {
- return null;
- }
+ if(containedValue == null) return null;
return unwrapper.apply(containedValue);
});