From f51f6da7319787348c38b875652b5c0e9f88c8aa Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Mon, 13 Apr 2020 18:43:13 -0400 Subject: Cleanup pass Pass to do some cleanups --- src/main/java/bjc/data/internals/BoundLazy.java | 66 ++++++++++++++----------- 1 file changed, 38 insertions(+), 28 deletions(-) (limited to 'src/main/java/bjc/data/internals/BoundLazy.java') diff --git a/src/main/java/bjc/data/internals/BoundLazy.java b/src/main/java/bjc/data/internals/BoundLazy.java index 728af8e..9c984eb 100644 --- a/src/main/java/bjc/data/internals/BoundLazy.java +++ b/src/main/java/bjc/data/internals/BoundLazy.java @@ -15,7 +15,8 @@ import bjc.funcdata.IList; * @author Ben Culkin */ @SuppressWarnings("javadoc") -public class BoundLazy implements IHolder { +public class BoundLazy + implements IHolder { /* The old value. */ private final Supplier> oldSupplier; @@ -29,16 +30,17 @@ public class BoundLazy implements IHolder> actions = new FunctionalList<>(); + private final IList> actions + = new FunctionalList<>(); /** * Create a new bound lazy value. * * @param supp - * The supplier of the old value. + * The supplier of the old value. * * @param binder - * The function to use to bind the old value to the new one. + * The function to use to bind the old value to the new one. */ public BoundLazy(final Supplier> supp, final Function> binder) { @@ -47,11 +49,14 @@ public class BoundLazy implements IHolder IHolder bind(final Function> bindr) { - if(bindr == null) throw new NullPointerException("Binder must not be null"); + public IHolder + bind(final Function> bindr) { + if (bindr == null) + throw new NullPointerException("Binder must not be null"); /* Prepare a list of pending actions. */ - final IList> pendingActions = new FunctionalList<>(); + final IList> pendingActions + = new FunctionalList<>(); actions.forEach(pendingActions::add); /* Create the new supplier of a value. */ @@ -59,35 +64,37 @@ public class BoundLazy implements IHolder oldHolder = boundHolder; /* Bind the value if it hasn't been bound before. */ - if(!holderBound) { + if (!holderBound) { oldHolder = oldSupplier.get().unwrap(binder); } /* Apply all the pending actions. */ - return pendingActions.reduceAux(oldHolder, (action, state) -> { - return state.transform(action); - }, (value) -> value); + return pendingActions.reduceAux(oldHolder, (action, state) -> state.transform(action), value -> value); }; return new BoundLazy<>(typeSupplier, bindr); } @Override - public Function> lift( - final Function func) { - if(func == null) throw new NullPointerException("Function to lift must not be null"); + public Function> + lift(final Function func) { + if (func == null) + throw new NullPointerException("Function to lift must not be null"); - return (val) -> { + return val -> { return new Lazy<>(func.apply(val)); }; } @Override - public IHolder map(final Function mapper) { - if(mapper == null) throw new NullPointerException("Mapper must not be null"); + public IHolder + map(final Function mapper) { + if (mapper == null) + throw new NullPointerException("Mapper must not be null"); /* Prepare a list of pending actions. */ - final IList> pendingActions = new FunctionalList<>(); + final IList> pendingActions + = new FunctionalList<>(); actions.forEach(pendingActions::add); /* Prepare the new supplier. */ @@ -95,14 +102,12 @@ public class BoundLazy implements IHolder oldHolder = boundHolder; /* Bound the value if it hasn't been bound. */ - if(!holderBound) { + 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)); + return pendingActions.reduceAux(oldHolder.getValue(), (action, state) -> action.apply(state), value -> mapper.apply(value)); }; return new Lazy<>(typeSupplier); @@ -110,14 +115,17 @@ public class BoundLazy implements IHolder transform(final UnaryOperator transformer) { - if(transformer == null) throw new NullPointerException("Transformer must not be null"); + public IHolder + transform(final UnaryOperator transformer) { + if (transformer == null) + throw new NullPointerException("Transformer must not be null"); actions.add(transformer); @@ -125,10 +133,12 @@ public class BoundLazy implements IHolder UnwrappedType unwrap(final Function unwrapper) { - if(unwrapper == null) throw new NullPointerException("Unwrapper must not be null"); + public UnwrappedType + unwrap(final Function unwrapper) { + if (unwrapper == null) + throw new NullPointerException("Unwrapper must not be null"); - if(!holderBound) { + if (!holderBound) { boundHolder = oldSupplier.get().unwrap(binder::apply); } -- cgit v1.2.3