From 889fac2bdf993dc86f64a8893c0260fdcf848acb Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 10 Apr 2017 16:40:33 -0400 Subject: Cleanup --- .../src/main/java/bjc/utils/data/LazyPair.java | 105 +++++++++------------ 1 file changed, 43 insertions(+), 62 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java index 70768be..5cb85f3 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java @@ -1,12 +1,12 @@ package bjc.utils.data; -import bjc.utils.data.internals.BoundLazyPair; -import bjc.utils.data.internals.HalfBoundLazyPair; - import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Supplier; +import bjc.utils.data.internals.BoundLazyPair; +import bjc.utils.data.internals.HalfBoundLazyPair; + /** * A lazy implementation of a pair * @@ -36,7 +36,7 @@ public class LazyPair implements IPair * @param rightVal * The value for the right side of the pair */ - public LazyPair(LeftType leftVal, RightType rightVal) { + public LazyPair(final LeftType leftVal, final RightType rightVal) { leftValue = leftVal; rightValue = rightVal; @@ -52,7 +52,7 @@ public class LazyPair implements IPair * @param rightSupp * The source for a value on the right side of the pair */ - public LazyPair(Supplier leftSupp, Supplier rightSupp) { + public LazyPair(final Supplier leftSupp, final Supplier rightSupp) { // Use single suppliers to catch double-instantiation bugs leftSupplier = new SingleSupplier<>(leftSupp); rightSupplier = new SingleSupplier<>(rightSupp); @@ -63,16 +63,15 @@ public class LazyPair implements IPair @Override public IPair bind( - BiFunction> binder) { + final BiFunction> binder) { return new BoundLazyPair<>(leftSupplier, rightSupplier, binder); } @Override public IPair bindLeft( - Function> leftBinder) { - Supplier leftSupp = () -> { - if (leftMaterialized) - return leftValue; + final Function> leftBinder) { + final Supplier leftSupp = () -> { + if (leftMaterialized) return leftValue; return leftSupplier.get(); }; @@ -82,10 +81,9 @@ public class LazyPair implements IPair @Override public IPair bindRight( - Function> rightBinder) { - Supplier rightSupp = () -> { - if (rightMaterialized) - return rightValue; + final Function> rightBinder) { + final Supplier rightSupp = () -> { + if (rightMaterialized) return rightValue; return rightSupplier.get(); }; @@ -95,13 +93,13 @@ public class LazyPair implements IPair @Override public IPair combine( - IPair otherPair, - BiFunction leftCombiner, - BiFunction rightCombiner) { + final IPair otherPair, + final BiFunction leftCombiner, + final BiFunction rightCombiner) { return otherPair.bind((otherLeft, otherRight) -> { return bind((leftVal, rightVal) -> { - CombinedLeft left = leftCombiner.apply(leftVal, otherLeft); - CombinedRight right = rightCombiner.apply(rightVal, otherRight); + final CombinedLeft left = leftCombiner.apply(leftVal, otherLeft); + final CombinedRight right = rightCombiner.apply(rightVal, otherRight); return new LazyPair<>(left, right); }); @@ -131,17 +129,15 @@ public class LazyPair implements IPair } @Override - public IPair mapLeft(Function mapper) { - Supplier leftSupp = () -> { - if (leftMaterialized) - return mapper.apply(leftValue); + public IPair mapLeft(final Function mapper) { + final Supplier leftSupp = () -> { + if (leftMaterialized) return mapper.apply(leftValue); return mapper.apply(leftSupplier.get()); }; - Supplier rightSupp = () -> { - if (rightMaterialized) - return rightValue; + final Supplier rightSupp = () -> { + if (rightMaterialized) return rightValue; return rightSupplier.get(); }; @@ -150,17 +146,15 @@ public class LazyPair implements IPair } @Override - public IPair mapRight(Function mapper) { - Supplier leftSupp = () -> { - if (leftMaterialized) - return leftValue; + public IPair mapRight(final Function mapper) { + final Supplier leftSupp = () -> { + if (leftMaterialized) return leftValue; return leftSupplier.get(); }; - Supplier rightSupp = () -> { - if (rightMaterialized) - return mapper.apply(rightValue); + final Supplier rightSupp = () -> { + if (rightMaterialized) return mapper.apply(rightValue); return mapper.apply(rightSupplier.get()); }; @@ -169,7 +163,7 @@ public class LazyPair implements IPair } @Override - public MergedType merge(BiFunction merger) { + public MergedType merge(final BiFunction merger) { if (!leftMaterialized) { leftValue = leftSupplier.get(); @@ -211,48 +205,35 @@ public class LazyPair implements IPair int result = 1; result = prime * result + (leftMaterialized ? 1231 : 1237); - result = prime * result + ((leftValue == null) ? 0 : leftValue.hashCode()); + result = prime * result + (leftValue == null ? 0 : leftValue.hashCode()); result = prime * result + (rightMaterialized ? 1231 : 1237); - result = prime * result + ((rightValue == null) ? 0 : rightValue.hashCode()); + result = prime * result + (rightValue == null ? 0 : rightValue.hashCode()); return result; } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof LazyPair)) - return false; + public boolean equals(final Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof LazyPair)) return false; - LazyPair other = (LazyPair) obj; + final LazyPair other = (LazyPair) obj; - if (leftMaterialized != other.leftMaterialized) - return false; + if (leftMaterialized != other.leftMaterialized) return false; if (leftMaterialized) { if (leftValue == null) { - if (other.leftValue != null) - return false; - } else if (!leftValue.equals(other.leftValue)) - return false; - } else { - return false; - } + if (other.leftValue != null) return false; + } else if (!leftValue.equals(other.leftValue)) return false; + } else return false; - if (rightMaterialized != other.rightMaterialized) - return false; + if (rightMaterialized != other.rightMaterialized) return false; if (rightMaterialized) { if (rightValue == null) { - if (other.rightValue != null) - return false; - } else if (!rightValue.equals(other.rightValue)) - return false; - } else { - return false; - } + if (other.rightValue != null) return false; + } else if (!rightValue.equals(other.rightValue)) return false; + } else return false; return true; } -- cgit v1.2.3