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/Lazy.java | 83 +++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 36 deletions(-) (limited to 'src/main/java/bjc/data/Lazy.java') diff --git a/src/main/java/bjc/data/Lazy.java b/src/main/java/bjc/data/Lazy.java index 0702665..a425232 100644 --- a/src/main/java/bjc/data/Lazy.java +++ b/src/main/java/bjc/data/Lazy.java @@ -15,7 +15,7 @@ import bjc.funcdata.IList; * @author ben * * @param - * The type of the value being held. + * The type of the value being held. */ public class Lazy implements IHolder { /* The supplier of the type. */ @@ -32,7 +32,7 @@ public class Lazy implements IHolder { * Create a new lazy value from the specified seed value. * * @param value - * The seed value to use. + * The seed value to use. */ public Lazy(final ContainedType value) { heldValue = value; @@ -44,7 +44,7 @@ public class Lazy implements IHolder { * Create a new lazy value from the specified value source. * * @param supp - * The source of a value to use. + * The source of a value to use. */ public Lazy(final Supplier supp) { valueSupplier = new SingleSupplier<>(supp); @@ -53,38 +53,39 @@ public class Lazy implements IHolder { } /* Create a new value from a supplier and a list of actions. */ - private Lazy(final Supplier supp, final IList> pendingActions) { + private Lazy(final Supplier supp, + final IList> pendingActions) { valueSupplier = supp; actions = pendingActions; } @Override - public IHolder bind(final Function> binder) { + public IHolder + bind(final Function> binder) { final IList> pendingActions = new FunctionalList<>(); actions.forEach(pendingActions::add); final Supplier supplier = () -> { - if(valueMaterialized) return heldValue; + if (valueMaterialized) + return heldValue; return valueSupplier.get(); }; - return new BoundLazy<>(() -> { - return new Lazy<>(supplier, pendingActions); - }, binder); + return new BoundLazy<>(() -> new Lazy<>(supplier, pendingActions), binder); } @Override - public Function> lift(final Function func) { - return val -> { - return new Lazy<>(func.apply(val)); - }; + public Function> + lift(final Function func) { + return val -> new Lazy<>(func.apply(val)); } @Override - public IHolder map(final Function mapper) { + public IHolder + map(final Function mapper) { final IList> pendingActions = new FunctionalList<>(); actions.forEach(pendingActions::add); @@ -92,7 +93,7 @@ public class Lazy implements IHolder { return new Lazy<>(() -> { ContainedType currVal = heldValue; - if(!valueMaterialized) { + if (!valueMaterialized) { currVal = valueSupplier.get(); } @@ -103,8 +104,8 @@ public class Lazy implements IHolder { @Override public String toString() { - if(valueMaterialized) { - if(actions.isEmpty()) { + if (valueMaterialized) { + if (actions.isEmpty()) { return String.format("value[v='%s']", heldValue); } @@ -115,15 +116,17 @@ public class Lazy implements IHolder { } @Override - public IHolder transform(final UnaryOperator transformer) { + public IHolder + transform(final UnaryOperator transformer) { actions.add(transformer); return this; } @Override - public UnwrappedType unwrap(final Function unwrapper) { - if(!valueMaterialized) { + public UnwrappedType + unwrap(final Function unwrapper) { + if (!valueMaterialized) { heldValue = valueSupplier.get(); valueMaterialized = true; @@ -152,24 +155,32 @@ public class Lazy implements IHolder { @Override public boolean equals(final Object obj) { - if(this == obj) return true; - if(obj == null) return false; - if(!(obj instanceof Lazy)) return false; + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof Lazy)) + return false; final Lazy other = (Lazy) obj; - if(valueMaterialized != other.valueMaterialized) return false; + if (valueMaterialized != other.valueMaterialized) + return false; - if(valueMaterialized) { - if(heldValue == null) { - if(other.heldValue != null) return false; - } else if(!heldValue.equals(other.heldValue)) return false; + if (valueMaterialized) { + if (heldValue == null) { + if (other.heldValue != null) + return false; + } else if (!heldValue.equals(other.heldValue)) + return false; } else return false; - if(actions == null) { - if(other.actions != null) return false; - } else if(actions.getSize() > 0 || other.actions.getSize() > 0) return false; + if (actions == null) { + if (other.actions != null) + return false; + } else if (actions.getSize() > 0 || other.actions.getSize() > 0) + return false; return true; } @@ -178,7 +189,7 @@ public class Lazy implements IHolder { * Create a new lazy container with an already present value. * * @param val - * The value for the lazy container. + * The value for the lazy container. * * @return A new lazy container holding that value. */ @@ -190,12 +201,12 @@ public class Lazy implements IHolder { * Create a new lazy container with a suspended value. * * @param supp - * The suspended value for the lazy container. + * The suspended value for the lazy container. * - * @return A new lazy container that will un-suspend the value when - * necessary. + * @return A new lazy container that will un-suspend the value when necessary. */ - public static Lazy lazy(final Supplier supp) { + public static Lazy + lazy(final Supplier supp) { return new Lazy<>(supp); } } -- cgit v1.2.3