From 01cb9f504c860bc1c037a44f3a76bf342a293d46 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Tue, 22 Mar 2016 12:28:35 -0400 Subject: General formatting cleanup and documentation update --- .../java/bjc/utils/funcdata/FunctionalList.java | 94 ++++++++++++++-------- 1 file changed, 60 insertions(+), 34 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 72c5843..810e4f1 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java @@ -153,6 +153,11 @@ public class FunctionalList implements Cloneable { * NOTE: The returned list will have the length of the shorter of this * list and the combined one. * + * @param + * The type of the second list + * @param + * The type of the combined list + * * @param l * The list to combine with * @param bf @@ -197,6 +202,9 @@ public class FunctionalList implements Cloneable { * Apply a function to each member of the list, then flatten the * results. Does not change the underlying list. * + * @param + * The type of the flattened list + * * @param f * The function to apply to each member of the list. * @return A new list containing the flattened results of applying the @@ -276,6 +284,15 @@ public class FunctionalList implements Cloneable { return fl; } + /** + * Retrieve the size of the wrapped list + * + * @return The size of the wrapped list + */ + public int getSize() { + return wrap.size(); + } + /** * Check if this list is empty. * @@ -289,6 +306,9 @@ public class FunctionalList implements Cloneable { * Create a new list by applying the given function to each element in * the list. Does not change the underlying list. * + * @param + * The type of the transformed list + * * @param f * The function to apply to each element in the list * @return A new list containing the mapped elements of this list. @@ -304,6 +324,9 @@ public class FunctionalList implements Cloneable { /** * Zip two lists into a list of pairs * + * @param + * The type of the second list + * * @param fl * The list to use as the left side of the pair * @return A list containing pairs of this element and the specified @@ -313,6 +336,31 @@ public class FunctionalList implements Cloneable { return combineWith(fl, Pair::new); } + /** + * Partition this list into a list of sublists + * + * @param nPerPart + * The size of elements to put into each one of the sublists + * @return A list partitioned into partitions of size nPerPart + */ + public FunctionalList> partition(int nPerPart) { + FunctionalList> ret = new FunctionalList<>(); + + GenHolder> currPart = + new GenHolder<>(new FunctionalList<>()); + + this.forEach((val) -> { + if (currPart.unwrap((vl) -> vl.getSize() >= nPerPart)) { + ret.add(currPart.unwrap((vl) -> vl)); + currPart.transform((vl) -> new FunctionalList<>()); + } else { + currPart.unwrap((vl) -> vl.add(val)); + } + }); + + return ret; + } + /** * Prepend an item to the list * @@ -338,6 +386,11 @@ public class FunctionalList implements Cloneable { /** * Reduce this list to a single value, using a accumulative approach. * + * @param + * The in-between type of the values + * @param + * The final value type + * * @param val * The initial value of the accumulative state. * @param bf @@ -369,6 +422,12 @@ public class FunctionalList implements Cloneable { return wrap.removeIf(remPred); } + /** + * Remove all parameters that match a given parameter + * + * @param obj + * The object to remove all matching copies of + */ public void removeMatching(E obj) { removeIf((ele) -> ele.equals(obj)); } @@ -416,6 +475,7 @@ public class FunctionalList implements Cloneable { * * @see java.lang.Object#toString() */ + @Override public String toString() { StringBuilder sb = new StringBuilder("("); @@ -426,38 +486,4 @@ public class FunctionalList implements Cloneable { return sb.toString(); } - - /** - * Retrieve the size of the wrapped list - * - * @return The size of the wrapped list - */ - public int getSize() { - return wrap.size(); - } - - /** - * Partition this list into a list of sublists - * - * @param nPerPart - * The size of elements to put into each one of the sublists - * @return A list partitioned into partitions of size nPerPart - */ - public FunctionalList> partition(int nPerPart) { - FunctionalList> ret = new FunctionalList<>(); - - GenHolder> currPart = new GenHolder<>( - new FunctionalList<>()); - - this.forEach((val) -> { - if (currPart.unwrap((vl) -> vl.getSize() >= nPerPart)) { - ret.add(currPart.unwrap((vl) -> vl)); - currPart.transform((vl) -> new FunctionalList<>()); - } else { - currPart.unwrap((vl) -> vl.add(val)); - } - }); - - return ret; - } } -- cgit v1.2.3