diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2017-10-11 13:41:07 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2017-10-11 13:41:07 -0300 |
| commit | 946cab444bc301d8a7c756a1bab039558288de89 (patch) | |
| tree | 419f27c39a509bcd83cae0e6630be8eb7ff95a30 /base/src/main/java/bjc/utils/data/LazyPair.java | |
| parent | c82e3b3b2de0633317ec8fc85925e91422820597 (diff) | |
Cleanup work
Diffstat (limited to 'base/src/main/java/bjc/utils/data/LazyPair.java')
| -rw-r--r-- | base/src/main/java/bjc/utils/data/LazyPair.java | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/base/src/main/java/bjc/utils/data/LazyPair.java b/base/src/main/java/bjc/utils/data/LazyPair.java index 5cb85f3..548a09e 100644 --- a/base/src/main/java/bjc/utils/data/LazyPair.java +++ b/base/src/main/java/bjc/utils/data/LazyPair.java @@ -8,56 +8,63 @@ import bjc.utils.data.internals.BoundLazyPair; import bjc.utils.data.internals.HalfBoundLazyPair; /** - * A lazy implementation of a pair + * A lazy implementation of a pair. * * @author ben * * @param <LeftType> - * The type on the left side of the pair - * @param <RightType> - * The type on the right side of the pair + * The type on the left side of the pair. * + * @param <RightType> + * The type on the right side of the pair. */ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> { - private LeftType leftValue; - private RightType rightValue; - - private Supplier<LeftType> leftSupplier; - private Supplier<RightType> rightSupplier; - + /* The supplier for the left value. */ + private Supplier<LeftType> leftSupplier; + /* The left value. */ + private LeftType leftValue; + /* Whether the left value has been created. */ private boolean leftMaterialized; + + /* The supplier for the right value. */ + private Supplier<RightType> rightSupplier; + /* The right value. */ + private RightType rightValue; + /* Whether the right value has been created. */ private boolean rightMaterialized; /** - * Create a new lazy pair, using the set values + * 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; } /** - * Create a new lazy pair from the given value sources + * 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<LeftType> leftSupp, final Supplier<RightType> rightSupp) { - // Use single suppliers to catch double-instantiation bugs - leftSupplier = new SingleSupplier<>(leftSupp); + /* Use single suppliers to catch double-instantiation bugs. */ + leftSupplier = new SingleSupplier<>(leftSupp); rightSupplier = new SingleSupplier<>(rightSupp); - leftMaterialized = false; + leftMaterialized = false; rightMaterialized = false; } @@ -98,7 +105,7 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> final BiFunction<RightType, OtherRight, CombinedRight> 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); |
