From 504ca816530efdff06bc202e0432ebd354aec304 Mon Sep 17 00:00:00 2001 From: EVE Date: Tue, 14 Mar 2017 12:07:14 -0400 Subject: Cleanup --- .../main/java/bjc/utils/data/CircularIterator.java | 14 ++-- .../src/main/java/bjc/utils/data/Either.java | 64 +++++----------- .../src/main/java/bjc/utils/data/IHolder.java | 38 +++++---- BJC-Utils2/src/main/java/bjc/utils/data/IPair.java | 40 +++++----- BJC-Utils2/src/main/java/bjc/utils/data/ITree.java | 38 ++++----- .../src/main/java/bjc/utils/data/Identity.java | 28 +++---- BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java | 28 +++---- .../src/main/java/bjc/utils/data/LazyPair.java | 62 ++++++--------- .../src/main/java/bjc/utils/data/ListHolder.java | 14 ++-- .../src/main/java/bjc/utils/data/Option.java | 18 ++--- BJC-Utils2/src/main/java/bjc/utils/data/Pair.java | 28 ++----- .../main/java/bjc/utils/data/SingleIterator.java | 2 + .../main/java/bjc/utils/data/SingleSupplier.java | 10 +-- .../bjc/utils/data/TopDownTransformIterator.java | 87 +++++++++++---------- .../bjc/utils/data/TopDownTransformResult.java | 2 +- .../java/bjc/utils/data/TransformedIterator.java | 2 + BJC-Utils2/src/main/java/bjc/utils/data/Tree.java | 89 ++++++++++------------ .../java/bjc/utils/data/internals/BoundLazy.java | 38 ++++----- .../bjc/utils/data/internals/BoundLazyPair.java | 66 ++++++---------- .../bjc/utils/data/internals/BoundListHolder.java | 26 ++----- .../utils/data/internals/HalfBoundLazyPair.java | 38 ++++----- .../java/bjc/utils/data/internals/WrappedLazy.java | 6 +- .../bjc/utils/data/internals/WrappedOption.java | 22 ++---- 23 files changed, 314 insertions(+), 446 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/data') diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/CircularIterator.java b/BJC-Utils2/src/main/java/bjc/utils/data/CircularIterator.java index 8e0bf86..7131114 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/CircularIterator.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/CircularIterator.java @@ -3,8 +3,8 @@ package bjc.utils.data; import java.util.Iterator; public class CircularIterator implements Iterator { - private Iterable source; - private Iterator curr; + private Iterable source; + private Iterator curr; private E curElm; @@ -21,18 +21,19 @@ public class CircularIterator implements Iterator { this(src, true); } + @Override public boolean hasNext() { // We always have something return true; } + @Override public E next() { - if (!curr.hasNext()) { - if (doCircle) { + if(!curr.hasNext()) { + if(doCircle) { curr = source.iterator(); - } else { + } else return curElm; - } } curElm = curr.next(); @@ -40,6 +41,7 @@ public class CircularIterator implements Iterator { return curElm; } + @Override public void remove() { curr.remove(); } diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Either.java b/BJC-Utils2/src/main/java/bjc/utils/data/Either.java index 7ec1720..d34f752 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Either.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Either.java @@ -5,7 +5,7 @@ import java.util.function.Function; /** * Represents a pair where only one side has a value - * + * * @author ben * @param * The type that could be on the left @@ -16,7 +16,7 @@ import java.util.function.Function; public class Either implements IPair { /** * Create a new either with the left value occupied - * + * * @param * The type of the left value * @param @@ -31,7 +31,7 @@ public class Either implements IPair { /** * Create a new either with the right value occupied - * + * * @param * The type of the empty left value * @param @@ -51,7 +51,7 @@ public class Either implements IPair { private boolean isLeft; private Either(LeftType left, RightType right) { - if (left == null) { + if(left == null) { rightVal = right; } else { leftVal = left; @@ -63,9 +63,7 @@ public class Either implements IPair { @Override public IPair bind( BiFunction> binder) { - if (binder == null) { - throw new NullPointerException("Binder must not be null"); - } + if(binder == null) throw new NullPointerException("Binder must not be null"); return binder.apply(leftVal, rightVal); } @@ -73,13 +71,9 @@ public class Either implements IPair { @Override public IPair bindLeft( Function> leftBinder) { - if (leftBinder == null) { - throw new NullPointerException("Left binder must not be null"); - } + if(leftBinder == null) throw new NullPointerException("Left binder must not be null"); - if (isLeft) { - return leftBinder.apply(leftVal); - } + if(isLeft) return leftBinder.apply(leftVal); return new Either<>(null, rightVal); } @@ -87,13 +81,9 @@ public class Either implements IPair { @Override public IPair bindRight( Function> rightBinder) { - if (rightBinder == null) { - throw new NullPointerException("Right binder must not be null"); - } + if(rightBinder == null) throw new NullPointerException("Right binder must not be null"); - if (isLeft) { - return new Either<>(leftVal, null); - } + if(isLeft) return new Either<>(leftVal, null); return rightBinder.apply(rightVal); } @@ -103,19 +93,15 @@ public class Either implements IPair { IPair otherPair, BiFunction leftCombiner, BiFunction rightCombiner) { - if (otherPair == null) { + if(otherPair == null) throw new NullPointerException("Other pair must not be null"); - } else if (leftCombiner == null) { + else if(leftCombiner == null) throw new NullPointerException("Left combiner must not be null"); - } else if (rightCombiner == null) { - throw new NullPointerException("Right combiner must not be null"); - } + else if(rightCombiner == null) throw new NullPointerException("Right combiner must not be null"); - if (isLeft) { - return otherPair.bind((otherLeft, otherRight) -> { - return new Either<>(leftCombiner.apply(leftVal, otherLeft), null); - }); - } + if(isLeft) return otherPair.bind((otherLeft, otherRight) -> { + return new Either<>(leftCombiner.apply(leftVal, otherLeft), null); + }); return otherPair.bind((otherLeft, otherRight) -> { return new Either<>(null, rightCombiner.apply(rightVal, otherRight)); @@ -124,35 +110,25 @@ public class Either implements IPair { @Override public IPair mapLeft(Function mapper) { - if (mapper == null) { - throw new NullPointerException("Mapper must not be null"); - } + if(mapper == null) throw new NullPointerException("Mapper must not be null"); - if (isLeft) { - return new Either<>(mapper.apply(leftVal), null); - } + if(isLeft) return new Either<>(mapper.apply(leftVal), null); return new Either<>(null, rightVal); } @Override public IPair mapRight(Function mapper) { - if (mapper == null) { - throw new NullPointerException("Mapper must not be null"); - } + if(mapper == null) throw new NullPointerException("Mapper must not be null"); - if (isLeft) { - return new Either<>(leftVal, null); - } + if(isLeft) return new Either<>(leftVal, null); return new Either<>(null, mapper.apply(rightVal)); } @Override public MergedType merge(BiFunction merger) { - if (merger == null) { - throw new NullPointerException("Merger must not be null"); - } + if(merger == null) throw new NullPointerException("Merger must not be null"); return merger.apply(leftVal, rightVal); } diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java index 7b6c8d5..999f3da 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java @@ -1,18 +1,18 @@ package bjc.utils.data; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.UnaryOperator; - import bjc.utils.data.internals.BoundListHolder; import bjc.utils.data.internals.WrappedLazy; import bjc.utils.data.internals.WrappedOption; import bjc.utils.funcdata.FunctionalList; import bjc.utils.funcdata.theory.Functor; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.UnaryOperator; + /** * A holder of a single value. - * + * * @author ben * * @param @@ -21,7 +21,7 @@ import bjc.utils.funcdata.theory.Functor; public interface IHolder extends Functor { /** * Bind a function across the value in this container - * + * * @param * The type of value in this container * @param binder @@ -32,7 +32,7 @@ public interface IHolder extends Functor { /** * Apply an action to the value - * + * * @param action * The action to apply to the value */ @@ -48,10 +48,8 @@ public interface IHolder extends Functor { default Function, Functor> fmap( Function func) { return (argumentFunctor) -> { - if (!(argumentFunctor instanceof IHolder)) { - throw new IllegalArgumentException( - "This functor only supports mapping over instances of IHolder"); - } + if(!(argumentFunctor instanceof IHolder)) throw new IllegalArgumentException( + "This functor only supports mapping over instances of IHolder"); IHolder holder = (IHolder) argumentFunctor; @@ -66,7 +64,7 @@ public interface IHolder extends Functor { /** * Lifts a function to bind over this holder - * + * * @param * The type of the functions return * @param func @@ -77,7 +75,7 @@ public interface IHolder extends Functor { /** * Make this holder lazy - * + * * @return A lazy version of this holder */ public default IHolder makeLazy() { @@ -86,7 +84,7 @@ public interface IHolder extends Functor { /** * Make this holder a list - * + * * @return A list version of this holder */ public default IHolder makeList() { @@ -95,7 +93,7 @@ public interface IHolder extends Functor { /** * Make this holder optional - * + * * @return An optional version of this holder */ public default IHolder makeOptional() { @@ -105,9 +103,9 @@ public interface IHolder extends Functor { /** * Create a new holder with a mapped version of the value in this * holder. - * + * * Does not change the internal state of this holder - * + * * @param * The type of the mapped value * @param mapper @@ -118,7 +116,7 @@ public interface IHolder extends Functor { /** * Replace the held value with a new one - * + * * @param newValue * The value to hold instead * @return The holder itself @@ -131,7 +129,7 @@ public interface IHolder extends Functor { /** * Transform the value held in this holder - * + * * @param transformer * The function to transform the value with * @return The holder itself, for easy chaining @@ -141,7 +139,7 @@ public interface IHolder extends Functor { /** * Unwrap the value contained in this holder so that it is no longer * held - * + * * @param * The type of the unwrapped value * @param unwrapper diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java index 1405d75..24e0381 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/IPair.java @@ -1,14 +1,14 @@ package bjc.utils.data; +import bjc.utils.funcdata.theory.Bifunctor; + import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Function; -import bjc.utils.funcdata.theory.Bifunctor; - /** * Represents a pair of values - * + * * @author ben * @param * The type of the left side of the pair @@ -19,7 +19,7 @@ import bjc.utils.funcdata.theory.Bifunctor; public interface IPair extends Bifunctor { /** * Bind a function across the values in this pair - * + * * @param * The type of the bound left * @param @@ -33,7 +33,7 @@ public interface IPair extends Bifunctor * The type of the bound value * @param leftBinder @@ -45,7 +45,7 @@ public interface IPair extends Bifunctor * The type of the bound value * @param rightBinder @@ -57,7 +57,7 @@ public interface IPair extends Bifunctor * The left type of the other pair * @param @@ -74,7 +74,7 @@ public interface IPair extends Bifunctor * The type of the left value of the other pair * @param @@ -97,7 +97,7 @@ public interface IPair extends Bifunctor extends Bifunctor Function, Bifunctor> fmapLeft( Function func) { return (argumentPair) -> { - if (!(argumentPair instanceof IPair)) { - throw new IllegalArgumentException( - "This function can only be applied to instances of IPair"); - } + if(!(argumentPair instanceof IPair)) throw new IllegalArgumentException( + "This function can only be applied to instances of IPair"); IPair argPair = (IPair) argumentPair; @@ -129,10 +127,8 @@ public interface IPair extends Bifunctor func) { return (argumentPair) -> { - if (!(argumentPair instanceof IPair)) { - throw new IllegalArgumentException( - "This function can only be applied to instances of IPair"); - } + if(!(argumentPair instanceof IPair)) throw new IllegalArgumentException( + "This function can only be applied to instances of IPair"); IPair argPair = (IPair) argumentPair; @@ -142,7 +138,7 @@ public interface IPair extends Bifunctor extends Bifunctor extends Bifunctor * The new type of the left part of the pair * @param mapper @@ -176,7 +172,7 @@ public interface IPair extends Bifunctor * The new type of the right part of the pair * @param mapper @@ -188,7 +184,7 @@ public interface IPair extends Bifunctor * The type of the single value * @param merger diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/ITree.java b/BJC-Utils2/src/main/java/bjc/utils/data/ITree.java index 4b6725c..63a82b8 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/ITree.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/ITree.java @@ -1,16 +1,16 @@ package bjc.utils.data; +import bjc.utils.funcdata.IList; +import bjc.utils.funcdata.bst.TreeLinearizationMethod; + import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; import java.util.function.UnaryOperator; -import bjc.utils.funcdata.IList; -import bjc.utils.funcdata.bst.TreeLinearizationMethod; - /** * A node in a homogenous tree with a unlimited amount of children - * + * * @author ben * @param * The type of data contained in the tree nodes @@ -19,7 +19,7 @@ import bjc.utils.funcdata.bst.TreeLinearizationMethod; public interface ITree { /** * Add a child to this node - * + * * @param child * The child to add to this node */ @@ -27,7 +27,7 @@ public interface ITree { /** * Collapse a tree into a single version - * + * * @param * The intermediate type being folded * @param @@ -48,7 +48,7 @@ public interface ITree { /** * Execute a given action for each of this tree's children - * + * * @param action * The action to execute for each child */ @@ -57,7 +57,7 @@ public interface ITree { /** * Expand the nodes of a tree into trees, and then merge the contents of * those trees into a single tree - * + * * @param mapper * The function to use to map values into trees * @return A tree, with some nodes expanded into trees @@ -66,7 +66,7 @@ public interface ITree { /** * Get the specified child of this tree - * + * * @param childNo * The number of the child to get * @return The specified child of this tree @@ -77,14 +77,14 @@ public interface ITree { /** * Get a count of the number of direct children this node has - * + * * @return The number of direct children this node has */ public int getChildrenCount(); /** * Get the data stored in this node - * + * * @return The data stored in this node */ default ContainedType getHead() { @@ -93,7 +93,7 @@ public interface ITree { /** * Rebuild the tree with the same structure, but different nodes - * + * * @param * The type of the new tree * @param leafTransformer @@ -107,7 +107,7 @@ public interface ITree { /** * Transform some of the nodes in this tree - * + * * @param nodePicker * The predicate to use to pick nodes to transform * @param transformer @@ -117,7 +117,7 @@ public interface ITree { /** * Do a top-down transform of the tree - * + * * @param transformPicker * The function to use to pick how to progress * @param transformer @@ -129,7 +129,7 @@ public interface ITree { /** * Transform one of this nodes children - * + * * @param * The type of the transformed value * @param childNo @@ -137,7 +137,7 @@ public interface ITree { * @param transformer * The function to use to transform the value * @return The transformed value - * + * * @throws IllegalArgumentException * if the childNo is out of bounds (0 <= childNo <= * childCount()) @@ -147,7 +147,7 @@ public interface ITree { /** * Transform the value that is the head of this node - * + * * @param * The type of the transformed value * @param transformer @@ -158,7 +158,7 @@ public interface ITree { /** * Transform the tree into a tree with a different type of token - * + * * @param * The type of the new tree * @param transformer @@ -169,7 +169,7 @@ public interface ITree { /** * Perform an action on each part of the tree - * + * * @param linearizationMethod * The way to traverse the tree * @param action diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Identity.java b/BJC-Utils2/src/main/java/bjc/utils/data/Identity.java index aa3f7aa..9c4ea45 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Identity.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Identity.java @@ -10,7 +10,7 @@ import java.util.function.UnaryOperator; */ /** * Simple implementation of IHolder that has no hidden behavior - * + * * @author ben * * @param @@ -28,7 +28,7 @@ public class Identity implements IHolder { /** * Create a holder holding the specified value - * + * * @param value * The value to hold */ @@ -43,35 +43,29 @@ public class Identity implements IHolder { /* * (non-Javadoc) - * + * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { - if (this == obj) { + if(this == obj) return true; - } else if (obj == null) { - return false; - } else if (getClass() != obj.getClass()) { + else if(obj == null) return false; - } + else if(getClass() != obj.getClass()) return false; Identity other = (Identity) obj; - if (heldValue == null) { - if (other.heldValue != null) { - return false; - } - } else if (!heldValue.equals(other.heldValue)) { - return false; - } + if(heldValue == null) { + if(other.heldValue != null) return false; + } else if(!heldValue.equals(other.heldValue)) return false; return true; } /* * (non-Javadoc) - * + * * @see java.lang.Object#hashCode() */ @Override @@ -80,7 +74,7 @@ public class Identity implements IHolder { int result = 1; - int fieldHash = (heldValue == null) ? 0 : heldValue.hashCode(); + int fieldHash = heldValue == null ? 0 : heldValue.hashCode(); result = prime * result + fieldHash; 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 3a037d7..d4d350a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java @@ -1,17 +1,17 @@ package bjc.utils.data; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.function.UnaryOperator; - import bjc.utils.data.internals.BoundLazy; import bjc.utils.funcdata.FunctionalList; import bjc.utils.funcdata.IList; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.function.UnaryOperator; + /** * A holder that holds a means to create a value, but doesn't actually compute * the value until it's needed - * + * * @author ben * * @param @@ -27,7 +27,7 @@ public class Lazy implements IHolder { /** * Create a new lazy value from the specified seed value - * + * * @param value * The seed value to use */ @@ -39,7 +39,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 */ @@ -62,9 +62,7 @@ public class Lazy implements IHolder { actions.forEach(pendingActions::add); Supplier supplier = () -> { - if (valueMaterialized) { - return heldValue; - } + if(valueMaterialized) return heldValue; return valueSupplier.get(); }; @@ -90,7 +88,7 @@ public class Lazy implements IHolder { return new Lazy<>(() -> { ContainedType currVal = heldValue; - if (!valueMaterialized) { + if(!valueMaterialized) { currVal = valueSupplier.get(); } @@ -101,10 +99,8 @@ public class Lazy implements IHolder { @Override public String toString() { - if (valueMaterialized) { - if (actions.isEmpty()) { - return "value[v='" + heldValue + "']"; - } + if(valueMaterialized) { + if(actions.isEmpty()) return "value[v='" + heldValue + "']"; return "value[v='" + heldValue + "'] (has pending transforms)"; } @@ -121,7 +117,7 @@ public class Lazy implements IHolder { @Override public UnwrappedType unwrap(Function unwrapper) { - if (!valueMaterialized) { + if(!valueMaterialized) { heldValue = valueSupplier.get(); valueMaterialized = true; diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java index 29e37ac..59df1b1 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/LazyPair.java @@ -1,36 +1,36 @@ package bjc.utils.data; +import bjc.utils.data.internals.BoundLazyPair; +import bjc.utils.data.internals.HalfBoundLazyPair; + import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Supplier; -import bjc.utils.data.internals.BoundLazyPair; -import bjc.utils.data.internals.HalfBoundLazyPair; - /** * A lazy implementation of a pair - * + * * @author ben * * @param * The type on the left side of the pair * @param * The type on the right side of the pair - * + * */ public class LazyPair implements IPair { - private LeftType leftValue; - private RightType rightValue; + private LeftType leftValue; + private RightType rightValue; - private Supplier leftSupplier; - private Supplier rightSupplier; + private Supplier leftSupplier; + private Supplier rightSupplier; - private boolean leftMaterialized; - private boolean rightMaterialized; + private boolean leftMaterialized; + private boolean rightMaterialized; /** * Create a new lazy pair, using the set values - * + * * @param leftVal * The value for the left side of the pair * @param rightVal @@ -46,7 +46,7 @@ public class LazyPair implements IPair /** * Create a new lazy pair from the given value sources - * + * * @param leftSupp * The source for a value on the left side of the pair * @param rightSupp @@ -71,9 +71,7 @@ public class LazyPair implements IPair public IPair bindLeft( Function> leftBinder) { Supplier leftSupp = () -> { - if (leftMaterialized) { - return leftValue; - } + if(leftMaterialized) return leftValue; return leftSupplier.get(); }; @@ -85,9 +83,7 @@ public class LazyPair implements IPair public IPair bindRight( Function> rightBinder) { Supplier rightSupp = () -> { - if (rightMaterialized) { - return rightValue; - } + if(rightMaterialized) return rightValue; return rightSupplier.get(); }; @@ -110,7 +106,7 @@ public class LazyPair implements IPair @Override public LeftType getLeft() { - if (!leftMaterialized) { + if(!leftMaterialized) { leftValue = leftSupplier.get(); leftMaterialized = true; @@ -121,7 +117,7 @@ public class LazyPair implements IPair @Override public RightType getRight() { - if (!rightMaterialized) { + if(!rightMaterialized) { rightValue = rightSupplier.get(); rightMaterialized = true; @@ -133,17 +129,13 @@ public class LazyPair implements IPair @Override public IPair mapLeft(Function mapper) { Supplier leftSupp = () -> { - if (leftMaterialized) { - return mapper.apply(leftValue); - } + if(leftMaterialized) return mapper.apply(leftValue); return mapper.apply(leftSupplier.get()); }; Supplier rightSupp = () -> { - if (rightMaterialized) { - return rightValue; - } + if(rightMaterialized) return rightValue; return rightSupplier.get(); }; @@ -154,17 +146,13 @@ public class LazyPair implements IPair @Override public IPair mapRight(Function mapper) { Supplier leftSupp = () -> { - if (leftMaterialized) { - return leftValue; - } + if(leftMaterialized) return leftValue; return leftSupplier.get(); }; Supplier rightSupp = () -> { - if (rightMaterialized) { - return mapper.apply(rightValue); - } + if(rightMaterialized) return mapper.apply(rightValue); return mapper.apply(rightSupplier.get()); }; @@ -174,13 +162,13 @@ public class LazyPair implements IPair @Override public MergedType merge(BiFunction merger) { - if (!leftMaterialized) { + if(!leftMaterialized) { leftValue = leftSupplier.get(); leftMaterialized = true; } - if (!rightMaterialized) { + if(!rightMaterialized) { rightValue = rightSupplier.get(); rightMaterialized = true; @@ -193,7 +181,7 @@ public class LazyPair implements IPair public String toString() { StringBuilder sb = new StringBuilder("pair[l="); - if (leftMaterialized) { + if(leftMaterialized) { sb.append(leftValue.toString()); } else { sb.append("(un-materialized)"); @@ -201,7 +189,7 @@ public class LazyPair implements IPair sb.append(", r="); - if (rightMaterialized) { + if(rightMaterialized) { sb.append(rightValue.toString()); } else { sb.append("(un-materialized)"); diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java index 5c14475..84ea01d 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java @@ -1,15 +1,15 @@ package bjc.utils.data; -import java.util.function.Function; -import java.util.function.UnaryOperator; - import bjc.utils.data.internals.BoundListHolder; import bjc.utils.funcdata.FunctionalList; import bjc.utils.funcdata.IList; +import java.util.function.Function; +import java.util.function.UnaryOperator; + /** * A holder that represents a set of non-deterministic computations - * + * * @author ben * * @param @@ -20,7 +20,7 @@ public class ListHolder implements IHolder { /** * Create a new list holder - * + * * @param values * The possible values for the computation */ @@ -28,8 +28,8 @@ public class ListHolder implements IHolder { public ListHolder(ContainedType... values) { heldValues = new FunctionalList<>(); - if (values != null) { - for (ContainedType containedValue : values) { + if(values != null) { + for(ContainedType containedValue : values) { heldValues.add(containedValue); } } diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Option.java b/BJC-Utils2/src/main/java/bjc/utils/data/Option.java index 210d2aa..052e78a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Option.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Option.java @@ -5,7 +5,7 @@ import java.util.function.UnaryOperator; /** * A holder that may or may not contain a value - * + * * @author ben * * @param @@ -16,7 +16,7 @@ public class Option implements IHolder { /** * Create a new optional, using the given initial value - * + * * @param seed * The initial value for the optional */ @@ -26,9 +26,7 @@ public class Option implements IHolder { @Override public IHolder bind(Function> binder) { - if (held == null) { - return new Option<>(null); - } + if(held == null) return new Option<>(null); return binder.apply(held); } @@ -42,16 +40,14 @@ public class Option implements IHolder { @Override public IHolder map(Function mapper) { - if (held == null) { - return new Option<>(null); - } + if(held == null) return new Option<>(null); return new Option<>(mapper.apply(held)); } @Override public IHolder transform(UnaryOperator transformer) { - if (held != null) { + if(held != null) { held = transformer.apply(held); } @@ -60,9 +56,7 @@ public class Option implements IHolder { @Override public UnwrappedType unwrap(Function unwrapper) { - if (held == null) { - return null; - } + if(held == null) return null; return unwrapper.apply(held); } diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java index b22fd28..77afa4a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java @@ -5,7 +5,7 @@ import java.util.function.Function; /** * A pair of values, with nothing special about them. - * + * * @author ben * * @param @@ -29,7 +29,7 @@ public class Pair implements IPair { /** * Create a new pair with both sides set to the specified values - * + * * @param left * The value of the left side * @param right @@ -43,9 +43,7 @@ public class Pair implements IPair { @Override public IPair bind( BiFunction> binder) { - if (binder == null) { - throw new NullPointerException("Binder must not be null."); - } + if(binder == null) throw new NullPointerException("Binder must not be null."); return binder.apply(leftValue, rightValue); } @@ -53,9 +51,7 @@ public class Pair implements IPair { @Override public IPair bindLeft( Function> leftBinder) { - if (leftBinder == null) { - throw new NullPointerException("Binder must not be null"); - } + if(leftBinder == null) throw new NullPointerException("Binder must not be null"); return leftBinder.apply(leftValue); } @@ -63,9 +59,7 @@ public class Pair implements IPair { @Override public IPair bindRight( Function> rightBinder) { - if (rightBinder == null) { - throw new NullPointerException("Binder must not be null"); - } + if(rightBinder == null) throw new NullPointerException("Binder must not be null"); return rightBinder.apply(rightValue); } @@ -83,27 +77,21 @@ public class Pair implements IPair { @Override public IPair mapLeft(Function mapper) { - if (mapper == null) { - throw new NullPointerException("Mapper must not be null"); - } + if(mapper == null) throw new NullPointerException("Mapper must not be null"); return new Pair<>(mapper.apply(leftValue), rightValue); } @Override public IPair mapRight(Function mapper) { - if (mapper == null) { - throw new NullPointerException("Mapper must not be null"); - } + if(mapper == null) throw new NullPointerException("Mapper must not be null"); return new Pair<>(leftValue, mapper.apply(rightValue)); } @Override public MergedType merge(BiFunction merger) { - if (merger == null) { - throw new NullPointerException("Merger must not be null"); - } + if(merger == null) throw new NullPointerException("Merger must not be null"); return merger.apply(leftValue, rightValue); } diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/SingleIterator.java b/BJC-Utils2/src/main/java/bjc/utils/data/SingleIterator.java index fde1197..4d79b92 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/SingleIterator.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/SingleIterator.java @@ -13,10 +13,12 @@ public class SingleIterator implements Iterator { yielded = false; } + @Override public boolean hasNext() { return !yielded; } + @Override public T next() { yielded = true; diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java b/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java index bf8b0a0..76c9be2 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java @@ -4,9 +4,9 @@ import java.util.function.Supplier; /** * A supplier that can only supply one value. - * + * * Attempting to retrieve another value will cause an exception to be thrown. - * + * * @author ben * * @param @@ -26,7 +26,7 @@ public class SingleSupplier implements Supplier { /** * Create a new single supplier from an existing value - * + * * @param supp * The supplier to give a single value from */ @@ -40,7 +40,7 @@ public class SingleSupplier implements Supplier { @Override public T get() { - if (gotten == true) { + if(gotten == true) { IllegalStateException isex = new IllegalStateException("Attempted to get value more than once" + " from single supplier #" + id + ". Previous instantiation below."); @@ -53,7 +53,7 @@ public class SingleSupplier implements Supplier { try { throw new IllegalStateException("Previous instantiation here."); - } catch (IllegalStateException isex) { + } catch(IllegalStateException isex) { instSite = isex; } diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformIterator.java b/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformIterator.java index 8a24512..2463df9 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformIterator.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformIterator.java @@ -8,25 +8,25 @@ import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Function; -import static bjc.utils.data.TopDownTransformResult.*; +import static bjc.utils.data.TopDownTransformResult.RTRANSFORM; public class TopDownTransformIterator implements Iterator> { - private Function picker; - private BiFunction, Consumer>>, ITree> transform; + private Function picker; + private BiFunction, Consumer>>, ITree> transform; - private ITree preParent; - private ITree postParent; + private ITree preParent; + private ITree postParent; - private Deque> preChildren; - private Deque> postChildren; + private Deque> preChildren; + private Deque> postChildren; private TopDownTransformIterator curChild; - private boolean done; - private boolean initial; + private boolean done; + private boolean initial; - private Deque>> toYield; - private Iterator> curYield; + private Deque>> toYield; + private Iterator> curYield; public TopDownTransformIterator(Function pickr, BiFunction, Consumer>>, ITree> transfrm, @@ -45,69 +45,67 @@ public class TopDownTransformIterator implements Iterator> src) { - if (curYield != null) { + if(curYield != null) { toYield.push(curYield); } curYield = src; } + @Override public boolean hasNext() { return !done; } public ITree flushYields(ITree val) { - if (curYield != null) { + if(curYield != null) { toYield.add(new SingleIterator<>(val)); - if (curYield.hasNext()) { + if(curYield.hasNext()) return curYield.next(); - } else { - while (toYield.size() != 0 && !curYield.hasNext()) { + else { + while(toYield.size() != 0 && !curYield.hasNext()) { curYield = toYield.pop(); } - if (toYield.size() == 0 && !curYield.hasNext()) { + if(toYield.size() == 0 && !curYield.hasNext()) { curYield = null; return val; - } else { + } else return curYield.next(); - } } - } else { + } else return val; - } } + @Override public ITree next() { - if (done) - throw new NoSuchElementException(); + if(done) throw new NoSuchElementException(); - if (curYield != null) { - if (curYield.hasNext()) { + if(curYield != null) { + if(curYield.hasNext()) return curYield.next(); - } else { - while (toYield.size() != 0 && !curYield.hasNext()) { + else { + while(toYield.size() != 0 && !curYield.hasNext()) { curYield = toYield.pop(); } - if (toYield.size() == 0 && !curYield.hasNext()) { + if(toYield.size() == 0 && !curYield.hasNext()) { curYield = null; - } else { + } else return curYield.next(); - } } } - if (initial) { + if(initial) { TopDownTransformResult res = picker.apply(preParent.getHead()); - switch (res) { + switch(res) { case PASSTHROUGH: postParent = new Tree<>(preParent.getHead()); - if (preParent.getChildrenCount() != 0) { - for (int i = 0; i < preParent.getChildrenCount(); i++) { + if(preParent.getChildrenCount() != 0) { + for(int i = 0; i < preParent.getChildrenCount(); i++) { preChildren.add(preParent.getChild(i)); } @@ -127,8 +125,8 @@ public class TopDownTransformIterator implements Iterator implements Iterator(intRes.getHead()); - if (intRes.getChildrenCount() != 0) { - for (int i = 0; i < intRes.getChildrenCount(); i++) { + if(intRes.getChildrenCount() != 0) { + for(int i = 0; i < intRes.getChildrenCount(); i++) { preChildren.add(intRes.getChild(i)); } @@ -159,12 +157,13 @@ public class TopDownTransformIterator implements Iterator(picker, transform, preChildren.pop()); ITree res = curChild.next(); @@ -175,12 +174,12 @@ public class TopDownTransformIterator implements Iterator res = null; - if (postParent == null) { + if(postParent == null) { res = new Tree<>(preParent.getHead()); System.out.println("\t\tTRACE: adding nodes " + postChildren + " to " + res); - for (ITree child : postChildren) { + for(ITree child : postChildren) { res.addChild(child); } @@ -190,7 +189,7 @@ public class TopDownTransformIterator implements Iterator child : postChildren) { + for(ITree child : postChildren) { res.addChild(child); } } diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformResult.java b/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformResult.java index 0db9482..ed41eae 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformResult.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformResult.java @@ -2,7 +2,7 @@ package bjc.utils.data; /** * Represents the results for doing a top-down transform of a tree - * + * * @author ben * */ diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/TransformedIterator.java b/BJC-Utils2/src/main/java/bjc/utils/data/TransformedIterator.java index 742a73b..80de96f 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/TransformedIterator.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/TransformedIterator.java @@ -13,10 +13,12 @@ public class TransformedIterator implements Iterator @@ -19,16 +19,16 @@ import bjc.utils.funcdata.bst.TreeLinearizationMethod; public class Tree implements ITree { private ContainedType data; - private IList> children; - private boolean hasChildren; - private int childCount = 0; + private IList> children; + private boolean hasChildren; + private int childCount = 0; - private int ID; - private static int nextID = 0; + private int ID; + private static int nextID = 0; /** * Create a new leaf node in a tree - * + * * @param leaf * The data to store as a leaf node */ @@ -42,7 +42,7 @@ public class Tree implements ITree { /** * Create a new tree node with the specified children - * + * * @param leaf * The data to hold in this node * @param childrn @@ -58,7 +58,7 @@ public class Tree implements ITree { /** * Create a new tree node with the specified children - * + * * @param leaf * The data to hold in this node * @param childrn @@ -74,7 +74,7 @@ public class Tree implements ITree { children = new FunctionalList<>(); - for (ITree child : childrn) { + for(ITree child : childrn) { children.add(child); childCount++; @@ -83,7 +83,7 @@ public class Tree implements ITree { @Override public void addChild(ITree child) { - if (hasChildren == false) { + if(hasChildren == false) { hasChildren = true; children = new FunctionalList<>(); @@ -109,7 +109,7 @@ public class Tree implements ITree { @Override public ITree flatMapTree(Function> mapper) { - if (hasChildren) { + if(hasChildren) { ITree flatMappedData = mapper.apply(data); children.map((child) -> child.flatMapTree(mapper)) @@ -128,10 +128,10 @@ public class Tree implements ITree { protected NewType internalCollapse(Function leafTransform, Function, NewType>> nodeCollapser) { - if (hasChildren) { + if(hasChildren) { Function, NewType> nodeTransformer = nodeCollapser.apply(data); - IList collapsedChildren = (IList) children.map((child) -> { + IList collapsedChildren = children.map((child) -> { return child.collapse(leafTransform, nodeCollapser, (subTreeVal) -> subTreeVal); }); @@ -142,7 +142,7 @@ public class Tree implements ITree { } protected void internalToString(StringBuilder builder, int indentLevel, boolean initial) { - for (int i = 0; i < indentLevel; i++) { + for(int i = 0; i < indentLevel; i++) { builder.append(">\t"); } @@ -152,7 +152,7 @@ public class Tree implements ITree { builder.append(data == null ? "(null)" : data.toString()); builder.append("\n"); - if (hasChildren) { + if(hasChildren) { children.forEach((child) -> { ((Tree) child).internalToString(builder, indentLevel + 1, false); }); @@ -162,7 +162,7 @@ public class Tree implements ITree { @Override public ITree rebuildTree(Function leafTransformer, Function operatorTransformer) { - if (hasChildren) { + if(hasChildren) { IList> mappedChildren = children.map((child) -> { return child.rebuildTree(leafTransformer, operatorTransformer); }); @@ -175,7 +175,7 @@ public class Tree implements ITree { @Override public void selectiveTransform(Predicate nodePicker, UnaryOperator transformer) { - if (hasChildren) { + if(hasChildren) { children.forEach((child) -> child.selectiveTransform(nodePicker, transformer)); } else { data = transformer.apply(data); @@ -187,11 +187,11 @@ public class Tree implements ITree { UnaryOperator> transformer) { TopDownTransformResult transformResult = transformPicker.apply(data); - switch (transformResult) { + switch(transformResult) { case PASSTHROUGH: ITree result = new Tree<>(data); - if (hasChildren) { + if(hasChildren) { children.forEach((child) -> { result.addChild(child.topDownTransform(transformPicker, transformer)); }); @@ -207,7 +207,7 @@ public class Tree implements ITree { case PUSHDOWN: result = new Tree<>(data); - if (hasChildren) { + if(hasChildren) { children.forEach((child) -> { result.addChild(child.topDownTransform(transformPicker, transformer)); }); @@ -244,9 +244,8 @@ public class Tree implements ITree { @Override public TransformedType transformChild(int childNo, Function, TransformedType> transformer) { - if (childNo < 0 || childNo > (childCount - 1)) { + if(childNo < 0 || childNo > childCount - 1) throw new IllegalArgumentException("Child index #" + childNo + " is invalid"); - } return transformer.apply(children.getByIndex(childNo)); } @@ -258,7 +257,7 @@ public class Tree implements ITree { @Override public ITree transformTree(Function transformer) { - if (hasChildren) { + if(hasChildren) { IList> transformedChildren = children .map((child) -> child.transformTree(transformer)); @@ -270,13 +269,11 @@ public class Tree implements ITree { @Override public void traverse(TreeLinearizationMethod linearizationMethod, Consumer action) { - if (hasChildren) { - switch (linearizationMethod) { + if(hasChildren) { + switch(linearizationMethod) { case INORDER: - if (childCount != 2) { - throw new IllegalArgumentException( - "Can only do in-order traversal for binary trees."); - } + if(childCount != 2) throw new IllegalArgumentException( + "Can only do in-order traversal for binary trees."); children.getByIndex(0).traverse(linearizationMethod, action); @@ -303,32 +300,26 @@ public class Tree implements ITree { } } + @Override public boolean equals(Object other) { - if (!(other instanceof Tree)) - return false; + if(!(other instanceof Tree)) return false; @SuppressWarnings("unchecked") Tree otr = (Tree) other; - if (!otr.data.equals(data)) - return false; + if(!otr.data.equals(data)) return false; - if (children == null && otr.children == null) - return true; + if(children == null && otr.children == null) return true; - if (children == null && otr.children != null) - return false; - if (children != null && otr.children == null) - return false; + if(children == null && otr.children != null) return false; + if(children != null && otr.children == null) return false; - if (children.getSize() != otr.children.getSize()) - return false; + if(children.getSize() != otr.children.getSize()) return false; int childNo = 0; - for (ITree child : children) { - if (!otr.children.getByIndex(childNo).equals(child)) - return false; + for(ITree child : children) { + if(!otr.children.getByIndex(childNo).equals(child)) return false; childNo += 1; } diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazy.java b/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazy.java index 57bf006..0ec69f0 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazy.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazy.java @@ -1,14 +1,14 @@ package bjc.utils.data.internals; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.function.UnaryOperator; - import bjc.utils.data.IHolder; import bjc.utils.data.Lazy; import bjc.utils.funcdata.FunctionalList; import bjc.utils.funcdata.IList; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.function.UnaryOperator; + /** * Implements a lazy holder that has been bound */ @@ -48,9 +48,7 @@ public class BoundLazy implements IHolder IHolder bind(Function> bindr) { - if (bindr == null) { - throw new NullPointerException("Binder must not be null"); - } + if(bindr == null) throw new NullPointerException("Binder must not be null"); /* * Prepare a list of pending actions @@ -67,7 +65,7 @@ public class BoundLazy implements IHolder implements IHolder Function> lift( Function func) { - if (func == null) { - throw new NullPointerException("Function to lift must not be null"); - } + if(func == null) throw new NullPointerException("Function to lift must not be null"); return (val) -> { return new Lazy<>(func.apply(val)); @@ -96,9 +92,7 @@ public class BoundLazy implements IHolder IHolder map(Function mapper) { - if (mapper == null) { - throw new NullPointerException("Mapper must not be null"); - } + if(mapper == null) throw new NullPointerException("Mapper must not be null"); // Prepare a list of pending actions IList> pendingActions = new FunctionalList<>(); @@ -109,7 +103,7 @@ 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); } @@ -123,18 +117,14 @@ public class BoundLazy implements IHolder transform(UnaryOperator transformer) { - if (transformer == null) { - throw new NullPointerException("Transformer must not be null"); - } + if(transformer == null) throw new NullPointerException("Transformer must not be null"); actions.add(transformer); @@ -143,11 +133,9 @@ public class BoundLazy implements IHolder UnwrappedType unwrap(Function unwrapper) { - if (unwrapper == null) { - throw new NullPointerException("Unwrapper must not be null"); - } + if(unwrapper == null) throw new NullPointerException("Unwrapper must not be null"); - if (!holderBound) { + if(!holderBound) { boundHolder = oldSupplier.get().unwrap(binder::apply); } diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazyPair.java index d425d99..6ab8121 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazyPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundLazyPair.java @@ -1,14 +1,14 @@ package bjc.utils.data.internals; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.function.Supplier; - import bjc.utils.data.IHolder; import bjc.utils.data.IPair; import bjc.utils.data.Identity; import bjc.utils.data.LazyPair; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.Supplier; + /** * Implements a lazy pair that has been bound */ @@ -47,15 +47,13 @@ public class BoundLazyPair implements IPai @Override public IPair bind( BiFunction> bindr) { - if (bindr == null) { - throw new NullPointerException("Binder must not be null"); - } + if(bindr == null) throw new NullPointerException("Binder must not be null"); IHolder> newPair = new Identity<>(boundPair); IHolder newPairMade = new Identity<>(pairBound); Supplier leftSupp = () -> { - if (!newPairMade.getValue()) { + if(!newPairMade.getValue()) { newPair.replace(binder.apply(leftSupplier.get(), rightSupplier.get())); newPairMade.replace(true); @@ -65,7 +63,7 @@ public class BoundLazyPair implements IPai }; Supplier rightSupp = () -> { - if (!newPairMade.getValue()) { + if(!newPairMade.getValue()) { newPair.replace(binder.apply(leftSupplier.get(), rightSupplier.get())); newPairMade.replace(true); @@ -80,14 +78,12 @@ public class BoundLazyPair implements IPai @Override public IPair bindLeft( Function> leftBinder) { - if (leftBinder == null) { - throw new NullPointerException("Left binder must not be null"); - } + if(leftBinder == null) throw new NullPointerException("Left binder must not be null"); Supplier leftSupp = () -> { IPair newPair = boundPair; - if (!pairBound) { + if(!pairBound) { newPair = binder.apply(leftSupplier.get(), rightSupplier.get()); } @@ -100,14 +96,12 @@ public class BoundLazyPair implements IPai @Override public IPair bindRight( Function> rightBinder) { - if (rightBinder == null) { - throw new NullPointerException("Right binder must not be null"); - } + if(rightBinder == null) throw new NullPointerException("Right binder must not be null"); Supplier rightSupp = () -> { IPair newPair = boundPair; - if (!pairBound) { + if(!pairBound) { newPair = binder.apply(leftSupplier.get(), rightSupplier.get()); } @@ -122,13 +116,11 @@ public class BoundLazyPair implements IPai IPair otherPair, BiFunction leftCombiner, BiFunction rightCombiner) { - if (otherPair == null) { + if(otherPair == null) throw new NullPointerException("Other pair must not be null"); - } else if (leftCombiner == null) { + else if(leftCombiner == null) throw new NullPointerException("Left combiner must not be null"); - } else if (rightCombiner == null) { - throw new NullPointerException("Right combiner must not be null"); - } + else if(rightCombiner == null) throw new NullPointerException("Right combiner must not be null"); return otherPair.bind((otherLeft, otherRight) -> { return bind((leftVal, rightVal) -> { @@ -140,12 +132,10 @@ public class BoundLazyPair implements IPai @Override public IPair mapLeft(Function mapper) { - if (mapper == null) { - throw new NullPointerException("Mapper must not be null"); - } + if(mapper == null) throw new NullPointerException("Mapper must not be null"); Supplier leftSupp = () -> { - if (!pairBound) { + if(!pairBound) { NewLeft leftVal = binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft(); return mapper.apply(leftVal); @@ -155,9 +145,7 @@ public class BoundLazyPair implements IPai }; Supplier rightSupp = () -> { - if (!pairBound) { - return binder.apply(leftSupplier.get(), rightSupplier.get()).getRight(); - } + if(!pairBound) return binder.apply(leftSupplier.get(), rightSupplier.get()).getRight(); return boundPair.getRight(); }; @@ -167,20 +155,16 @@ public class BoundLazyPair implements IPai @Override public IPair mapRight(Function mapper) { - if (mapper == null) { - throw new NullPointerException("Mapper must not be null"); - } + if(mapper == null) throw new NullPointerException("Mapper must not be null"); Supplier leftSupp = () -> { - if (!pairBound) { - return binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft(); - } + if(!pairBound) return binder.apply(leftSupplier.get(), rightSupplier.get()).getLeft(); return boundPair.getLeft(); }; Supplier rightSupp = () -> { - if (!pairBound) { + if(!pairBound) { NewRight rightVal = binder.apply(leftSupplier.get(), rightSupplier.get()).getRight(); return mapper.apply(rightVal); @@ -194,11 +178,9 @@ public class BoundLazyPair implements IPai @Override public MergedType merge(BiFunction merger) { - if (merger == null) { - throw new NullPointerException("Merger must not be null"); - } + if(merger == null) throw new NullPointerException("Merger must not be null"); - if (!pairBound) { + if(!pairBound) { boundPair = binder.apply(leftSupplier.get(), rightSupplier.get()); pairBound = true; @@ -209,9 +191,7 @@ public class BoundLazyPair implements IPai @Override public String toString() { - if (pairBound) { - return boundPair.toString(); - } + if(pairBound) return boundPair.toString(); return "(un-materialized)"; } diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundListHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundListHolder.java index f363b7e..467d55d 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundListHolder.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/internals/BoundListHolder.java @@ -1,12 +1,12 @@ package bjc.utils.data.internals; -import java.util.function.Function; -import java.util.function.UnaryOperator; - import bjc.utils.data.IHolder; import bjc.utils.data.ListHolder; import bjc.utils.funcdata.IList; +import java.util.function.Function; +import java.util.function.UnaryOperator; + /* * Holds a list, converted into a holder */ @@ -19,9 +19,7 @@ public class BoundListHolder implements IHolder { @Override public IHolder bind(Function> binder) { - if (binder == null) { - throw new NullPointerException("Binder must not be null"); - } + if(binder == null) throw new NullPointerException("Binder must not be null"); IList> boundHolders = heldHolders.map((containedHolder) -> { return containedHolder.bind(binder); @@ -32,9 +30,7 @@ public class BoundListHolder implements IHolder { @Override public Function> lift(Function func) { - if (func == null) { - throw new NullPointerException("Function to lift must not be null"); - } + if(func == null) throw new NullPointerException("Function to lift must not be null"); return (val) -> { return new ListHolder<>(func.apply(val)); @@ -43,9 +39,7 @@ public class BoundListHolder implements IHolder { @Override public IHolder map(Function mapper) { - if (mapper == null) { - throw new NullPointerException("Mapper must not be null"); - } + if(mapper == null) throw new NullPointerException("Mapper must not be null"); IList> mappedHolders = heldHolders.map((containedHolder) -> { return containedHolder.map(mapper); @@ -56,9 +50,7 @@ public class BoundListHolder implements IHolder { @Override public IHolder transform(UnaryOperator transformer) { - if (transformer == null) { - throw new NullPointerException("Transformer must not be null"); - } + if(transformer == null) throw new NullPointerException("Transformer must not be null"); heldHolders.forEach((containedHolder) -> { containedHolder.transform(transformer); @@ -69,9 +61,7 @@ public class BoundListHolder implements IHolder { @Override public UnwrappedType unwrap(Function unwrapper) { - if (unwrapper == null) { - throw new NullPointerException("Unwrapper must not be null"); - } + if(unwrapper == null) throw new NullPointerException("Unwrapper must not be null"); return heldHolders.randItem().unwrap(unwrapper); } diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java index a8bdb6a..c5e9c9f 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/internals/HalfBoundLazyPair.java @@ -1,14 +1,14 @@ package bjc.utils.data.internals; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.function.Supplier; - import bjc.utils.data.IHolder; import bjc.utils.data.IPair; import bjc.utils.data.Identity; import bjc.utils.data.LazyPair; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.Supplier; + /* * A lazy pair, with only one side bound */ @@ -17,8 +17,8 @@ public class HalfBoundLazyPair implements IPair> binder; - private IPair boundPair; - private boolean pairBound; + private IPair boundPair; + private boolean pairBound; public HalfBoundLazyPair(Supplier oldSupp, Function> bindr) { oldSupplier = oldSupp; @@ -32,7 +32,7 @@ public class HalfBoundLazyPair implements IPair newPairMade = new Identity<>(pairBound); Supplier leftSupp = () -> { - if (!newPairMade.getValue()) { + if(!newPairMade.getValue()) { newPair.replace(binder.apply(oldSupplier.get())); newPairMade.replace(true); } @@ -41,7 +41,7 @@ public class HalfBoundLazyPair implements IPair rightSupp = () -> { - if (!newPairMade.getValue()) { + if(!newPairMade.getValue()) { newPair.replace(binder.apply(oldSupplier.get())); newPairMade.replace(true); } @@ -58,7 +58,7 @@ public class HalfBoundLazyPair implements IPair leftSupp = () -> { IPair newPair = boundPair; - if (!pairBound) { + if(!pairBound) { newPair = binder.apply(oldSupplier.get()); } @@ -74,7 +74,7 @@ public class HalfBoundLazyPair implements IPair rightSupp = () -> { IPair newPair = boundPair; - if (!pairBound) { + if(!pairBound) { newPair = binder.apply(oldSupplier.get()); } @@ -100,9 +100,7 @@ public class HalfBoundLazyPair implements IPair IPair mapLeft(Function mapper) { Supplier leftSupp = () -> { - if (pairBound) { - return mapper.apply(boundPair.getLeft()); - } + if(pairBound) return mapper.apply(boundPair.getLeft()); NewLeft leftVal = binder.apply(oldSupplier.get()).getLeft(); @@ -110,9 +108,7 @@ public class HalfBoundLazyPair implements IPair rightSupp = () -> { - if (pairBound) { - return boundPair.getRight(); - } + if(pairBound) return boundPair.getRight(); return binder.apply(oldSupplier.get()).getRight(); }; @@ -123,17 +119,13 @@ public class HalfBoundLazyPair implements IPair IPair mapRight(Function mapper) { Supplier leftSupp = () -> { - if (pairBound) { - return boundPair.getLeft(); - } + if(pairBound) return boundPair.getLeft(); return binder.apply(oldSupplier.get()).getLeft(); }; Supplier rightSupp = () -> { - if (pairBound) { - return mapper.apply(boundPair.getRight()); - } + if(pairBound) return mapper.apply(boundPair.getRight()); NewRight rightVal = binder.apply(oldSupplier.get()).getRight(); @@ -145,7 +137,7 @@ public class HalfBoundLazyPair implements IPair MergedType merge(BiFunction merger) { - if (!pairBound) { + if(!pairBound) { boundPair = binder.apply(oldSupplier.get()); pairBound = true; diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedLazy.java b/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedLazy.java index 7f0b8db..f400345 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedLazy.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedLazy.java @@ -1,11 +1,11 @@ package bjc.utils.data.internals; -import java.util.function.Function; -import java.util.function.UnaryOperator; - import bjc.utils.data.IHolder; import bjc.utils.data.Lazy; +import java.util.function.Function; +import java.util.function.UnaryOperator; + public class WrappedLazy implements IHolder { private IHolder> held; diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedOption.java b/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedOption.java index 2b03f62..1639351 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedOption.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/internals/WrappedOption.java @@ -1,11 +1,11 @@ package bjc.utils.data.internals; -import java.util.function.Function; -import java.util.function.UnaryOperator; - import bjc.utils.data.IHolder; import bjc.utils.data.Option; +import java.util.function.Function; +import java.util.function.UnaryOperator; + public class WrappedOption implements IHolder { private IHolder> held; @@ -21,9 +21,7 @@ public class WrappedOption implements IHolder { public IHolder bind(Function> binder) { IHolder> newHolder = held.map((containedHolder) -> { return containedHolder.bind((containedValue) -> { - if (containedValue == null) { - return new Option<>(null); - } + if(containedValue == null) return new Option<>(null); return binder.apply(containedValue); }); @@ -43,9 +41,7 @@ public class WrappedOption implements IHolder { public IHolder map(Function mapper) { IHolder> newHolder = held.map((containedHolder) -> { return containedHolder.map((containedValue) -> { - if (containedValue == null) { - return null; - } + if(containedValue == null) return null; return mapper.apply(containedValue); }); @@ -58,9 +54,7 @@ public class WrappedOption implements IHolder { public IHolder transform(UnaryOperator transformer) { held.transform((containedHolder) -> { return containedHolder.transform((containedValue) -> { - if (containedValue == null) { - return null; - } + if(containedValue == null) return null; return transformer.apply(containedValue); }); @@ -73,9 +67,7 @@ public class WrappedOption implements IHolder { public UnwrappedType unwrap(Function unwrapper) { return held.unwrap((containedHolder) -> { return containedHolder.unwrap((containedValue) -> { - if (containedValue == null) { - return null; - } + if(containedValue == null) return null; return unwrapper.apply(containedValue); }); -- cgit v1.2.3