
net.sf.jagg.msd.EnumDiscriminator 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;
/**
* An EnumDiscriminator
discriminates Lists
of
* Enums
by their ordinals.
*
* @author Randy Gettman
* @since 0.5.0
*/
public class EnumDiscriminator> extends ChainedDiscriminator
{
/**
* Returns an appropriate ChainedExtractor
.
* @param elements The List
of elements.
* @param extractor A ChainedExtractor
that returns appropriate
* labels.
* @return An appropriate ChainedExtractor
.
*/
protected ChainedExtractor getChainedExtractor(List elements, Extractor extractor)
{
return new EnumChainedExtractor(extractor);
}
/**
* An EnumChainedExtractor
extracts the enum ordinal.
* @param The type of element.
*/
protected class EnumChainedExtractor extends ChainedExtractor
{
/**
* Create an EnumChainedExtractor
that uses the given
* Extractor
to retrieve the array.
* @param extractor An Extractor
whose label is an integer.
*/
public EnumChainedExtractor(Extractor extractor)
{
super(extractor);
}
/**
* The label is the ordinal of the Enum
.
* @param element The element.
* @return The ordinal of the Enum
.
*/
public Integer getLabel(E element)
{
return myExtractor.getLabel(element).ordinal();
}
/**
* The discrimination is complete when the chained Extractor
* is complete.
* @param element The element.
* @return true
if complete, false
otherwise.
*/
public boolean isComplete(E element)
{
// Only check the ordinal once!
return myExtractor.isComplete(element) || myIndex >= 1;
}
}
/**
* Returns the Discriminator
that discriminates on the enum
* ordinals.
* @param elements The list of elements.
* @param extractor The ChainedExtractor
that was obtained from
* getChainedExtractor
.
* @param index The index of the loop.
* @return A Discriminator
that discriminates on the enum
* ordinals.
*/
protected Discriminator getDiscriminator(List elements, ChainedExtractor extractor,
int index)
{
return new IntegerDiscriminator();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy