From 8923edffdb36b790014ff47301e53f7ede93ea0d Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Wed, 11 Oct 2017 22:49:16 -0300 Subject: Cleanup more --- .../bjc/utils/funcutils/GroupPartIteration.java | 38 +++++++++++++++++----- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'base/src/main/java/bjc/utils/funcutils/GroupPartIteration.java') diff --git a/base/src/main/java/bjc/utils/funcutils/GroupPartIteration.java b/base/src/main/java/bjc/utils/funcutils/GroupPartIteration.java index f3b2254..9e4b43a 100644 --- a/base/src/main/java/bjc/utils/funcutils/GroupPartIteration.java +++ b/base/src/main/java/bjc/utils/funcutils/GroupPartIteration.java @@ -7,24 +7,46 @@ import bjc.utils.funcdata.FunctionalList; import bjc.utils.funcdata.IList; /** - * Implements a single group partitioning pass on a list + * Implements a single group partitioning pass on a list. * * @author ben * * @param - * The type of element in the list being partitioned + * The type of element in the list being partitioned */ final class GroupPartIteration implements Consumer { + /* The list we're returning. */ private final IList> returnedList; - public IList currentPartition; - private final IList rejectedItems; + /* The current partition of the list. */ + public IList currentPartition; + /* The items rejected from the current partition. */ + private final IList rejectedItems; - private int numberInCurrentPartition; - private final int numberPerPartition; + /* The number of items in the current partition. */ + private int numberInCurrentPartition; + /* The number of items in each partition. */ + private final int numberPerPartition; + /* The function to use to count an item. */ private final Function elementCounter; + /** + * Create a new group partitioning iteration. + * + * @param returned + * The list containing all of the existing partitions. + * + * @param rejects + * The items that have been rejected from a partition for being too + * large. + * + * @param nPerPart + * The combined value of items that should go into each partition. + * + * @param eleCount + * The function to use to determine the value of an item. + */ public GroupPartIteration(final IList> returned, final IList rejects, final int nPerPart, final Function eleCount) { this.returnedList = returned; @@ -48,8 +70,8 @@ final class GroupPartIteration implements Consumer { } else { final int currentElementCount = elementCounter.apply(value); - final boolean shouldReject = numberInCurrentPartition - + currentElementCount >= numberPerPartition; + final boolean shouldReject = + (numberInCurrentPartition + currentElementCount) >= numberPerPartition; if (shouldReject) { rejectedItems.add(value); -- cgit v1.2.3