newAverageObj.set(newCount.intValue(), newSum); return new AverageResult(newAverageObj); } else { throw new IllegalArgumentException(
public CalcResult merge(CalcResult resultsToAdd) { if (!isCompatible(resultsToAdd)) { throw new IllegalArgumentException("Parameter is not a compatible type"); } if (resultsToAdd == CalcResult.NULL_RESULT) { return this; } if (resultsToAdd instanceof SumResult) { // create a new strategy object of the correct dataType Number[] sums = new Number[2]; sums[0] = (Number) sum.getResult(); sums[1] = (Number) resultsToAdd.getValue(); SumStrategy newSum = createStrategy(CalcUtil.getObject(sums).getClass()); // add the two sums newSum.add(sums[0]); newSum.add(sums[1]); return new SumResult(newSum); } else if (resultsToAdd instanceof CountResult) { // SumResult + CountResult = AverageResult int count = resultsToAdd.toInt(); AverageResult newResult = new AverageResult(count, sum.getResult()); return newResult; } else { throw new IllegalArgumentException( "The CalcResults claim to be compatible, but the appropriate merge method has not been implemented."); } } }
newAverageObj.set(newCount.intValue(), newSum); return new AverageResult(newAverageObj); } else { throw new IllegalArgumentException(
newAverageObj.set(newCount.intValue(), newSum); return new AverageResult(newAverageObj); } else { throw new IllegalArgumentException(
public CalcResult merge(CalcResult resultsToAdd) { if (!isCompatible(resultsToAdd)) { throw new IllegalArgumentException( "Parameter is not a compatible type"); } if(resultsToAdd == CalcResult.NULL_RESULT) { return this; } if (resultsToAdd instanceof SumResult) { //create a new strategy object of the correct dataType Number[] sums = new Number[2]; sums[0] = (Number) sum.getResult(); sums[1] = (Number) resultsToAdd.getValue(); SumStrategy newSum = createStrategy(CalcUtil.getObject(sums).getClass()); //add the two sums newSum.add(sums[0]); newSum.add(sums[1]); return new SumResult(newSum); } else if (resultsToAdd instanceof CountResult) { //SumResult + CountResult = AverageResult int count = resultsToAdd.toInt(); AverageResult newResult = new AverageResult(count, sum.getResult()); return newResult; } else { throw new IllegalArgumentException( "The CalcResults claim to be compatible, but the appropriate merge method has not been implemented."); } } }
public CalcResult merge(CalcResult resultsToAdd) { if (!isCompatible(resultsToAdd)) { throw new IllegalArgumentException( "Parameter is not a compatible type"); } if (resultsToAdd instanceof SumResult) { //create a new strategy object of the correct dataType Number[] sums = new Number[2]; sums[0] = (Number) sum.getResult(); sums[1] = (Number) resultsToAdd.getValue(); SumStrategy newSum = createStrategy(CalcUtil.getObject(sums).getClass()); //add the two sums newSum.add(sums[0]); newSum.add(sums[1]); return new SumResult(newSum); } else if (resultsToAdd instanceof CountResult) { //SumResult + CountResult = AverageResult int count = resultsToAdd.toInt(); AverageResult newResult = new AverageResult(count, sum.getResult()); return newResult; } else { throw new IllegalArgumentException( "The CalcResults claim to be compatible, but the appropriate merge method has not been implemented."); } } }
/** * Returns a CalcResult object (containing the Average) * */ public CalcResult getResult() { if(strategy == null) { return CalcResult.NULL_RESULT; } return new AverageResult(strategy, isOptimized); }
/** * Returns a CalcResult object (containing the Average) * */ public CalcResult getResult() { return new AverageResult(strategy, isOptimized); }
/** Returns a CalcResult object (containing the Average) */ public CalcResult getResult() { if (strategy == null) { return CalcResult.NULL_RESULT; } return new AverageResult(strategy, isOptimized); }
@Override public CalcResult wrap(Expression aggregateAttribute, Object value) { return new AverageVisitor.AverageResult(value); } },