summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyPair.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-04-13 16:54:12 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-04-13 16:54:12 -0400
commitba07771f8333f1b098ab8a9ec9fec886b72b9cc0 (patch)
tree7d1326235d021cb4767065cddd25bbe9fbdf5ce1 /BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyPair.java
parent12637af8d6b7b9b2d96deb89e5a09e05178a8e65 (diff)
Removed old data types
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyPair.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyPair.java168
1 files changed, 0 insertions, 168 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyPair.java
deleted file mode 100644
index dcaeeba..0000000
--- a/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyPair.java
+++ /dev/null
@@ -1,168 +0,0 @@
-package bjc.utils.data.lazy;
-
-import java.util.function.BiConsumer;
-import java.util.function.BiFunction;
-import java.util.function.Supplier;
-
-import bjc.utils.data.IHolder;
-import bjc.utils.data.IPair;
-import bjc.utils.data.Pair;
-
-/**
- * A lazy holder of two values
- *
- * Lazy variant of {@link IPair}
- *
- * @author ben
- *
- * @param <L>
- * The type of value stored on the left side of the pair
- * @param <R>
- * The type of value stored on the right side of the pair
- */
-public class LazyPair<L, R> implements IPair<L, R>, ILazy {
- /**
- * The backing store for this pair
- */
- protected IHolder<IPair<L, R>> delegatePair;
-
- private boolean materialized = false;
- private boolean pendingActions = false;
-
- /**
- * Create a new blank lazy pair
- */
- public LazyPair() {
- delegatePair = new LazyHolder<>(new Pair<>());
- }
-
- /**
- * Create a new lazy pair with the specified initial values
- *
- * @param leftValue
- * The initial value for the left side of the pair
- * @param rightValue
- * The initial value for the right side of the pair
- */
- public LazyPair(L leftValue, R rightValue) {
- materialized = true;
-
- delegatePair = new LazyHolder<>(new Pair<>(leftValue, rightValue));
- }
-
- /**
- * Create a new lazy pair with the specified sources for initial values
- *
- * @param leftValueSource
- * The function to call for the left initial value
- * @param rightValueSource
- * The function to call for the right initial value
- */
- public LazyPair(Supplier<L> leftValueSource,
- Supplier<R> rightValueSource) {
- if (leftValueSource == null || rightValueSource == null) {
- throw new NullPointerException("Sources must be non-null");
- }
-
- delegatePair = new LazyHolder<>(() -> {
- return new Pair<>(leftValueSource.get(),
- rightValueSource.get());
- });
- }
-
- /**
- * Create a new lazy pair with a specified internal delegate
- *
- * @param delegate
- * The internal delegate for the pair
- */
- private LazyPair(IHolder<IPair<L, R>> delegate, boolean mater,
- boolean pend) {
- materialized = mater;
- pendingActions = pend;
-
- delegatePair = delegate;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see bjc.utils.data.IPair#doWith(java.util.function.BiConsumer)
- */
- @Override
- public void doWith(BiConsumer<L, R> action) {
- if (action == null) {
- throw new NullPointerException("Action must be non-null");
- }
-
- pendingActions = true;
-
- delegatePair.doWith((currentPair) -> {
- currentPair.doWith(action);
- });
- }
-
- /*
- * (non-Javadoc)
- *
- * @see bjc.utils.data.IPair#merge(java.util.function.BiFunction)
- */
- @Override
- public <E> E merge(BiFunction<L, R, E> merger) {
- if (merger == null) {
- throw new NullPointerException("Merger must be non-null");
- }
-
- materialized = true;
- pendingActions = false;
-
- return delegatePair
- .unwrap((currentPair) -> currentPair.merge(merger));
- }
-
- @Override
- public boolean isMaterialized() {
- return materialized;
- }
-
- @Override
- public boolean hasPendingActions() {
- return pendingActions;
- }
-
- /*
- * Note: Materializing will also apply all currently pending actions
- */
- @Override
- public void materialize() {
- merge((left, right) -> null);
-
- materialized = true;
- pendingActions = false;
- }
-
- @Override
- public void applyPendingActions() {
- merge((left, right) -> null);
-
- materialized = true;
- pendingActions = false;
- }
-
- @Override
- public <L2, R2> IPair<L2, R2> bind(
- BiFunction<L, R, IPair<L2, R2>> binder) {
- IHolder<IPair<L2, R2>> newDelegate = delegatePair
- .map((pairVal) -> {
- return pairVal.bind(binder);
- });
-
- return new LazyPair<>(newDelegate, isMaterialized(),
- hasPendingActions());
- }
-
- @Override
- public String toString() {
- return delegatePair.toString();
- }
-} \ No newline at end of file