summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java
diff options
context:
space:
mode:
authorbjculkin <bjculkin@WIT-136XG42.wvu-ad.wvu.edu>2017-02-27 10:11:43 -0500
committerbjculkin <bjculkin@WIT-136XG42.wvu-ad.wvu.edu>2017-02-27 10:11:43 -0500
commite6459a351f14d76dbac83e95a55664820387ad7b (patch)
tree3fba82ce642fb6da2359bf55510b87fcd8064a88 /BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java
parent0b4fd83d36eb82c92a39af8b8e1c521d822bd4c3 (diff)
Package reorganization
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java158
1 files changed, 0 insertions, 158 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java
deleted file mode 100644
index 58c375b..0000000
--- a/BJC-Utils2/src/main/java/bjc/utils/data/HalfBoundLazyPair.java
+++ /dev/null
@@ -1,158 +0,0 @@
-package bjc.utils.data;
-
-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;
-
- private Function<OldType, IPair<NewLeft, NewRight>> binder;
-
- private IPair<NewLeft, NewRight> boundPair;
- private boolean pairBound;
-
- public HalfBoundLazyPair(Supplier<OldType> oldSupp,
- Function<OldType, IPair<NewLeft, NewRight>> bindr) {
- oldSupplier = oldSupp;
- binder = bindr;
- }
-
- @Override
- public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind(
- BiFunction<NewLeft, NewRight, IPair<BoundLeft, BoundRight>> bindr) {
- IHolder<IPair<NewLeft, NewRight>> newPair = new Identity<>(
- boundPair);
- IHolder<Boolean> newPairMade = new Identity<>(pairBound);
-
- Supplier<NewLeft> leftSupp = () -> {
- if (!newPairMade.getValue()) {
- newPair.replace(binder.apply(oldSupplier.get()));
- newPairMade.replace(true);
- }
-
- return newPair.unwrap((pair) -> pair.getLeft());
- };
-
- Supplier<NewRight> rightSupp = () -> {
- if (!newPairMade.getValue()) {
- newPair.replace(binder.apply(oldSupplier.get()));
- newPairMade.replace(true);
- }
-
- return newPair.unwrap((pair) -> pair.getRight());
- };
-
- return new BoundLazyPair<>(leftSupp, rightSupp, bindr);
- }
-
- @Override
- public <BoundLeft> IPair<BoundLeft, NewRight> bindLeft(
- Function<NewLeft, IPair<BoundLeft, NewRight>> leftBinder) {
- Supplier<NewLeft> leftSupp = () -> {
- IPair<NewLeft, NewRight> newPair = boundPair;
-
- if (!pairBound) {
- newPair = binder.apply(oldSupplier.get());
- }
-
- return newPair.getLeft();
- };
-
- return new HalfBoundLazyPair<>(leftSupp, leftBinder);
- }
-
- @Override
- public <BoundRight> IPair<NewLeft, BoundRight> bindRight(
- Function<NewRight, IPair<NewLeft, BoundRight>> rightBinder) {
- Supplier<NewRight> rightSupp = () -> {
- IPair<NewLeft, NewRight> newPair = boundPair;
-
- if (!pairBound) {
- newPair = binder.apply(oldSupplier.get());
- }
-
- return newPair.getRight();
- };
-
- return new HalfBoundLazyPair<>(rightSupp, rightBinder);
- }
-
- @Override
- 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<>(
- leftCombiner.apply(leftVal, otherLeft),
- rightCombiner.apply(rightVal, otherRight));
- });
- });
- }
-
- @Override
- public <NewLeftType> IPair<NewLeftType, NewRight> mapLeft(
- Function<NewLeft, NewLeftType> mapper) {
- Supplier<NewLeftType> leftSupp = () -> {
- if (pairBound) {
- return mapper.apply(boundPair.getLeft());
- }
-
- NewLeft leftVal = binder.apply(oldSupplier.get()).getLeft();
-
- return mapper.apply(leftVal);
- };
-
- Supplier<NewRight> rightSupp = () -> {
- if (pairBound) {
- return boundPair.getRight();
- }
-
- return binder.apply(oldSupplier.get()).getRight();
- };
-
- return new LazyPair<>(leftSupp, rightSupp);
- }
-
- @Override
- public <NewRightType> IPair<NewLeft, NewRightType> mapRight(
- Function<NewRight, NewRightType> mapper) {
- Supplier<NewLeft> leftSupp = () -> {
- if (pairBound) {
- return boundPair.getLeft();
- }
-
- return binder.apply(oldSupplier.get()).getLeft();
- };
-
- Supplier<NewRightType> rightSupp = () -> {
- if (pairBound) {
- return mapper.apply(boundPair.getRight());
- }
-
- NewRight rightVal = binder.apply(oldSupplier.get()).getRight();
-
- return mapper.apply(rightVal);
- };
-
- return new LazyPair<>(leftSupp, rightSupp);
- }
-
- @Override
- public <MergedType> MergedType merge(
- BiFunction<NewLeft, NewRight, MergedType> merger) {
- if (!pairBound) {
- boundPair = binder.apply(oldSupplier.get());
-
- pairBound = true;
- }
-
- return boundPair.merge(merger);
- }
-} \ No newline at end of file