All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.jett.expression.JaggFuncs Maven / Gradle / Ivy

Go to download

JETT is a Java API that reads an Excel spreadsheet as a template, takes your data, and creates a new Excel spreadsheet that contains your data, formatted as in the template. It works with .xls and .xlsx template spreadsheets.

The newest version!
package net.sf.jett.expression;

import java.util.ArrayList;
import java.util.List;

import net.sf.jagg.AggregateFunction;
import net.sf.jagg.Aggregations;
import net.sf.jagg.Aggregator;
import net.sf.jagg.model.AggregateValue;

/**
 * A JaggFuncs object is an object that represents jAgg aggregate
 * functionality in the JEXL world.
 *
 * @author Randy Gettman
 */
public class JaggFuncs
{
    /**
     * Have jAgg evaluate an Aggregate Expression.
     * @param values A List of values to aggregate.
     * @param aggSpecString An aggregator specification string, e.g.
     *    "Count(*)", "Sum(quantity)".
     * @return The result of the aggregate operation.
     */
    public static Object eval(List values, String aggSpecString)
    {
        List aggs = new ArrayList<>(1);
        AggregateFunction agg = Aggregator.getAggregator(aggSpecString.trim());
        aggs.add(agg);
        List props = new ArrayList<>(0);
        List> aggValues = Aggregations.groupBy(values, props, aggs);
        // There should be only one AggregateValue returned (no group-by properties!)
        return aggValues.get(0).getAggregateValue(agg);
    }
}