Repository: groovy
Updated Branches:
  refs/heads/master 8b11b22f1 -> 679eb23ce


formatting


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/679eb23c
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/679eb23c
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/679eb23c

Branch: refs/heads/master
Commit: 679eb23cea2858dec2ea2e24e5a896ef2350797a
Parents: 8b11b22
Author: paulk <pa...@asert.com.au>
Authored: Mon Jul 25 19:29:33 2016 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Mon Jul 25 19:29:33 2016 +1000

----------------------------------------------------------------------
 .../groovy/runtime/typehandling/NumberMath.java | 103 ++++++++++---------
 src/test/groovy/NumberMathTest.groovy           |  20 ++--
 2 files changed, 62 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/679eb23c/src/main/org/codehaus/groovy/runtime/typehandling/NumberMath.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/typehandling/NumberMath.java 
b/src/main/org/codehaus/groovy/runtime/typehandling/NumberMath.java
index 0ef83a0..c953ffd 100644
--- a/src/main/org/codehaus/groovy/runtime/typehandling/NumberMath.java
+++ b/src/main/org/codehaus/groovy/runtime/typehandling/NumberMath.java
@@ -21,75 +21,71 @@ package org.codehaus.groovy.runtime.typehandling;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 
-
 /**
  * Stateless objects used to perform math on the various Number subclasses.
  * Instances are required so that polymorphic calls work properly, but each
  * subclass creates a singleton instance to minimize garbage.  All methods
  * must be thread-safe.
- * 
+ *
  * The design goals of this class are as follows:
  * <ol>
  * <li>Support a 'least surprising' math model to scripting language users.  
This
  * means that exact, or decimal math should be used for default calculations.  
This
  * scheme assumes that by default, groovy literals with decimal points are 
instantiated
- * as BigDecimal objects rather than binary floating points (Float, Double). 
- * <li>Do not force the appearance of exactness on a number that is by 
definition not 
- * guaranteed to be exact.  In particular this means that if an operand in a 
NumberMath 
- * operation is a binary floating point number, ensure that the result remains 
a binary floating point 
- * number (i.e. never automatically promote a binary floating point number to 
a BigDecimal).  
+ * as BigDecimal objects rather than binary floating points (Float, Double).
+ * <li>Do not force the appearance of exactness on a number that is by 
definition not
+ * guaranteed to be exact.  In particular this means that if an operand in a 
NumberMath
+ * operation is a binary floating point number, ensure that the result remains 
a binary floating point
+ * number (i.e. never automatically promote a binary floating point number to 
a BigDecimal).
  * This has the effect of preserving the expectations of binary floating point 
users and helps performance.
- * <li>Provide an implementation that is as close as practical to the Java 1.5 
BigDecimal math model 
- * which implements precision based floating point decimal math (ANSI 
X3.274-1996 and 
- * ANSI X3.274-1996/AM 1-2000 (section 7.4).  
+ * <li>Provide an implementation that is as close as practical to the Java 1.5 
BigDecimal math model which implements
+ * precision based floating point decimal math (ANSI X3.274-1996 and ANSI 
X3.274-1996/AM 1-2000 (section 7.4).
  * </ol>
- * 
- * @author Steve Goetze
  */
 public abstract class NumberMath {
-        
+
     public static Number abs(Number number) {
         return getMath(number).absImpl(number);
     }
-    
+
     public static Number add(Number left, Number right) {
-        return getMath(left, right).addImpl(left,right);
+        return getMath(left, right).addImpl(left, right);
     }
-    
+
     public static Number subtract(Number left, Number right) {
-        return getMath(left,right).subtractImpl(left,right);
+        return getMath(left, right).subtractImpl(left, right);
     }
-    
+
     public static Number multiply(Number left, Number right) {
-        return getMath(left,right).multiplyImpl(left,right);
+        return getMath(left, right).multiplyImpl(left, right);
     }
-    
+
     public static Number divide(Number left, Number right) {
-        return getMath(left,right).divideImpl(left,right);
-     }
-      
+        return getMath(left, right).divideImpl(left, right);
+    }
+
     public static int compareTo(Number left, Number right) {
-        return getMath(left,right).compareToImpl(left, right);
+        return getMath(left, right).compareToImpl(left, right);
     }
-    
+
     public static Number or(Number left, Number right) {
-        return getMath(left,right).orImpl(left, right);
+        return getMath(left, right).orImpl(left, right);
     }
-    
+
     public static Number and(Number left, Number right) {
-        return getMath(left,right).andImpl(left, right);
+        return getMath(left, right).andImpl(left, right);
     }
-    
+
     public static Number xor(Number left, Number right) {
-        return getMath(left,right).xorImpl(left, right);
+        return getMath(left, right).xorImpl(left, right);
     }
-    
+
     public static Number intdiv(Number left, Number right) {
-        return getMath(left,right).intdivImpl(left,right);
-     }
+        return getMath(left, right).intdivImpl(left, right);
+    }
 
     public static Number mod(Number left, Number right) {
-        return getMath(left,right).modImpl(left, right);
+        return getMath(left, right).modImpl(left, right);
     }
 
     /**
@@ -100,11 +96,11 @@ public abstract class NumberMath {
      */
     public static Number leftShift(Number left, Number right) {
         if (isFloatingPoint(right) || isBigDecimal(right)) {
-            throw new UnsupportedOperationException("Shift distance must be an 
integral type, but " +  right + " (" + right.getClass().getName() + ") was 
supplied");
+            throw new UnsupportedOperationException("Shift distance must be an 
integral type, but " + right + " (" + right.getClass().getName() + ") was 
supplied");
         }
-        return getMath(left).leftShiftImpl(left,right);
+        return getMath(left).leftShiftImpl(left, right);
     }
-    
+
     /**
      * For this operation, consider the operands independently.  Throw an 
exception if the right operand
      * (shift distance) is not an integral type.  For the left operand (shift 
value) also require an integral
@@ -113,11 +109,11 @@ public abstract class NumberMath {
      */
     public static Number rightShift(Number left, Number right) {
         if (isFloatingPoint(right) || isBigDecimal(right)) {
-            throw new UnsupportedOperationException("Shift distance must be an 
integral type, but " +  right + " (" + right.getClass().getName() + ") was 
supplied");
+            throw new UnsupportedOperationException("Shift distance must be an 
integral type, but " + right + " (" + right.getClass().getName() + ") was 
supplied");
         }
-        return getMath(left).rightShiftImpl(left,right);
+        return getMath(left).rightShiftImpl(left, right);
     }
-    
+
     /**
      * For this operation, consider the operands independently.  Throw an 
exception if the right operand
      * (shift distance) is not an integral type.  For the left operand (shift 
value) also require an integral
@@ -126,9 +122,9 @@ public abstract class NumberMath {
      */
     public static Number rightShiftUnsigned(Number left, Number right) {
         if (isFloatingPoint(right) || isBigDecimal(right)) {
-            throw new UnsupportedOperationException("Shift distance must be an 
integral type, but " +  right + " (" + right.getClass().getName() + ") was 
supplied");
+            throw new UnsupportedOperationException("Shift distance must be an 
integral type, but " + right + " (" + right.getClass().getName() + ") was 
supplied");
         }
-        return getMath(left).rightShiftUnsignedImpl(left,right);
+        return getMath(left).rightShiftUnsignedImpl(left, right);
     }
 
     public static Number bitwiseNegate(Number left) {
@@ -166,11 +162,11 @@ public abstract class NumberMath {
     public static BigDecimal toBigDecimal(Number n) {
         return (n instanceof BigDecimal ? (BigDecimal) n : new 
BigDecimal(n.toString()));
     }
-                
+
     public static BigInteger toBigInteger(Number n) {
         return (n instanceof BigInteger ? (BigInteger) n : new 
BigInteger(n.toString()));
     }
-                    
+
     /**
      * Determine which NumberMath instance to use, given the supplied 
operands.  This method implements
      * the type promotion rules discussed in the documentation.  Note that by 
the time this method is
@@ -197,7 +193,7 @@ public abstract class NumberMath {
         if (isBigInteger(left) || isBigInteger(right)) {
             return BigIntegerMath.INSTANCE;
         }
-        if (isLong(left) || isLong(right)){
+        if (isLong(left) || isLong(right)) {
             return LongMath.INSTANCE;
         }
         return IntegerMath.INSTANCE;
@@ -209,7 +205,7 @@ public abstract class NumberMath {
         }
         if (isFloatingPoint(number)) {
             return FloatingPointMath.INSTANCE;
-        }            
+        }
         if (isBigDecimal(number)) {
             return BigDecimalMath.INSTANCE;
         }
@@ -218,15 +214,22 @@ public abstract class NumberMath {
         }
         return IntegerMath.INSTANCE;
     }
-    
+
     //Subclasses implement according to the type promotion hierarchy rules
     protected abstract Number absImpl(Number number);
+
     public abstract Number addImpl(Number left, Number right);
+
     public abstract Number subtractImpl(Number left, Number right);
+
     public abstract Number multiplyImpl(Number left, Number right);
+
     public abstract Number divideImpl(Number left, Number right);
+
     public abstract int compareToImpl(Number left, Number right);
+
     protected abstract Number unaryMinusImpl(Number left);
+
     protected abstract Number unaryPlusImpl(Number left);
 
     protected Number bitwiseNegateImpl(Number left) {
@@ -244,15 +247,15 @@ public abstract class NumberMath {
     protected Number xorImpl(Number left, Number right) {
         throw createUnsupportedException("xor()", left);
     }
-    
+
     protected Number modImpl(Number left, Number right) {
         throw createUnsupportedException("mod()", left);
     }
-    
+
     protected Number intdivImpl(Number left, Number right) {
         throw createUnsupportedException("intdiv()", left);
     }
-    
+
     protected Number leftShiftImpl(Number left, Number right) {
         throw createUnsupportedException("leftShift()", left);
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/679eb23c/src/test/groovy/NumberMathTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/NumberMathTest.groovy 
b/src/test/groovy/NumberMathTest.groovy
index 2ab8d88..686a5ee 100644
--- a/src/test/groovy/NumberMathTest.groovy
+++ b/src/test/groovy/NumberMathTest.groovy
@@ -18,9 +18,7 @@
  */
 package groovy
 
-import junit.framework.Assert
-
-/** 
+/**
  * Basic NumberMath test.
  * @see org.codehaus.groovy.runtime.typehandling.NumberMath
  */
@@ -111,9 +109,9 @@ class NumberMathTest extends GroovyTestCase {
         assert I1 / I2 instanceof BigDecimal
         assert I1 / I2 == new BigDecimal("0.5")
         assert F1 / F2 instanceof Double
-        Assert.assertEquals F1 / F2, 0.5, 0.0000000001
+        assertEquals F1 / F2, 0.5, 0.0000000001
         assert D1 / D2 instanceof Double
-        Assert.assertEquals D1 / D2, 0.5, 0.0000000001
+        assertEquals D1 / D2, 0.5, 0.0000000001
 
         assert I1.intdiv(I2) instanceof Integer
         assert I1.intdiv(I2) == 0
@@ -149,14 +147,14 @@ class NumberMathTest extends GroovyTestCase {
     void testUnsupportedIntDivision() {
         try {
             1.0.intdiv(3)
-        } catch (UnsupportedOperationException uoe) {
+        } catch (UnsupportedOperationException ignore) {
             return
         }
         fail("Should catch an UnsupportedOperationException")
 
         try {
             1.0G.intdiv(3)
-        } catch (UnsupportedOperationException uoe) {
+        } catch (UnsupportedOperationException ignore) {
             return
         }
         fail("Should catch an UnsupportedOperationException")
@@ -166,17 +164,17 @@ class NumberMathTest extends GroovyTestCase {
         assert 20 == new Short("10") << 1
         assert 2 == new Byte("1") << 1
     }
-    
+
     void testLongDivAssign() {
         long d = 100L
         d /= 33L
         assert d.class == Long.class
     }
-    
+
     void testIntegerPlusCastException() {
         shouldFail(ClassCastException) {
-           Integer i = 12
-           i += " angry men"
+            Integer i = 12
+            i += " angry men"
         }
     }
 }

Reply via email to