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