From 946cab444bc301d8a7c756a1bab039558288de89 Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Wed, 11 Oct 2017 13:41:07 -0300 Subject: Cleanup work --- .../java/bjc/utils/data/internals/BoundLazy.java | 61 +++++++++------------- 1 file changed, 26 insertions(+), 35 deletions(-) (limited to 'base/src/main/java/bjc/utils/data/internals/BoundLazy.java') diff --git a/base/src/main/java/bjc/utils/data/internals/BoundLazy.java b/base/src/main/java/bjc/utils/data/internals/BoundLazy.java index f71d32b..b160c0c 100644 --- a/base/src/main/java/bjc/utils/data/internals/BoundLazy.java +++ b/base/src/main/java/bjc/utils/data/internals/BoundLazy.java @@ -9,37 +9,35 @@ import bjc.utils.data.Lazy; import bjc.utils.funcdata.FunctionalList; import bjc.utils.funcdata.IList; -/* - * Implements a lazy holder that has been bound +/** + * Implements a lazy holder that has been bound. + * + * @author Ben Culkin */ public class BoundLazy implements IHolder { - /* - * The old value - */ + /* The old value. */ private final Supplier> oldSupplier; - /* - * The function to use to transform the old value into a new value - */ + /* The function to use to transform the old value into a new value. */ private final Function> binder; - /* - * The bound value being held - */ + /* The bound value being held. */ private IHolder boundHolder; - /* - * Whether the bound value has been actualized or not - */ + /* Whether the bound value has been actualized or not. */ private boolean holderBound; - /* - * Transformations currently pending on the bound value - */ + /* Transformations currently pending on the bound value. */ private final IList> actions = new FunctionalList<>(); - /* - * Create a new bound lazy value + /** + * Create a new bound lazy value. + * + * @param supp + * The supplier of the old value. + * + * @param binder + * The function to use to bind the old value to the new one. */ public BoundLazy(final Supplier> supp, final Function> binder) { @@ -51,28 +49,20 @@ public class BoundLazy implements IHolder IHolder bind(final Function> bindr) { if (bindr == null) throw new NullPointerException("Binder must not be null"); - /* - * Prepare a list of pending actions - */ + /* Prepare a list of pending actions. */ final IList> pendingActions = new FunctionalList<>(); actions.forEach(pendingActions::add); - /* - * Create the new supplier of a value - */ + /* Create the new supplier of a value. */ final Supplier> typeSupplier = () -> { IHolder oldHolder = boundHolder; - /* - * Bind the value if it hasn't been bound before - */ + /* Bind the value if it hasn't been bound before. */ if (!holderBound) { oldHolder = oldSupplier.get().unwrap(binder); } - /* - * Apply all the pending actions - */ + /* Apply all the pending actions. */ return pendingActions.reduceAux(oldHolder, (action, state) -> { return state.transform(action); }, (value) -> value); @@ -95,19 +85,20 @@ public class BoundLazy implements IHolder IHolder map(final Function mapper) { if (mapper == null) throw new NullPointerException("Mapper must not be null"); - // Prepare a list of pending actions + /* Prepare a list of pending actions. */ final IList> pendingActions = new FunctionalList<>(); actions.forEach(pendingActions::add); - // Prepare the new supplier + /* Prepare the new supplier. */ final Supplier typeSupplier = () -> { IHolder oldHolder = boundHolder; - // Bound the value if it hasn't been bound + /* Bound the value if it hasn't been bound. */ if (!holderBound) { oldHolder = oldSupplier.get().unwrap(binder); } + /* Apply pending actions. */ return pendingActions.reduceAux(oldHolder.getValue(), (action, state) -> { return action.apply(state); }, (value) -> mapper.apply(value)); @@ -142,4 +133,4 @@ public class BoundLazy implements IHolder