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

fuzzycsv.Sum.groovy Maven / Gradle / Ivy

Go to download

A groovy/java tabular Data (from CSV,SQL,JSON) processing library that supports fuzzy column matching,tranformations/merging/querying etc

There is a newer version: 1.9.1-groovy4
Show newest version
package fuzzycsv


class Sum extends AbstractAggregator {

    /**
     * A list of either Record functions or Column Names
     */
    List columns

    Sum() {}


    Sum(List columns) {
        this.columns = columns
    }

    Sum(List columns, String columnName) {
        this.columnName = columnName
        this.columns = columns
    }

    @Override
    Number getValue() {
        List data = getData(columns)
        def value = data.sum { row ->
            return FuzzyCSVUtils.toNumbers(row).sum()
        }
        return value
    }


    static Sum sum(Object[] aggregateColumns) {
        return new Sum(aggregateColumns as List)
    }

    @Override
    String getColumnName() {
        if (!super.columnName) {
            return "sum(${columns*.toString().join(',')})"
        }
        else {
            return super.getColumnName()
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy