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."); } } }
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 getResult() { return new SumResult(strategy); }
public CalcResult getResult() { if(strategy == null) { return CalcResult.NULL_RESULT; } return new SumResult(strategy); }
public CalcResult getResult() { if (strategy == null) { return CalcResult.NULL_RESULT; } return new SumResult(strategy); }
@Override public CalcResult wrap(Expression aggregateAttribute, Object value) { if (value == null) { return AbstractCalcResult.NULL_RESULT; } return new SumVisitor.SumResult(value); } };
@Override public CalcResult wrap(Expression aggregateAttribute, Object value) { return new SumVisitor.SumResult(value); } },