/**
   * @param valueGroups
   * @param valuesAreDates
   *     <p>TODO use param valuesAreDates
   */
  protected void applyAdaptiveVisualRounding(List<ValueRange> valueGroups, boolean valuesAreDates) {
    if (valuesAreDates) {
      DateFormat dateFormat = getDateFormat();
      for (ValueRange range : valueGroups) {
        NumericalValueRange numericalValueRange = (NumericalValueRange) range;
        numericalValueRange.setDateFormat(dateFormat);
      }
    } else {
      // values are not dates

      // first pass
      NumericalValueRange previous = null;
      NumericalValueRange current = null;
      NumericalValueRange next = null;
      for (ValueRange valueGroup : valueGroups) {
        next = (NumericalValueRange) valueGroup;
        if (previous != null) {
          int precisionLower =
              Math.min(
                  DataStructureUtils.getOptimalPrecision(
                      current.getLowerBound(), current.getUpperBound()),
                  DataStructureUtils.getOptimalPrecision(
                      previous.getLowerBound(), current.getLowerBound()));
          int precisionUpper =
              Math.min(
                  DataStructureUtils.getOptimalPrecision(
                      current.getLowerBound(), current.getUpperBound()),
                  DataStructureUtils.getOptimalPrecision(
                      current.getUpperBound(), next.getUpperBound()));
          if (precisionUpper >= Integer.MAX_VALUE) {
            precisionUpper = precisionLower;
          }
          current.setVisualPrecision(precisionLower, precisionUpper);
        } else if (current != null) {
          int precisionLower =
              DataStructureUtils.getOptimalPrecision(
                  current.getLowerBound(), current.getUpperBound());
          int precisionUpper =
              Math.min(
                  DataStructureUtils.getOptimalPrecision(
                      current.getLowerBound(), current.getUpperBound()),
                  DataStructureUtils.getOptimalPrecision(
                      current.getUpperBound(), next.getUpperBound()));
          if (precisionUpper >= Integer.MAX_VALUE) {
            precisionUpper = precisionLower;
          }
          current.setVisualPrecision(precisionLower, precisionUpper);
        }
        previous = current;
        current = next;
      }
      if (previous != null) {
        // even if eclipse states that this code is dead, it is not! (eclipse bug)
        int precisionLower =
            Math.min(
                DataStructureUtils.getOptimalPrecision(
                    current.getLowerBound(), current.getUpperBound()),
                DataStructureUtils.getOptimalPrecision(
                    previous.getLowerBound(), current.getLowerBound()));
        int precisionUpper =
            DataStructureUtils.getOptimalPrecision(
                current.getLowerBound(), current.getUpperBound());
        if (precisionUpper >= Integer.MAX_VALUE) {
          precisionUpper = precisionLower;
        }
        current.setVisualPrecision(precisionLower, precisionUpper);
      } else if (current != null) {
        int precision =
            DataStructureUtils.getOptimalPrecision(
                current.getLowerBound(), current.getUpperBound());
        current.setVisualPrecision(precision, precision);
      }

      //		// second pass
      //		current = null;
      //		next = null;
      //		for (ValueRange valueGroup : valueGroups ) {
      //			next = (NumericalValueRange)valueGroup;
      //			if (current != null) {
      //				int currentPrecision = current.getUpperPrecision();
      //				int nextPrecision = next.getLowerPrecision();
      //				int precision = Math.min(nextPrecision, currentPrecision);
      //				current.setUpperPrecision(precision);
      //				next.setLowerPrecision(precision);
      //			}
      //			current = next;
      //		}
    }
  }