summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/data
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/data')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java28
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java16
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/IPair.java16
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Pair.java23
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyHolder.java64
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyPair.java48
6 files changed, 100 insertions, 95 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java
index 8b1983e..6854440 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/GenHolder.java
@@ -19,24 +19,24 @@ public class GenHolder<T> implements IHolder<T> {
/**
* The state this holder is responsible for.
*/
- private T held;
+ private T heldValue;
/**
* Creates a new empty holder, with its state set to null
*/
public GenHolder() {
- held = null;
+ heldValue = null;
}
/**
* Creates a new holder, with its state initialized to the provided
* value
*
- * @param hld
+ * @param held
* The state to initialize this holder to.
*/
- public GenHolder(T hld) {
- held = hld;
+ public GenHolder(T held) {
+ heldValue = held;
}
/*
@@ -45,8 +45,8 @@ public class GenHolder<T> implements IHolder<T> {
* @see bjc.utils.data.IHolder#doWith(java.util.function.Consumer)
*/
@Override
- public void doWith(Consumer<T> f) {
- f.accept(held);
+ public void doWith(Consumer<T> action) {
+ action.accept(heldValue);
}
/*
@@ -55,8 +55,8 @@ public class GenHolder<T> implements IHolder<T> {
* @see bjc.utils.data.IHolder#map(java.util.function.Function)
*/
@Override
- public <NewT> IHolder<NewT> map(Function<T, NewT> f) {
- return new GenHolder<>(f.apply(held));
+ public <NewT> IHolder<NewT> map(Function<T, NewT> transformer) {
+ return new GenHolder<>(transformer.apply(heldValue));
}
/*
@@ -65,8 +65,8 @@ public class GenHolder<T> implements IHolder<T> {
* @see bjc.utils.data.IHolder#transform(java.util.function.Function)
*/
@Override
- public IHolder<T> transform(Function<T, T> f) {
- held = f.apply(held);
+ public IHolder<T> transform(Function<T, T> transformer) {
+ heldValue = transformer.apply(heldValue);
return this;
}
@@ -77,12 +77,12 @@ public class GenHolder<T> implements IHolder<T> {
* @see bjc.utils.data.IHolder#unwrap(java.util.function.Function)
*/
@Override
- public <E> E unwrap(Function<T, E> f) {
- return f.apply(held);
+ public <E> E unwrap(Function<T, E> unwrapper) {
+ return unwrapper.apply(heldValue);
}
@Override
public String toString() {
- return held.toString();
+ return heldValue.toString();
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java
index 3675842..6290d5f 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java
@@ -17,10 +17,10 @@ public interface IHolder<T> {
/**
* Call a provided function with the value being held
*
- * @param f
+ * @param action
* The function to call
*/
- public void doWith(Consumer<T> f);
+ public void doWith(Consumer<T> action);
/**
* Return the result of applying the given transformation to the held
@@ -29,21 +29,21 @@ public interface IHolder<T> {
* @param <NewT>
* The new type of the held value
*
- * @param f
+ * @param transformer
* The transformation to apply
* @return A holder with the transformed value
*/
- public <NewT> IHolder<NewT> map(Function<T, NewT> f);
+ public <NewT> IHolder<NewT> map(Function<T, NewT> transformer);
/**
* Apply the given transformation to the held value. Returns the holder
* for allowing chaining of transforms
*
- * @param f
+ * @param transformer
* The transform to apply to the value
* @return The holder
*/
- public IHolder<T> transform(Function<T, T> f);
+ public IHolder<T> transform(Function<T, T> transformer);
/**
* Returns a raw mapped value, not contained in a GenHolder
@@ -51,9 +51,9 @@ public interface IHolder<T> {
* @param <E>
* The type of the value that is the end result
*
- * @param f
+ * @param unwrapper
* The function to use for mapping the value
* @return The mapped value outside of a GenHolder
*/
- public <E> E unwrap(Function<T, E> f);
+ public <E> E unwrap(Function<T, E> unwrapper);
} \ No newline at end of file
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java
index fcf5618..e2ee6a4 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java
@@ -25,23 +25,23 @@ public interface IPair<L, R> {
* @param <R2>
* The new right type of the pair
*
- * @param lf
+ * @param leftTransformer
* The function to apply to the left value.
- * @param rf
+ * @param rightTransformer
* The function to apply to the right value.
* @return A new pair containing the two modified values.
*/
- public <L2, R2> IPair<L2, R2> apply(Function<L, L2> lf,
- Function<R, R2> rf);
+ public <L2, R2> IPair<L2, R2> apply(Function<L, L2> leftTransformer,
+ Function<R, R2> rightTransformer);
/**
* Execute an action with the values of this pair. Has no effect on the
* internal contents
*
- * @param bc
+ * @param action
* The action to execute on the values
*/
- public void doWith(BiConsumer<L, R> bc);
+ public void doWith(BiConsumer<L, R> action);
/**
* Collapse this pair to a single value. Does not change the internal
@@ -50,9 +50,9 @@ public interface IPair<L, R> {
* @param <E>
* The resulting type after merging
*
- * @param bf
+ * @param merger
* The function to use to collapse the pair.
* @return The collapsed value.
*/
- public <E> E merge(BiFunction<L, R, E> bf);
+ public <E> E merge(BiFunction<L, R, E> merger);
} \ No newline at end of file
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java
index 4a8fbc3..b5ad953 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java
@@ -20,12 +20,12 @@ public class Pair<L, R> implements IPair<L, R> {
/**
* The left value of the pair
*/
- protected L l;
+ protected L leftValue;
/**
* The right value of the pair
*/
- protected R r;
+ protected R rightValue;
/**
* Create a new pair that holds two nulls.
@@ -43,8 +43,8 @@ public class Pair<L, R> implements IPair<L, R> {
* The value to hold on the right.
*/
public Pair(L left, R right) {
- l = left;
- r = right;
+ leftValue = left;
+ rightValue = right;
}
/*
@@ -54,9 +54,10 @@ public class Pair<L, R> implements IPair<L, R> {
* java.util.function.Function)
*/
@Override
- public <L2, R2> IPair<L2, R2> apply(Function<L, L2> lf,
- Function<R, R2> rf) {
- return new Pair<>(lf.apply(l), rf.apply(r));
+ public <L2, R2> IPair<L2, R2> apply(Function<L, L2> leftTransformer,
+ Function<R, R2> rightTransformer) {
+ return new Pair<>(leftTransformer.apply(leftValue),
+ rightTransformer.apply(rightValue));
}
/*
@@ -65,8 +66,8 @@ public class Pair<L, R> implements IPair<L, R> {
* @see bjc.utils.data.IPair#doWith(java.util.function.BiConsumer)
*/
@Override
- public void doWith(BiConsumer<L, R> bc) {
- bc.accept(l, r);
+ public void doWith(BiConsumer<L, R> action) {
+ action.accept(leftValue, rightValue);
}
/*
@@ -75,7 +76,7 @@ public class Pair<L, R> implements IPair<L, R> {
* @see bjc.utils.data.IPair#merge(java.util.function.BiFunction)
*/
@Override
- public <E> E merge(BiFunction<L, R, E> bf) {
- return bf.apply(l, r);
+ public <E> E merge(BiFunction<L, R, E> merger) {
+ return merger.apply(leftValue, rightValue);
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyHolder.java
index ddf3cfc..e74ce91 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyHolder.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyHolder.java
@@ -23,26 +23,26 @@ public class LazyHolder<T> implements IHolder<T> {
private final class LazyHolderSupplier<NewT>
implements Supplier<NewT> {
private FunctionalList<Function<T, T>> pendingActions;
- private Function<T, NewT> f;
+ private Function<T, NewT> pendingTransform;
public LazyHolderSupplier(FunctionalList<Function<T, T>> actons,
- Function<T, NewT> f) {
+ Function<T, NewT> transform) {
// Resolve latent bug I just realized. After a map, adding new
// actions to the original holder could've resulted in changes
// to all unactualized mapped values from that holder
pendingActions = actons.clone();
- this.f = f;
+ this.pendingTransform = transform;
}
@Override
public NewT get() {
- if (held == null) {
- return pendingActions.reduceAux(heldSrc.get(),
- Function<T, T>::apply, f::apply);
+ if (heldValue == null) {
+ return pendingActions.reduceAux(heldSource.get(),
+ Function<T, T>::apply, pendingTransform::apply);
} else {
- return pendingActions.reduceAux(held,
- Function<T, T>::apply, f::apply);
+ return pendingActions.reduceAux(heldValue,
+ Function<T, T>::apply, pendingTransform::apply);
}
}
}
@@ -50,76 +50,78 @@ public class LazyHolder<T> implements IHolder<T> {
/**
* List of queued actions to be performed on realized values
*/
- private FunctionalList<Function<T, T>> actions;
+ private FunctionalList<Function<T, T>> actions =
+ new FunctionalList<>();
/**
* The value internally held by this lazy holder
*/
- private T held;
+ private T heldValue;
/**
* The source for a value held by this lazy holder
*/
- private Supplier<T> heldSrc;
+ private Supplier<T> heldSource;
/**
* Create a new lazy holder with the given supplier
*
- * @param src
+ * @param source
* The supplier for a value when it is neededs
*/
- public LazyHolder(Supplier<T> src) {
- heldSrc = src;
+ public LazyHolder(Supplier<T> source) {
+ heldSource = source;
- held = null;
+ heldValue = null;
}
/**
* Create a new lazy holder with the given value
*
- * @param val
+ * @param value
* The value held in the holder
*/
- public LazyHolder(T val) {
- held = val;
+ public LazyHolder(T value) {
+ heldValue = value;
}
@Override
- public void doWith(Consumer<T> f) {
- transform((val) -> {
+ public void doWith(Consumer<T> action) {
+ transform((value) -> {
// Do the action with the value
- f.accept(val);
+ action.accept(value);
// Return the untransformed value
- return val;
+ return value;
});
}
@Override
- public <NewT> IHolder<NewT> map(Function<T, NewT> f) {
+ public <NewT> IHolder<NewT> map(Function<T, NewT> transform) {
// Don't actually map until we need to
- return new LazyHolder<>(new LazyHolderSupplier<>(actions, f));
+ return new LazyHolder<>(
+ new LazyHolderSupplier<>(actions, transform));
}
@Override
- public IHolder<T> transform(Function<T, T> f) {
+ public IHolder<T> transform(Function<T, T> transform) {
// Queue the transform until we need to apply it
- actions.add(f);
+ actions.add(transform);
return this;
}
@Override
- public <E> E unwrap(Function<T, E> f) {
+ public <E> E unwrap(Function<T, E> unwrapper) {
// Actualize ourselves
- if (held == null) {
- held = heldSrc.get();
+ if (heldValue == null) {
+ heldValue = heldSource.get();
}
// Apply all pending transforms
- actions.forEach((act) -> held = act.apply(held));
+ actions.forEach((action) -> heldValue = action.apply(heldValue));
- return f.apply(held);
+ return unwrapper.apply(heldValue);
}
}
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
index 70b6f2f..3c21b56 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyPair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/lazy/LazyPair.java
@@ -25,49 +25,51 @@ public class LazyPair<L, R> implements IPair<L, R> {
/**
* The backing store for this pair
*/
- protected IHolder<IPair<L, R>> del;
+ protected IHolder<IPair<L, R>> delegatePair;
/**
* Create a new blank lazy pair
*/
public LazyPair() {
- del = new LazyHolder<>(new Pair<>());
+ delegatePair = new LazyHolder<>(new Pair<>());
}
/**
* Create a new lazy pair with the specified initial values
*
- * @param leftVal
+ * @param leftValue
* The initial value for the left side of the pair
- * @param rightVal
+ * @param rightValue
* The initial value for the right side of the pair
*/
- public LazyPair(L leftVal, R rightVal) {
- del = new LazyHolder<>(new Pair<>(leftVal, rightVal));
+ public LazyPair(L leftValue, R rightValue) {
+ delegatePair = new LazyHolder<>(new Pair<>(leftValue, rightValue));
}
/**
* Create a new lazy pair with the specified sources for initial values
*
- * @param leftValSrc
+ * @param leftValueSource
* The function to call for the left initial value
- * @param rightValSrc
+ * @param rightValueSource
* The function to call for the right initial value
*/
- public LazyPair(Supplier<L> leftValSrc, Supplier<R> rightValSrc) {
- del = new LazyHolder<>(() -> {
- return new Pair<>(leftValSrc.get(), rightValSrc.get());
+ public LazyPair(Supplier<L> leftValueSource,
+ Supplier<R> rightValueSource) {
+ delegatePair = new LazyHolder<>(() -> {
+ return new Pair<>(leftValueSource.get(),
+ rightValueSource.get());
});
}
/**
* Create a new lazy pair with a specified internal delegate
*
- * @param deleg
+ * @param delegate
* The internal delegate for the pair
*/
- private LazyPair(IHolder<IPair<L, R>> deleg) {
- del = deleg;
+ private LazyPair(IHolder<IPair<L, R>> delegate) {
+ delegatePair = delegate;
}
/*
@@ -77,10 +79,10 @@ public class LazyPair<L, R> implements IPair<L, R> {
* java.util.function.Function)
*/
@Override
- public <L2, R2> IPair<L2, R2> apply(Function<L, L2> lf,
- Function<R, R2> rf) {
- IHolder<IPair<L2, R2>> newPair =
- del.map(par -> par.apply(lf, rf));
+ public <L2, R2> IPair<L2, R2> apply(Function<L, L2> leftTransform,
+ Function<R, R2> rightTransform) {
+ IHolder<IPair<L2, R2>> newPair = delegatePair
+ .map((currentPair) -> currentPair.apply(leftTransform, rightTransform));
return new LazyPair<>(newPair);
}
@@ -91,9 +93,9 @@ public class LazyPair<L, R> implements IPair<L, R> {
* @see bjc.utils.data.IPair#doWith(java.util.function.BiConsumer)
*/
@Override
- public void doWith(BiConsumer<L, R> bc) {
- del.doWith((par) -> {
- par.doWith(bc);
+ public void doWith(BiConsumer<L, R> action) {
+ delegatePair.doWith((currentPair) -> {
+ currentPair.doWith(action);
});
}
@@ -103,7 +105,7 @@ public class LazyPair<L, R> implements IPair<L, R> {
* @see bjc.utils.data.IPair#merge(java.util.function.BiFunction)
*/
@Override
- public <E> E merge(BiFunction<L, R, E> bf) {
- return del.unwrap((par) -> par.merge(bf));
+ public <E> E merge(BiFunction<L, R, E> merger) {
+ return delegatePair.unwrap((currentPair) -> currentPair.merge(merger));
}
}