fuzzycsv.Sum.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fuzzy-csv Show documentation
Show all versions of fuzzy-csv Show documentation
A groovy/java tabular Data (from CSV,SQL,JSON) processing library that supports fuzzy column matching,tranformations/merging/querying etc
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()
}
}
}