public static Number downCast(long value) {
    Number retVal;

    if (value <= Integer.MAX_VALUE && value >= Integer.MIN_VALUE) {
      retVal = (int) value;
    } else {
      retVal = value;
    }

    return retVal;
  }
Abstract Aggregator class providing support for down casting the result.
geode-core/src/main/java/org/apache/geode/cache/query/internal/aggregate/AbstractAggregator.java