From 27bf571d6413c3cc6a5d664b5bddd38d21d7b1cd Mon Sep 17 00:00:00 2001 From: EVE Date: Mon, 13 Mar 2017 16:42:21 -0400 Subject: Formatting --- .../java/bjc/utils/funcdata/FunctionalList.java | 61 ++++++++++------------ 1 file changed, 28 insertions(+), 33 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java index 3f61303..f98f32c 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java @@ -18,16 +18,16 @@ import bjc.utils.data.Identity; import bjc.utils.data.Pair; /** - * A wrapper over another list that provides eager functional operations - * over it. + * A wrapper over another list that provides eager functional operations over + * it. * - * Differs from a stream in every way except for the fact that - * they both provide functional operations. + * Differs from a stream in every way except for the fact that they both provide + * functional operations. * * @author ben * * @param - * The type in this list + * The type in this list */ public class FunctionalList implements Cloneable, IList { /* @@ -48,7 +48,7 @@ public class FunctionalList implements Cloneable, IList { * Takes O(n) time, where n is the number of items specified * * @param items - * The items to put into this functional list. + * The items to put into this functional list. */ @SafeVarargs public FunctionalList(E... items) { @@ -63,7 +63,7 @@ public class FunctionalList implements Cloneable, IList { * Create a new functional list with the specified size. * * @param size - * The size of the backing list . + * The size of the backing list . */ private FunctionalList(int size) { wrapped = new ArrayList<>(size); @@ -75,12 +75,11 @@ public class FunctionalList implements Cloneable, IList { * Takes O(1) time, since it doesn't copy the list. * * @param backing - * The list to use as a backing list. + * The list to use as a backing list. */ public FunctionalList(List backing) { if (backing == null) { - throw new NullPointerException( - "Backing list must be non-null"); + throw new NullPointerException("Backing list must be non-null"); } wrapped = backing; @@ -144,10 +143,9 @@ public class FunctionalList implements Cloneable, IList { } @Override - public IList combineWith(IList rightList, - BiFunction itemCombiner) { + public IList combineWith(IList rightList, BiFunction itemCombiner) { if (rightList == null) { - throw new NullPointerException( "Target combine list must not be null"); + throw new NullPointerException("Target combine list must not be null"); } else if (itemCombiner == null) { throw new NullPointerException("Combiner must not be null"); } @@ -157,8 +155,8 @@ public class FunctionalList implements Cloneable, IList { // Get the iterator for the other list Iterator rightIterator = rightList.toIterable().iterator(); - for (Iterator leftIterator = wrapped.iterator(); - leftIterator.hasNext() && rightIterator.hasNext();) { + for (Iterator leftIterator = wrapped.iterator(); leftIterator.hasNext() + && rightIterator.hasNext();) { // Add the transformed items to the result list E leftVal = leftIterator.next(); T rightVal = rightIterator.next(); @@ -220,7 +218,8 @@ public class FunctionalList implements Cloneable, IList { throw new NullPointerException("Action must not be null"); } - // This is held b/c ref'd variables must be final/effectively final + // This is held b/c ref'd variables must be final/effectively + // final IHolder currentIndex = new Identity<>(0); wrapped.forEach((element) -> { @@ -256,7 +255,8 @@ public class FunctionalList implements Cloneable, IList { wrapped.forEach((element) -> { if (predicate.test(element)) { - // The item matches, so add it to the returned list + // The item matches, so add it to the returned + // list returned.add(element); } }); @@ -277,8 +277,7 @@ public class FunctionalList implements Cloneable, IList { /* * Check if a partition has room for another item */ - private Boolean isPartitionFull(int numberPerPartition, - IHolder> currentPartition) { + private Boolean isPartitionFull(int numberPerPartition, IHolder> currentPartition) { return currentPartition.unwrap((partition) -> partition.getSize() >= numberPerPartition); } @@ -305,18 +304,15 @@ public class FunctionalList implements Cloneable, IList { @Override public IList> partition(int numberPerPartition) { - if (numberPerPartition < 1 - || numberPerPartition > wrapped.size()) { + if (numberPerPartition < 1 || numberPerPartition > wrapped.size()) { throw new IllegalArgumentException("" + numberPerPartition - + " is an invalid partition size. Must be between 1 and " - + wrapped.size()); + + " is an invalid partition size. Must be between 1 and " + wrapped.size()); } IList> returned = new FunctionalList<>(); // The current partition being filled - IHolder> currentPartition = new Identity<>( - new FunctionalList<>()); + IHolder> currentPartition = new Identity<>(new FunctionalList<>()); this.forEach((element) -> { if (isPartitionFull(numberPerPartition, currentPartition)) { @@ -351,8 +347,7 @@ public class FunctionalList implements Cloneable, IList { } @Override - public F reduceAux(T initialValue, - BiFunction stateAccumulator, + public F reduceAux(T initialValue, BiFunction stateAccumulator, Function resultTransformer) { if (stateAccumulator == null) { throw new NullPointerException("Accumulator must not be null"); @@ -394,8 +389,7 @@ public class FunctionalList implements Cloneable, IList { @Override public E search(E searchKey, Comparator comparator) { // Search our internal list - int foundIndex = Collections.binarySearch(wrapped, searchKey, - comparator); + int foundIndex = Collections.binarySearch(wrapped, searchKey, comparator); if (foundIndex >= 0) { // We found a matching element @@ -431,21 +425,22 @@ public class FunctionalList implements Cloneable, IList { public String toString() { int lSize = getSize(); - if(lSize == 0) return "()"; + if (lSize == 0) + return "()"; StringBuilder sb = new StringBuilder("("); Iterator itr = toIterable().iterator(); E itm = itr.next(); int i = 0; - if(lSize == 1) { + if (lSize == 1) { return "(" + itm + ")"; } - for(E item : toIterable()) { + for (E item : toIterable()) { sb.append(item.toString()); - if(i < lSize-1) { + if (i < lSize - 1) { sb.append(", "); } -- cgit v1.2.3