[teiid-commits] teiid SVN: r1285 - in trunk/engine/src: test/java/com/metamatrix/query/function and 1 other directory.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Thu Aug 27 15:04:17 EDT 2009


Author: shawkins
Date: 2009-08-27 15:04:17 -0400 (Thu, 27 Aug 2009)
New Revision: 1285

Modified:
   trunk/engine/src/main/java/com/metamatrix/query/function/FunctionMethods.java
   trunk/engine/src/test/java/com/metamatrix/query/function/TestFunction.java
Log:
TEIID-671 mod with big integer inputs should use the remainder function, not mod

Modified: trunk/engine/src/main/java/com/metamatrix/query/function/FunctionMethods.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/function/FunctionMethods.java	2009-08-27 15:04:32 UTC (rev 1284)
+++ trunk/engine/src/main/java/com/metamatrix/query/function/FunctionMethods.java	2009-08-27 19:04:17 UTC (rev 1285)
@@ -154,23 +154,29 @@
 
 	// ================== Function = abs =====================
 
-	public static Object abs(Object x) throws FunctionExecutionException {
-		if(x instanceof Integer) {
-			return new Integer(Math.abs(((Integer)x).intValue()));
-		} else if(x instanceof Long) {
-			return new Long(Math.abs(((Long)x).longValue()));
-		} else if(x instanceof Float) {
-			return new Float(Math.abs(((Float)x).floatValue()));
-		} else if(x instanceof Double) {
-			return new Double(Math.abs(((Double)x).doubleValue()));
-		} else if(x instanceof BigInteger) {
-			return ((BigInteger)x).abs();
-		} else if(x instanceof BigDecimal) {
-			return ((BigDecimal)x).abs();
-		}
-
-		throw new FunctionExecutionException(ErrorMessageKeys.FUNCTION_0015, QueryPlugin.Util.getString(ErrorMessageKeys.FUNCTION_0015, "abs", x.getClass().getName())); //$NON-NLS-1$
+	public static int abs(int x) {
+		return Math.abs(x);
 	}
+	
+	public static long abs(long x) {
+		return Math.abs(x);
+	}
+	
+	public static float abs(float x) {
+		return Math.abs(x);
+	}
+	
+	public static double abs(double x) {
+		return Math.abs(x);
+	}
+	
+	public static Object abs(BigInteger x) {
+		return x.abs();
+	}
+	
+	public static Object abs(BigDecimal x) {
+		return x.abs();
+	}
 
 	// ================== Function = ceiling =====================
 
@@ -226,38 +232,30 @@
     
 	// ================== Function = mod =====================
 
-	public static  Object mod(Object x, Object y) throws FunctionExecutionException {
-		if(x == null || y == null) {
-			return null;
-		} else if(x instanceof Integer) {
-			if(y instanceof Integer) {
-				return new Integer(((Integer)x).intValue() % ((Integer)y).intValue());
-			}
-		} else if(x instanceof Long) {
-			if(y instanceof Long) {
-				return new Long(((Long)x).longValue() % ((Long)y).longValue());
-			}
-		} else if(x instanceof Float) {
-			if(y instanceof Float) {
-				return new Float(((Float)x).floatValue() % ((Float)y).floatValue());
-			}
-		} else if(x instanceof Double) {
-			if(y instanceof Double) {
-				return new Double(((Double)x).doubleValue() % ((Double)y).doubleValue());
-			}
-		} else if(x instanceof BigInteger) {
-			if(y instanceof BigInteger) {
-				return ((BigInteger)x).mod((BigInteger) y);
-			}
-		} else if(x instanceof BigDecimal) {
-			if(y instanceof BigDecimal) {
-				return ((BigDecimal)x).remainder((BigDecimal) y);
-			}
-		}
-
-		throw new FunctionExecutionException(ErrorMessageKeys.FUNCTION_0007, QueryPlugin.Util.getString(ErrorMessageKeys.FUNCTION_0007, new Object[]{"mod", x.getClass().getName(), y.getClass().getName()})); //$NON-NLS-1$
+	public static int mod(int x, int y) {
+		return x % y;
 	}
-
+	
+	public static long mod(long x, long y) {
+		return x % y;
+	}
+	
+	public static float mod(float x, float y) {
+		return x % y;
+	}
+	
+	public static double mod(double x, double y) {
+		return x % y;
+	}
+	
+	public static Object mod(BigInteger x, BigInteger y) {
+		return x.remainder(y);
+	}
+	
+	public static Object mod(BigDecimal x, BigDecimal y) {
+		return x.remainder(y);
+	}
+    
 	// ================== Function = power =====================
 	
 	public static double power(double x, double y) {

Modified: trunk/engine/src/test/java/com/metamatrix/query/function/TestFunction.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/function/TestFunction.java	2009-08-27 15:04:32 UTC (rev 1284)
+++ trunk/engine/src/test/java/com/metamatrix/query/function/TestFunction.java	2009-08-27 19:04:17 UTC (rev 1285)
@@ -1170,4 +1170,28 @@
     	assertEquals(TimestampUtil.createTime(15, 0, 0), FunctionMethods.parseTime(" 15:00:00 ", "HH:mm:ss")); //$NON-NLS-1$ //$NON-NLS-2$
     }
     
+    @Test public void testMod() {
+        assertEquals(new BigDecimal("-1.1"), FunctionMethods.mod(new BigDecimal("-3.1"), new BigDecimal("2")));   //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+    
+    @Test public void testMod1() {
+        assertEquals(new BigDecimal("-1.1"), FunctionMethods.mod(new BigDecimal("-3.1"), new BigDecimal("-2")));   //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+    
+    @Test public void testMod2() {
+        assertEquals(-40, FunctionMethods.mod(-340, 60), 0);
+    }
+    
+    @Test public void testMod3() {
+        assertEquals(-40, FunctionMethods.mod(-340, -60), 0);
+    }
+    
+    @Test public void testMod4() {
+        assertEquals(new BigInteger("-1"), FunctionMethods.mod(new BigInteger("-3"), new BigInteger("2")));   //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+    
+    @Test public void testMod5() {
+        assertEquals(new BigInteger("-1"), FunctionMethods.mod(new BigInteger("-3"), new BigInteger("-2")));   //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+    
 }



More information about the teiid-commits mailing list