From 63d88eb8db1f7a6d5924ec2a8b7f462373d5ac9a Mon Sep 17 00:00:00 2001 From: bjculkin Date: Fri, 7 Apr 2017 10:51:31 -0400 Subject: Cleanup --- BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java | 40 ++++++++++++++--------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java b/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java index 2eb2cf3..719b11f 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java @@ -62,7 +62,8 @@ public class Lazy implements IHolder { actions.forEach(pendingActions::add); Supplier supplier = () -> { - if (valueMaterialized) return heldValue; + if (valueMaterialized) + return heldValue; return valueSupplier.get(); }; @@ -74,7 +75,7 @@ public class Lazy implements IHolder { @Override public Function> lift(Function func) { - return (val) -> { + return val -> { return new Lazy<>(func.apply(val)); }; } @@ -93,16 +94,17 @@ public class Lazy implements IHolder { } return pendingActions.reduceAux(currVal, UnaryOperator::apply, - (value) -> mapper.apply(value)); + value -> mapper.apply(value)); }); } @Override public String toString() { if (valueMaterialized) { - if (actions.isEmpty()) return "value[v='" + heldValue + "']"; - - return "value[v='" + heldValue + "'] (has pending transforms)"; + if (actions.isEmpty()) + return String.format("value[v='%s']", heldValue); + else + return String.format("value[v='%s'] (has pending transforms)", heldValue); } return "(unmaterialized)"; @@ -123,7 +125,7 @@ public class Lazy implements IHolder { valueMaterialized = true; } - actions.forEach((action) -> { + actions.forEach(action -> { heldValue = action.apply(heldValue); }); @@ -146,25 +148,33 @@ public class Lazy implements IHolder { @Override public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof Lazy)) + return false; 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 (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 (other.actions != null) + return false; + } else if (actions.getSize() > 0 || other.actions.getSize() > 0) + return false; return true; } -- cgit v1.2.3