From df94066e3af02ff02d5ab4d033a3d603f743234c Mon Sep 17 00:00:00 2001 From: bjculkin Date: Mon, 12 Feb 2018 22:45:04 -0500 Subject: Formatting pass --- base/src/main/java/bjc/utils/data/LazyPair.java | 88 +++++++++++++------------ 1 file changed, 45 insertions(+), 43 deletions(-) (limited to 'base/src/main/java/bjc/utils/data/LazyPair.java') diff --git a/base/src/main/java/bjc/utils/data/LazyPair.java b/base/src/main/java/bjc/utils/data/LazyPair.java index 548a09e..0500486 100644 --- a/base/src/main/java/bjc/utils/data/LazyPair.java +++ b/base/src/main/java/bjc/utils/data/LazyPair.java @@ -13,40 +13,40 @@ import bjc.utils.data.internals.HalfBoundLazyPair; * @author ben * * @param - * The type on the left side of the pair. + * The type on the left side of the pair. * * @param - * The type on the right side of the pair. + * The type on the right side of the pair. */ public class LazyPair implements IPair { /* The supplier for the left value. */ - private Supplier leftSupplier; + private Supplier leftSupplier; /* The left value. */ private LeftType leftValue; /* Whether the left value has been created. */ - private boolean leftMaterialized; + private boolean leftMaterialized; /* The supplier for the right value. */ private Supplier rightSupplier; /* The right value. */ private RightType rightValue; /* Whether the right value has been created. */ - private boolean rightMaterialized; + private boolean rightMaterialized; /** * Create a new lazy pair, using the set values. * * @param leftVal - * The value for the left side of the pair. + * The value for the left side of the pair. * * @param rightVal - * The value for the right side of the pair. + * The value for the right side of the pair. */ public LazyPair(final LeftType leftVal, final RightType rightVal) { - leftValue = leftVal; + leftValue = leftVal; rightValue = rightVal; - leftMaterialized = true; + leftMaterialized = true; rightMaterialized = true; } @@ -54,17 +54,17 @@ public class LazyPair implements IPair * Create a new lazy pair from the given value sources. * * @param leftSupp - * The source for a value on the left side of the pair. + * The source for a value on the left side of the pair. * * @param rightSupp - * The source for a value on the right side of the pair. + * The source for a value on the right side of the pair. */ public LazyPair(final Supplier leftSupp, final Supplier rightSupp) { /* Use single suppliers to catch double-instantiation bugs. */ - leftSupplier = new SingleSupplier<>(leftSupp); + leftSupplier = new SingleSupplier<>(leftSupp); rightSupplier = new SingleSupplier<>(rightSupp); - leftMaterialized = false; + leftMaterialized = false; rightMaterialized = false; } @@ -78,7 +78,7 @@ public class LazyPair implements IPair public IPair bindLeft( final Function> leftBinder) { final Supplier leftSupp = () -> { - if (leftMaterialized) return leftValue; + if(leftMaterialized) return leftValue; return leftSupplier.get(); }; @@ -90,7 +90,7 @@ public class LazyPair implements IPair public IPair bindRight( final Function> rightBinder) { final Supplier rightSupp = () -> { - if (rightMaterialized) return rightValue; + if(rightMaterialized) return rightValue; return rightSupplier.get(); }; @@ -105,7 +105,7 @@ public class LazyPair implements IPair final BiFunction rightCombiner) { return otherPair.bind((otherLeft, otherRight) -> { return bind((leftVal, rightVal) -> { - final CombinedLeft left = leftCombiner.apply(leftVal, otherLeft); + final CombinedLeft left = leftCombiner.apply(leftVal, otherLeft); final CombinedRight right = rightCombiner.apply(rightVal, otherRight); return new LazyPair<>(left, right); @@ -115,7 +115,7 @@ public class LazyPair implements IPair @Override public LeftType getLeft() { - if (!leftMaterialized) { + if(!leftMaterialized) { leftValue = leftSupplier.get(); leftMaterialized = true; @@ -126,7 +126,7 @@ public class LazyPair implements IPair @Override public RightType getRight() { - if (!rightMaterialized) { + if(!rightMaterialized) { rightValue = rightSupplier.get(); rightMaterialized = true; @@ -138,13 +138,13 @@ public class LazyPair implements IPair @Override public IPair mapLeft(final Function mapper) { final Supplier leftSupp = () -> { - if (leftMaterialized) return mapper.apply(leftValue); + if(leftMaterialized) return mapper.apply(leftValue); return mapper.apply(leftSupplier.get()); }; final Supplier rightSupp = () -> { - if (rightMaterialized) return rightValue; + if(rightMaterialized) return rightValue; return rightSupplier.get(); }; @@ -155,13 +155,13 @@ public class LazyPair implements IPair @Override public IPair mapRight(final Function mapper) { final Supplier leftSupp = () -> { - if (leftMaterialized) return leftValue; + if(leftMaterialized) return leftValue; return leftSupplier.get(); }; final Supplier rightSupp = () -> { - if (rightMaterialized) return mapper.apply(rightValue); + if(rightMaterialized) return mapper.apply(rightValue); return mapper.apply(rightSupplier.get()); }; @@ -171,13 +171,13 @@ public class LazyPair implements IPair @Override public MergedType merge(final BiFunction merger) { - if (!leftMaterialized) { + if(!leftMaterialized) { leftValue = leftSupplier.get(); leftMaterialized = true; } - if (!rightMaterialized) { + if(!rightMaterialized) { rightValue = rightSupplier.get(); rightMaterialized = true; @@ -191,13 +191,13 @@ public class LazyPair implements IPair String leftVal; String rightVal; - if (leftMaterialized) { + if(leftMaterialized) { leftVal = leftValue.toString(); } else { leftVal = "(un-materialized)"; } - if (rightMaterialized) { + if(rightMaterialized) { rightVal = rightValue.toString(); } else { rightVal = "(un-materialized)"; @@ -221,26 +221,28 @@ public class LazyPair implements IPair @Override public boolean equals(final Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (!(obj instanceof LazyPair)) return false; + if(this == obj) return true; + if(obj == null) return false; + if(!(obj instanceof LazyPair)) return false; final LazyPair other = (LazyPair) obj; - 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 (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(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(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; return true; } -- cgit v1.2.3