Exemple #1
0
  private static Integer parseInteger(String value) {

    try {
      return Integer.valueOf(value);
    } catch (NumberFormatException nfeInteger) {

      try {
        Double result = parseDouble(value);

        if (DoubleMath.isMathematicalInteger(result)) {
          return result.intValue();
        }
      } catch (NumberFormatException nfeDouble) {
        // Ignored
      }

      throw nfeInteger;
    }
  }
Exemple #2
0
 public void testIsMathematicalIntegerNotFinite() {
   for (double d : Arrays.asList(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN)) {
     assertFalse(DoubleMath.isMathematicalInteger(d));
   }
 }
Exemple #3
0
 public void testIsMathematicalIntegerFractional() {
   for (double d : FRACTIONAL_DOUBLE_CANDIDATES) {
     assertFalse(DoubleMath.isMathematicalInteger(d));
   }
 }
Exemple #4
0
 public void testIsMathematicalIntegerIntegral() {
   for (double d : INTEGRAL_DOUBLE_CANDIDATES) {
     assertTrue(DoubleMath.isMathematicalInteger(d));
   }
 }