コード例 #1
0
  /**
   * Creates and returns the appropriate implementation of AggregationResultHolder, based on
   * aggregation function.
   *
   * @param function Aggregation function
   * @return Appropriate aggregation result holder
   */
  public static AggregationResultHolder getAggregationResultHolder(AggregationFunction function) {
    String functionName = function.getName();

    switch (functionName.toLowerCase()) {
      case AggregationFunctionFactory.COUNT_AGGREGATION_FUNCTION:
      case AggregationFunctionFactory.MAX_AGGREGATION_FUNCTION:
      case AggregationFunctionFactory.MIN_AGGREGATION_FUNCTION:
      case AggregationFunctionFactory.SUM_AGGREGATION_FUNCTION:
        return new DoubleAggregationResultHolder(function.getDefaultValue());

      default:
        return new ObjectAggregationResultHolder();
    }
  }
コード例 #2
0
  /**
   * Creates and returns the appropriate implementation of GroupByResultHolder, based on aggregation
   * function.
   *
   * @param function Aggregation function
   * @param maxNumResults Max number of results
   * @return Appropriate group by result holder
   */
  public static GroupByResultHolder getGroupByResultHolder(
      AggregationFunction function, long maxNumResults) {
    String functionName = function.getName();

    int capacityCap = maxNumResults > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) maxNumResults;
    int initialCapacity = Math.min(capacityCap, MAX_INITIAL_RESULT_HOLDER_CAPACITY);

    switch (functionName.toLowerCase()) {
      case AggregationFunctionFactory.COUNT_AGGREGATION_FUNCTION:
      case AggregationFunctionFactory.MAX_AGGREGATION_FUNCTION:
      case AggregationFunctionFactory.MIN_AGGREGATION_FUNCTION:
      case AggregationFunctionFactory.SUM_AGGREGATION_FUNCTION:
        return new DoubleGroupByResultHolder(
            initialCapacity, capacityCap, function.getDefaultValue());

      default:
        return new ObjectGroupByResultHolder(initialCapacity, capacityCap);
    }
  }