diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-03-22 12:28:35 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-03-22 12:28:35 -0400 |
| commit | 01cb9f504c860bc1c037a44f3a76bf342a293d46 (patch) | |
| tree | 02d1d34de0828159bbda93e881c93a6b45720f32 /BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java | |
| parent | 4685955a62c430007c5c8ed2b915ffc618d30aca (diff) | |
General formatting cleanup and documentation update
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java | 94 |
1 files changed, 60 insertions, 34 deletions
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<E> implements Cloneable { * NOTE: The returned list will have the length of the shorter of this * list and the combined one. * + * @param <T> + * The type of the second list + * @param <F> + * The type of the combined list + * * @param l * The list to combine with * @param bf @@ -197,6 +202,9 @@ public class FunctionalList<E> implements Cloneable { * Apply a function to each member of the list, then flatten the * results. Does not change the underlying list. * + * @param <T> + * 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 @@ -277,6 +285,15 @@ public class FunctionalList<E> implements Cloneable { } /** + * 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. * * @return Whether or not this list is empty. @@ -289,6 +306,9 @@ public class FunctionalList<E> implements Cloneable { * Create a new list by applying the given function to each element in * the list. Does not change the underlying list. * + * @param <T> + * 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<E> implements Cloneable { /** * Zip two lists into a list of pairs * + * @param <T> + * 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 @@ -314,6 +337,31 @@ public class FunctionalList<E> implements Cloneable { } /** + * 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<FunctionalList<E>> partition(int nPerPart) { + FunctionalList<FunctionalList<E>> ret = new FunctionalList<>(); + + GenHolder<FunctionalList<E>> 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 * * @param item @@ -338,6 +386,11 @@ public class FunctionalList<E> implements Cloneable { /** * Reduce this list to a single value, using a accumulative approach. * + * @param <T> + * The in-between type of the values + * @param <F> + * The final value type + * * @param val * The initial value of the accumulative state. * @param bf @@ -369,6 +422,12 @@ public class FunctionalList<E> 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<E> implements Cloneable { * * @see java.lang.Object#toString() */ + @Override public String toString() { StringBuilder sb = new StringBuilder("("); @@ -426,38 +486,4 @@ public class FunctionalList<E> 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<FunctionalList<E>> partition(int nPerPart) { - FunctionalList<FunctionalList<E>> ret = new FunctionalList<>(); - - GenHolder<FunctionalList<E>> 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; - } } |
