
net.sf.jagg.msd.DateDiscriminator 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.Date;
import java.util.List;
/**
* A DateDiscriminator
discriminates Dates
.
*
* @author Randy Gettman
* @since 0.6.0
*/
public class DateDiscriminator 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 DateChainedExtractor(extractor);
}
/**
* A DateChainedExtractor
extracts the milliseconds value of
* the Date
.
* @param The type of element.
*/
protected class DateChainedExtractor extends ChainedExtractor
{
/**
* Create an EnumChainedExtractor
that uses the given
* Extractor
to retrieve the array.
* @param extractor An Extractor
whose label is a
* long
.
*/
public DateChainedExtractor(Extractor extractor)
{
super(extractor);
}
/**
* The label is the milliseconds value of the Date
.
* @param element The element.
* @return The milliseconds value of the Date
.
*/
public Long getLabel(E element)
{
return myExtractor.getLabel(element).getTime();
}
/**
* 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
* milliseconds value of the Date
.
* @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
* milliseconds value of the Date
.
*/
protected Discriminator getDiscriminator(List elements, ChainedExtractor extractor,
int index)
{
return new LongDiscriminator();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy