test_class.file: beanmother-core/src/test/java/io/beanmother/core/util/NumberUtilsTest.java
test_class.identifier: NumberUtilsTest
test_case.body: @Test
      public void testConvertNumberToTargetClass() throws Exception {
          assertEquals(new Integer(1), NumberUtils.convertNumberToTargetClass(1.1, Integer.class));
          assertEquals(new Byte("1"), NumberUtils.convertNumberToTargetClass(1.1, Byte.class));
          assertEquals(new Float(1.1), NumberUtils.convertNumberToTargetClass(1.1, Float.class));
          assertEquals(new Double(1.1), NumberUtils.convertNumberToTargetClass(1.1, Double.class));
          assertEquals(new Long(1), NumberUtils.convertNumberToTargetClass(1.1, Long.class));
          assertEquals(new Short("1"), NumberUtils.convertNumberToTargetClass(1.1, Short.class));
          assertEquals(new BigInteger("1"), NumberUtils.convertNumberToTargetClass(1, BigInteger.class));
      }
test_case.class_method_signature: NumberUtilsTest.testConvertNumberToTargetClass()
test_case.full_signature: @Test public void testConvertNumberToTargetClass()
test_case.identifier: testConvertNumberToTargetClass
test_case.invocations: assertEquals convertNumberToTargetClass assertEquals convertNumberToTargetClass assertEquals convertNumberToTargetClass assertEquals convertNumberToTargetClass assertEquals convertNumberToTargetClass assertEquals convertNumberToTargetClass assertEquals convertNumberToTargetClass
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testConvertNumberToTargetClass()
focal_class.declarator: LONG_MIN = BigInteger.valueOf(Long.MIN_VALUE)
focal_class.modifier: private static final
focal_class.original_string: private static final BigInteger LONG_MIN = BigInteger.valueOf(Long.MIN_VALUE);
focal_class.type: BigInteger
focal_class.var_name: LONG_MIN
focal_class.declarator: LONG_MAX = BigInteger.valueOf(Long.MAX_VALUE)
focal_class.modifier: private static final
focal_class.original_string: private static final BigInteger LONG_MAX = BigInteger.valueOf(Long.MAX_VALUE);
focal_class.type: BigInteger
focal_class.var_name: LONG_MAX
focal_class.declarator: STANDARD_NUMBER_TYPES
focal_class.modifier: public static final
focal_class.original_string: public static final Set<Class<?>> STANDARD_NUMBER_TYPES;
focal_class.type: Set<Class<?>>
focal_class.var_name: STANDARD_NUMBER_TYPES
focal_class.file: beanmother-core/src/main/java/io/beanmother/core/util/NumberUtils.java
focal_class.identifier: NumberUtils
focal_class.class_method_signature: NumberUtils.convertNumberToTargetClass(Number number, Class<T> targetClass)
focal_class.full_signature: @SuppressWarnings("unchecked") public static T convertNumberToTargetClass(Number number, Class<T> targetClass)
focal_class.identifier: convertNumberToTargetClass
focal_class.modifiers: @SuppressWarnings("unchecked") public static
focal_class.parameters: (Number number, Class<T> targetClass)
focal_class.return: T
focal_class.signature: T convertNumberToTargetClass(Number number, Class<T> targetClass)
focal_class.class_method_signature: NumberUtils.checkedLongValue(Number number, Class<? extends Number> targetClass)
focal_class.full_signature: private static long checkedLongValue(Number number, Class<? extends Number> targetClass)
focal_class.identifier: checkedLongValue
focal_class.modifiers: private static
focal_class.parameters: (Number number, Class<? extends Number> targetClass)
focal_class.return: long
focal_class.signature: long checkedLongValue(Number number, Class<? extends Number> targetClass)
focal_class.class_method_signature: NumberUtils.raiseOverflowException(Number number, Class<?> targetClass)
focal_class.full_signature: private static void raiseOverflowException(Number number, Class<?> targetClass)
focal_class.identifier: raiseOverflowException
focal_class.modifiers: private static
focal_class.parameters: (Number number, Class<?> targetClass)
focal_class.return: void
focal_class.signature: void raiseOverflowException(Number number, Class<?> targetClass)
focal_class.class_method_signature: NumberUtils.parseNumber(String text, Class<T> targetClass)
focal_class.full_signature: @SuppressWarnings("unchecked") public static T parseNumber(String text, Class<T> targetClass)
focal_class.identifier: parseNumber
focal_class.modifiers: @SuppressWarnings("unchecked") public static
focal_class.parameters: (String text, Class<T> targetClass)
focal_class.return: T
focal_class.signature: T parseNumber(String text, Class<T> targetClass)
focal_class.class_method_signature: NumberUtils.isHexNumber(String value)
focal_class.full_signature: private static boolean isHexNumber(String value)
focal_class.identifier: isHexNumber
focal_class.modifiers: private static
focal_class.parameters: (String value)
focal_class.return: boolean
focal_class.signature: boolean isHexNumber(String value)
focal_class.class_method_signature: NumberUtils.decodeBigInteger(String value)
focal_class.full_signature: private static BigInteger decodeBigInteger(String value)
focal_class.identifier: decodeBigInteger
focal_class.modifiers: private static
focal_class.parameters: (String value)
focal_class.return: BigInteger
focal_class.signature: BigInteger decodeBigInteger(String value)
focal_class.class_method_signature: NumberUtils.trimAllWhitespace(String str)
focal_class.full_signature: public static String trimAllWhitespace(String str)
focal_class.identifier: trimAllWhitespace
focal_class.modifiers: public static
focal_class.parameters: (String str)
focal_class.return: String
focal_class.signature: String trimAllWhitespace(String str)
focal_method.body: @SuppressWarnings("unchecked")
      public static <T extends Number> T convertNumberToTargetClass(Number number, Class<T> targetClass)
              throws IllegalArgumentException {
  
          if (targetClass.isInstance(number)) {
              return (T) number;
          }
          else if (Byte.class == targetClass) {
              long value = checkedLongValue(number, targetClass);
              if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
                  raiseOverflowException(number, targetClass);
              }
              return (T) Byte.valueOf(number.byteValue());
          }
          else if (Short.class == targetClass) {
              long value = checkedLongValue(number, targetClass);
              if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
                  raiseOverflowException(number, targetClass);
              }
              return (T) Short.valueOf(number.shortValue());
          }
          else if (Integer.class == targetClass) {
              long value = checkedLongValue(number, targetClass);
              if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
                  raiseOverflowException(number, targetClass);
              }
              return (T) Integer.valueOf(number.intValue());
          }
          else if (Long.class == targetClass) {
              long value = checkedLongValue(number, targetClass);
              return (T) Long.valueOf(value);
          }
          else if (BigInteger.class == targetClass) {
              if (number instanceof BigDecimal) {
                  // do not lose precision - use BigDecimal's own conversion
                  return (T) ((BigDecimal) number).toBigInteger();
              }
              else {
                  // original value is not a Big* number - use standard long conversion
                  return (T) BigInteger.valueOf(number.longValue());
              }
          }
          else if (Float.class == targetClass) {
              return (T) Float.valueOf(number.floatValue());
          }
          else if (Double.class == targetClass) {
              return (T) Double.valueOf(number.doubleValue());
          }
          else if (BigDecimal.class == targetClass) {
              // always use BigDecimal(String) here to avoid unpredictability of BigDecimal(double)
              // (see BigDecimal javadoc for details)
              return (T) new BigDecimal(number.toString());
          }
          else if (AtomicInteger.class == targetClass) {
              return (T) new AtomicInteger(number.intValue());
          }
          else if (AtomicLong.class == targetClass) {
              return (T) new AtomicLong(number.longValue());
          }
          else {
              throw new IllegalArgumentException("Could not convert number [" + number + "] of type [" +
                      number.getClass().getName() + "] to unsupported target class [" + targetClass.getName() + "]");
          }
      }
focal_method.class_method_signature: NumberUtils.convertNumberToTargetClass(Number number, Class<T> targetClass)
focal_method.full_signature: @SuppressWarnings("unchecked") public static T convertNumberToTargetClass(Number number, Class<T> targetClass)
focal_method.identifier: convertNumberToTargetClass
focal_method.invocations: isInstance checkedLongValue raiseOverflowException valueOf byteValue checkedLongValue raiseOverflowException valueOf shortValue checkedLongValue raiseOverflowException valueOf intValue checkedLongValue valueOf toBigInteger valueOf longValue valueOf floatValue valueOf doubleValue toString intValue longValue getName getClass getName
focal_method.modifiers: @SuppressWarnings("unchecked") public static
focal_method.parameters: (Number number, Class<T> targetClass)
focal_method.return: T
focal_method.signature: T convertNumberToTargetClass(Number number, Class<T> targetClass)