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 MinResult) { // take the smaller of the 2 values Comparable toAdd = (Comparable) resultsToAdd.getValue(); Comparable newMin = minValue; if (newMin.getClass() != toAdd.getClass()) { // 2 different data types, therefore convert Class bestClass = CalcUtil.bestClass(new Object[] {toAdd, newMin}); if (bestClass != toAdd.getClass()) toAdd = (Comparable) CalcUtil.convert(toAdd, bestClass); if (bestClass != newMin.getClass()) newMin = (Comparable) CalcUtil.convert(newMin, bestClass); } if (newMin.compareTo(toAdd) > 0) { newMin = toAdd; } return new MinResult(newMin); } 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 MinResult) { //take the smaller of the 2 values Comparable toAdd = (Comparable) resultsToAdd.getValue(); Comparable newMin = minValue; if (newMin.getClass() != toAdd.getClass()) { //2 different data types, therefore convert Class bestClass = CalcUtil.bestClass(new Object[] {toAdd, newMin}); if (bestClass != toAdd.getClass()) toAdd = (Comparable) CalcUtil.convert(toAdd, bestClass); if (bestClass != newMin.getClass()) newMin = (Comparable) CalcUtil.convert(newMin, bestClass); } if (newMin.compareTo(toAdd) > 0) { newMin = toAdd; } return new MinResult(newMin); } 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 MinResult) { //take the smaller of the 2 values Comparable toAdd = (Comparable) resultsToAdd.getValue(); Comparable newMin = minValue; if (newMin.getClass() != toAdd.getClass()) { //2 different data types, therefore convert Class bestClass = CalcUtil.bestClass(new Object[] {toAdd, newMin}); if (bestClass != toAdd.getClass()) toAdd = (Comparable) CalcUtil.convert(toAdd, bestClass); if (bestClass != newMin.getClass()) newMin = (Comparable) CalcUtil.convert(newMin, bestClass); } if (newMin.compareTo(toAdd) > 0) { newMin = toAdd; } return new MinResult(newMin); } else { throw new IllegalArgumentException( "The CalcResults claim to be compatible, but the appropriate merge method has not been implemented."); } } }
public CalcResult getResult() { if (!visited) { throw new IllegalStateException( "Must visit before min value is ready!"); } return new MinResult(minvalue); }
public CalcResult getResult() { if (!visited) { return CalcResult.NULL_RESULT; } return new MinResult(minvalue); }
assertEquals(1, minResult3.toInt()); CalcResult minResult4 = new MinResult((Comparable) Integer.valueOf(10)); CalcResult minResult5 = minResult4.merge(minResult1); assertEquals(1, minResult5.toInt()); assertEquals(10, minResult4.toInt()); CalcResult minResult6 = new MinResult((Comparable) Integer.valueOf(-5)); CalcResult minResult7 = (MinResult) minResult1.merge(minResult6); assertEquals(-5, minResult7.toInt());
@Override public CalcResult wrap(Expression aggregateAttribute, Object value) { return new MinVisitor.MinResult((Comparable<?>) value); } },
public CalcResult getResult() { if (!visited) { return CalcResult.NULL_RESULT; } return new MinResult(minvalue); }