From 6340caa7ec15be51c6d633a0519f3e0c76b25241 Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Mon, 9 Nov 2020 18:53:43 -0500 Subject: Formatting cleanup --- src/main/java/bjc/data/Lazy.java | 62 +++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 27 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 a425232..8573325 100644 --- a/src/main/java/bjc/data/Lazy.java +++ b/src/main/java/bjc/data/Lazy.java @@ -65,13 +65,14 @@ public class Lazy implements IHolder { bind(final Function> binder) { final IList> pendingActions = new FunctionalList<>(); - actions.forEach(pendingActions::add); + for (UnaryOperator action : actions) { + pendingActions.add(action); + } + final Supplier supplier = () -> { - if (valueMaterialized) - return heldValue; - - return valueSupplier.get(); + if (valueMaterialized) return heldValue; + else return valueSupplier.get(); }; return new BoundLazy<>(() -> new Lazy<>(supplier, pendingActions), binder); @@ -87,8 +88,10 @@ public class Lazy implements IHolder { public IHolder map(final Function mapper) { final IList> pendingActions = new FunctionalList<>(); - - actions.forEach(pendingActions::add); + + for (UnaryOperator action : actions) { + pendingActions.add(action); + } return new Lazy<>(() -> { ContainedType currVal = heldValue; @@ -97,7 +100,8 @@ public class Lazy implements IHolder { currVal = valueSupplier.get(); } - return pendingActions.reduceAux(currVal, UnaryOperator::apply, + return pendingActions.reduceAux(currVal, + UnaryOperator::apply, value -> mapper.apply(value)); }); } @@ -107,12 +111,18 @@ public class Lazy implements IHolder { if (valueMaterialized) { if (actions.isEmpty()) { return String.format("value[v='%s']", heldValue); + } else { + return String.format("value[v='%s'] (has %d pending transforms)", + heldValue, actions.getSize()); } - - return String.format("value[v='%s'] (has pending transforms)", heldValue); } - return "(unmaterialized)"; + if (actions.isEmpty()) { + return"(unmaterialized)"; + } else { + return String.format("(unmaterialized; has %d pending transforms", + actions.getSize()); + } } @Override @@ -132,9 +142,9 @@ public class Lazy implements IHolder { valueMaterialized = true; } - actions.forEach(action -> { - heldValue = action.apply(heldValue); - }); + for (UnaryOperator action : actions) { + heldValue = action.apply(heldValue); + } actions = new FunctionalList<>(); @@ -155,12 +165,9 @@ 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; @@ -169,18 +176,19 @@ public class Lazy implements IHolder { if (valueMaterialized) { if (heldValue == null) { - if (other.heldValue != null) - return false; - } else if (!heldValue.equals(other.heldValue)) + if (other.heldValue != null) return false; + } else if (!heldValue.equals(other.heldValue)) { return false; - } else + } + } else { return false; + } if (actions == null) { - if (other.actions != null) - return false; - } else if (actions.getSize() > 0 || other.actions.getSize() > 0) + if (other.actions != null) return false; + } else if (actions.getSize() > 0 || other.actions.getSize() > 0) { return false; + } return true; } -- cgit v1.2.3