
net.sf.jagg.msd.NullDiscriminator 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.ArrayList;
import java.util.List;
/**
* A NullDiscriminator
extracts nulls
into a separate
* equivalence class, then calls another discriminator.
*
* @author Randy Gettman
* @since 0.5.0
*/
public class NullDiscriminator extends AbstractDiscriminator
{
/**
* The decorated Discriminator
.
*/
private Discriminator myDiscriminator;
/**
* Create a NullDiscriminator
that decorates another
* Discriminator
, to allow null
labels.
* @param discriminator Another Discriminator
.
*/
public NullDiscriminator(Discriminator discriminator)
{
myDiscriminator = discriminator;
}
/**
* Partitions the given List
of elements into another
* List
, in which all of the elements from the given list exist
* in the new list, and all elements 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 elements
* that compare equal to each other.
*/
public List> discriminate(List elements, Extractor extractor, MsdWorkspace workspace)
{
List nulls = new ArrayList();
List nonNulls = new ArrayList();
int size = elements.size();
for (int i = 0; i < size; i++)
{
E element = elements.get(i);
if (extractor.getLabel(element) == null)
nulls.add(element);
else
nonNulls.add(element);
}
// Note: if all nulls, then the nested Discriminator is not necessary.
List> equivClasses = (nonNulls.isEmpty()) ?
new ArrayList>(1) :
myDiscriminator.discriminate(nonNulls, extractor, workspace);
if (!nulls.isEmpty())
equivClasses.add(nulls);
return equivClasses;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy