
net.sf.jagg.msd.BooleanDiscriminator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jagg-core Show documentation
Show all versions of jagg-core Show documentation
jAgg is a Java 5.0 API that supports “group by” operations on Lists of Java objects: aggregate operations such as count, sum, max, min, avg, and many more. It also allows custom aggregate operations.
The newest version!
package net.sf.jagg.msd;
import java.util.List;
import java.util.ArrayList;
/**
* A BooleanDiscriminator
discriminates Lists
of
* Booleans
.
*
* @author Randy Gettman
* @since 0.5.0
*/
public class BooleanDiscriminator extends AbstractDiscriminator
{
/**
* Partitions the given List
of values into another
* List
, in which all of the values from the given list exist
* in the new list, and all values that compare equal are adjacent to each
* other, according to the given Extractor
.
* @param elements A List
of elements.
* @param extractor An Extractor
that gives labels for
* each element.
* @param workspace The MsdWorkspace
used in the discrimination process.
* @return A List
of Lists
containing all
* equivalence classes. Each equivalence class list contains all values
* that compare equal to each other.
*/
public List> discriminate(List elements, Extractor extractor, MsdWorkspace workspace)
{
List trues = new ArrayList();
List falses = new ArrayList();
int size = elements.size();
for (int i = 0; i < size; i++)
{
E element = elements.get(i);
if (extractor.getLabel(element))
trues.add(element);
else
falses.add(element);
}
List> equivClasses = new ArrayList>();
if (!trues.isEmpty())
equivClasses.add(trues);
if (!falses.isEmpty())
equivClasses.add(falses);
return equivClasses;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy