Ejemplo n.º 1
0
  /**
   * Returns the value that corresponds to a given implementation calculator class.
   *
   * @param clazz the target class.
   * @throws IllegalArgumentException if {@code clazz} is {@code null} or if it is abstract.
   * @return never {@code null}.
   */
  public static AFCalculatorImplementation fromCalculatorClass(
      final Class<? extends AFCalculator> clazz) {
    Utils.nonNull(clazz, "input class cannot be null");
    Utils.validateArg(
        !Modifier.isAbstract(clazz.getModifiers()),
        "class " + clazz.getCanonicalName() + " should not be abstract");

    // Using iteration instead of a static map to avoid static state.
    for (final AFCalculatorImplementation impl : AFCalculatorImplementation.values()) {
      if (clazz.equals(impl.newInstance().getClass())) {
        return impl;
      }
    }
    throw new IllegalArgumentException(
        "Attempt to retrieve AFCalculatorImplementation instance from a non-registered calculator class "
            + clazz.getName());
  }
 /**
  * Transforms and composes the string representation of an individual count.
  *
  * <p>The output string must be fully formatted human friendly representation of the transformed
  * value.
  *
  * @param count the individual count value.
  * @param columnTotal the corresponding column total sum.
  * @return never {@code null}.
  * @throws IllegalArgumentException if {@code count} is less than 0 or greater than {@code
  *     columnTotal}.
  */
 protected String apply(final int count, final long columnTotal) {
   ParamUtils.isPositiveOrZero(count, "the count cannot less than 0");
   Utils.validateArg(count <= columnTotal, "the count cannot be larger than the column total");
   return operator.apply(count, columnTotal);
 }