commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang NumberUtilsTest.java
Date Sun, 15 Dec 2002 16:53:28 GMT
scolebourne    2002/12/15 08:53:28

  Modified:    lang/src/java/org/apache/commons/lang NumberUtils.java
               lang/src/test/org/apache/commons/lang NumberUtilsTest.java
  Log:
  Add constants for standard numeric values
  
  Revision  Changes    Path
  1.5       +39 -2     jakarta-commons/lang/src/java/org/apache/commons/lang/NumberUtils.java
  
  Index: NumberUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/NumberUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- NumberUtils.java	16 Nov 2002 10:41:03 -0000	1.4
  +++ NumberUtils.java	15 Dec 2002 16:53:28 -0000	1.5
  @@ -66,9 +66,46 @@
    * @version $Id$
    */
   public final class NumberUtils {
  +    
  +    /** Reusable Long constant for zero. */
  +    public static final Long LONG_ZERO = new Long(0L);
  +    /** Reusable Long constant for one. */
  +    public static final Long LONG_ONE = new Long(1L);
  +    /** Reusable Long constant for minus one. */
  +    public static final Long LONG_MINUS_ONE = new Long(-1L);
  +    /** Reusable Integer constant for zero. */
  +    public static final Integer INTEGER_ZERO = new Integer(0);
  +    /** Reusable Integer constant for one. */
  +    public static final Integer INTEGER_ONE = new Integer(1);
  +    /** Reusable Integer constant for minus one. */
  +    public static final Integer INTEGER_MINUS_ONE = new Integer(-1);
  +    /** Reusable Short constant for zero. */
  +    public static final Short SHORT_ZERO = new Short((short) 0);
  +    /** Reusable Short constant for one. */
  +    public static final Short SHORT_ONE = new Short((short) 1);
  +    /** Reusable Short constant for minus one. */
  +    public static final Short SHORT_MINUS_ONE = new Short((short) -1);
  +    /** Reusable Byte constant for zero. */
  +    public static final Byte BYTE_ZERO = new Byte((byte) 0);
  +    /** Reusable Byte constant for one. */
  +    public static final Byte BYTE_ONE = new Byte((byte) 1);
  +    /** Reusable Byte constant for minus one. */
  +    public static final Byte BYTE_MINUS_ONE = new Byte((byte) -1);
  +    /** Reusable Double constant for zero. */
  +    public static final Double DOUBLE_ZERO = new Double(0.0d);
  +    /** Reusable Double constant for one. */
  +    public static final Double DOUBLE_ONE = new Double(1.0d);
  +    /** Reusable Double constant for minus one. */
  +    public static final Double DOUBLE_MINUS_ONE = new Double(-1.0d);
  +    /** Reusable Float constant for zero. */
  +    public static final Float FLOAT_ZERO = new Float(0.0f);
  +    /** Reusable Float constant for one. */
  +    public static final Float FLOAT_ONE = new Float(1.0f);
  +    /** Reusable Float constant for minus one. */
  +    public static final Float FLOAT_MINUS_ONE = new Float(-1.0f);
   
       /**
  -     * <p>NumberUtils instances should NOT be constructed in standard programming.
  +     * <p><code>NumberUtils</code> instances should NOT be constructed
in standard programming.
        * Instead, the class should be used as <code>NumberUtils.stringToInt("6");</code>.</p>
        *
        * <p>This constructor is public to permit tools that require a JavaBean instance
  
  
  
  1.4       +40 -1     jakarta-commons/lang/src/test/org/apache/commons/lang/NumberUtilsTest.java
  
  Index: NumberUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/NumberUtilsTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- NumberUtilsTest.java	22 Nov 2002 23:30:32 -0000	1.3
  +++ NumberUtilsTest.java	15 Dec 2002 16:53:28 -0000	1.4
  @@ -511,4 +511,43 @@
           }
       }
   
  +    public void testConstants() {
  +        assertTrue(NumberUtils.LONG_ZERO instanceof Long);
  +        assertTrue(NumberUtils.LONG_ONE instanceof Long);
  +        assertTrue(NumberUtils.LONG_MINUS_ONE instanceof Long);
  +        assertTrue(NumberUtils.INTEGER_ZERO instanceof Integer);
  +        assertTrue(NumberUtils.INTEGER_ONE instanceof Integer);
  +        assertTrue(NumberUtils.INTEGER_MINUS_ONE instanceof Integer);
  +        assertTrue(NumberUtils.SHORT_ZERO instanceof Short);
  +        assertTrue(NumberUtils.SHORT_ONE instanceof Short);
  +        assertTrue(NumberUtils.SHORT_MINUS_ONE instanceof Short);
  +        assertTrue(NumberUtils.BYTE_ZERO instanceof Byte);
  +        assertTrue(NumberUtils.BYTE_ONE instanceof Byte);
  +        assertTrue(NumberUtils.BYTE_MINUS_ONE instanceof Byte);
  +        assertTrue(NumberUtils.DOUBLE_ZERO instanceof Double);
  +        assertTrue(NumberUtils.DOUBLE_ONE instanceof Double);
  +        assertTrue(NumberUtils.DOUBLE_MINUS_ONE instanceof Double);
  +        assertTrue(NumberUtils.FLOAT_ZERO instanceof Float);
  +        assertTrue(NumberUtils.FLOAT_ONE instanceof Float);
  +        assertTrue(NumberUtils.FLOAT_MINUS_ONE instanceof Float);
  +        
  +        assertTrue(NumberUtils.LONG_ZERO.longValue() == 0);
  +        assertTrue(NumberUtils.LONG_ONE.longValue() == 1);
  +        assertTrue(NumberUtils.LONG_MINUS_ONE.longValue() == -1);
  +        assertTrue(NumberUtils.INTEGER_ZERO.intValue() == 0);
  +        assertTrue(NumberUtils.INTEGER_ONE.intValue() == 1);
  +        assertTrue(NumberUtils.INTEGER_MINUS_ONE.intValue() == -1);
  +        assertTrue(NumberUtils.SHORT_ZERO.shortValue() == 0);
  +        assertTrue(NumberUtils.SHORT_ONE.shortValue() == 1);
  +        assertTrue(NumberUtils.SHORT_MINUS_ONE.shortValue() == -1);
  +        assertTrue(NumberUtils.BYTE_ZERO.byteValue() == 0);
  +        assertTrue(NumberUtils.BYTE_ONE.byteValue() == 1);
  +        assertTrue(NumberUtils.BYTE_MINUS_ONE.byteValue() == -1);
  +        assertTrue(NumberUtils.DOUBLE_ZERO.doubleValue() == 0.0d);
  +        assertTrue(NumberUtils.DOUBLE_ONE.doubleValue() == 1.0d);
  +        assertTrue(NumberUtils.DOUBLE_MINUS_ONE.doubleValue() == -1.0d);
  +        assertTrue(NumberUtils.FLOAT_ZERO.floatValue() == 0.0f);
  +        assertTrue(NumberUtils.FLOAT_ONE.floatValue() == 1.0f);
  +        assertTrue(NumberUtils.FLOAT_MINUS_ONE.floatValue() == -1.0f);
  +    }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message