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

com.codetaco.funnel.aggregation.AggregateSum Maven / Gradle / Ivy

There is a newer version: 3.0.5
Show newest version
package com.codetaco.funnel.aggregation;

import com.codetaco.funnel.orderby.KeyPart;
import com.codetaco.funnel.parameters.FunnelContext;

/**
 * 

* AggregateSum class. *

* * @author Chris DeGreef [email protected] */ public class AggregateSum extends Aggregate { double sumDouble; long sumLong; /** *

* Constructor for AggregateSum. *

*/ public AggregateSum() { reset(); } @Override Object getValueForEquations() { if (AggType.FLOAT == aggType) return new Double(sumDouble); if (AggType.INT == aggType) return new Long(sumLong); return new Double(0); } @Override void reset() { sumDouble = 0D; sumLong = 0L; } @Override void update(final FunnelContext context) throws Exception { if (equation != null) { final Object unknownType = equation.evaluate(); if (unknownType instanceof Double) { aggType = AggType.FLOAT; final double currentValue = ((Double) unknownType).doubleValue(); sumDouble += currentValue; return; } if (unknownType instanceof Long) { aggType = AggType.INT; final long currentValue = ((Long) unknownType).longValue(); sumLong += currentValue; return; } return; } if (columnName != null) { final KeyPart col = context.columnHelper.get(columnName); if (col.isFloat()) { aggType = AggType.FLOAT; final double currentValue = col.getContentsAsDouble(); sumDouble += currentValue; return; } if (col.isInteger()) { aggType = AggType.INT; final long currentValue = (Long) col.getContents(); sumLong += currentValue; return; } } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy