
net.sf.jagg.msd.IntegerDiscriminator 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;
/**
* A IntegerDiscriminator
discriminates Lists
of
* Integers
.
*
* @author Randy Gettman
* @since 0.5.0
*/
public class IntegerDiscriminator extends NumberDiscriminator
{
/**
* Returns a portion extractor appropriate for integers
.
* @param e An Extractor
that returns appropriate labels.
* @return An appropriate PortionExtractor
.
*/
protected PortionExtractor getPortionExtractor(Extractor e)
{
return new PortionExtractor(e) {
/**
* The label is the specific portion of the element, cast as an
* integer.
* @param element The element.
* @return The specific portion of the element, cast as an integer.
*/
public int getLabel(E element)
{
return (myExtractor.getLabel(element) >> (myIndex * PORTION_BITS)) & PORTION_MASK;
}
/**
* Complete after 2 portions.
* @param element The element.
* @return true
if the index is at least 2,
* false
otherwise.
*/
public boolean isComplete(E element)
{
return myExtractor.isComplete(element) || myIndex >= 2;
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy