From 8a8b457c98e207d809a7616e73eb59bfe197a7a5 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Thu, 31 Mar 2016 11:43:21 -0400 Subject: More code maintenance --- .../src/main/java/bjc/utils/data/GenHolder.java | 28 +++++----- .../src/main/java/bjc/utils/data/IHolder.java | 16 +++--- BJC-Utils2/src/main/java/bjc/utils/data/IPair.java | 16 +++--- BJC-Utils2/src/main/java/bjc/utils/data/Pair.java | 23 ++++---- .../main/java/bjc/utils/data/lazy/LazyHolder.java | 64 +++++++++++----------- .../main/java/bjc/utils/data/lazy/LazyPair.java | 48 ++++++++-------- 6 files changed, 100 insertions(+), 95 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/data') 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 implements IHolder { /** * 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 implements IHolder { * @see bjc.utils.data.IHolder#doWith(java.util.function.Consumer) */ @Override - public void doWith(Consumer f) { - f.accept(held); + public void doWith(Consumer action) { + action.accept(heldValue); } /* @@ -55,8 +55,8 @@ public class GenHolder implements IHolder { * @see bjc.utils.data.IHolder#map(java.util.function.Function) */ @Override - public IHolder map(Function f) { - return new GenHolder<>(f.apply(held)); + public IHolder map(Function transformer) { + return new GenHolder<>(transformer.apply(heldValue)); } /* @@ -65,8 +65,8 @@ public class GenHolder implements IHolder { * @see bjc.utils.data.IHolder#transform(java.util.function.Function) */ @Override - public IHolder transform(Function f) { - held = f.apply(held); + public IHolder transform(Function transformer) { + heldValue = transformer.apply(heldValue); return this; } @@ -77,12 +77,12 @@ public class GenHolder implements IHolder { * @see bjc.utils.data.IHolder#unwrap(java.util.function.Function) */ @Override - public E unwrap(Function f) { - return f.apply(held); + public E unwrap(Function 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 { /** * Call a provided function with the value being held * - * @param f + * @param action * The function to call */ - public void doWith(Consumer f); + public void doWith(Consumer action); /** * Return the result of applying the given transformation to the held @@ -29,21 +29,21 @@ public interface IHolder { * @param * The new type of the held value * - * @param f + * @param transformer * The transformation to apply * @return A holder with the transformed value */ - public IHolder map(Function f); + public IHolder map(Function 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 transform(Function f); + public IHolder transform(Function transformer); /** * Returns a raw mapped value, not contained in a GenHolder @@ -51,9 +51,9 @@ public interface IHolder { * @param * 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 unwrap(Function f); + public E unwrap(Function 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 { * @param * 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 IPair apply(Function lf, - Function rf); + public IPair apply(Function leftTransformer, + Function 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 bc); + public void doWith(BiConsumer action); /** * Collapse this pair to a single value. Does not change the internal @@ -50,9 +50,9 @@ public interface IPair { * @param * The resulting type after merging * - * @param bf + * @param merger * The function to use to collapse the pair. * @return The collapsed value. */ - public E merge(BiFunction bf); + public E merge(BiFunction 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 implements IPair { /** * 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 implements IPair { * 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 implements IPair { * java.util.function.Function) */ @Override - public IPair apply(Function lf, - Function rf) { - return new Pair<>(lf.apply(l), rf.apply(r)); + public IPair apply(Function leftTransformer, + Function rightTransformer) { + return new Pair<>(leftTransformer.apply(leftValue), + rightTransformer.apply(rightValue)); } /* @@ -65,8 +66,8 @@ public class Pair implements IPair { * @see bjc.utils.data.IPair#doWith(java.util.function.BiConsumer) */ @Override - public void doWith(BiConsumer bc) { - bc.accept(l, r); + public void doWith(BiConsumer action) { + action.accept(leftValue, rightValue); } /* @@ -75,7 +76,7 @@ public class Pair implements IPair { * @see bjc.utils.data.IPair#merge(java.util.function.BiFunction) */ @Override - public E merge(BiFunction bf) { - return bf.apply(l, r); + public E merge(BiFunction 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 implements IHolder { private final class LazyHolderSupplier implements Supplier { private FunctionalList> pendingActions; - private Function f; + private Function pendingTransform; public LazyHolderSupplier(FunctionalList> actons, - Function f) { + Function 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::apply, f::apply); + if (heldValue == null) { + return pendingActions.reduceAux(heldSource.get(), + Function::apply, pendingTransform::apply); } else { - return pendingActions.reduceAux(held, - Function::apply, f::apply); + return pendingActions.reduceAux(heldValue, + Function::apply, pendingTransform::apply); } } } @@ -50,76 +50,78 @@ public class LazyHolder implements IHolder { /** * List of queued actions to be performed on realized values */ - private FunctionalList> actions; + private FunctionalList> 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 heldSrc; + private Supplier 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 src) { - heldSrc = src; + public LazyHolder(Supplier 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 f) { - transform((val) -> { + public void doWith(Consumer 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 IHolder map(Function f) { + public IHolder map(Function 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 transform(Function f) { + public IHolder transform(Function transform) { // Queue the transform until we need to apply it - actions.add(f); + actions.add(transform); return this; } @Override - public E unwrap(Function f) { + public E unwrap(Function 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 implements IPair { /** * The backing store for this pair */ - protected IHolder> del; + protected IHolder> 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 leftValSrc, Supplier rightValSrc) { - del = new LazyHolder<>(() -> { - return new Pair<>(leftValSrc.get(), rightValSrc.get()); + public LazyPair(Supplier leftValueSource, + Supplier 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> deleg) { - del = deleg; + private LazyPair(IHolder> delegate) { + delegatePair = delegate; } /* @@ -77,10 +79,10 @@ public class LazyPair implements IPair { * java.util.function.Function) */ @Override - public IPair apply(Function lf, - Function rf) { - IHolder> newPair = - del.map(par -> par.apply(lf, rf)); + public IPair apply(Function leftTransform, + Function rightTransform) { + IHolder> newPair = delegatePair + .map((currentPair) -> currentPair.apply(leftTransform, rightTransform)); return new LazyPair<>(newPair); } @@ -91,9 +93,9 @@ public class LazyPair implements IPair { * @see bjc.utils.data.IPair#doWith(java.util.function.BiConsumer) */ @Override - public void doWith(BiConsumer bc) { - del.doWith((par) -> { - par.doWith(bc); + public void doWith(BiConsumer action) { + delegatePair.doWith((currentPair) -> { + currentPair.doWith(action); }); } @@ -103,7 +105,7 @@ public class LazyPair implements IPair { * @see bjc.utils.data.IPair#merge(java.util.function.BiFunction) */ @Override - public E merge(BiFunction bf) { - return del.unwrap((par) -> par.merge(bf)); + public E merge(BiFunction merger) { + return delegatePair.unwrap((currentPair) -> currentPair.merge(merger)); } } -- cgit v1.2.3