db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r180029 - in /incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types: BigIntegerDecimal.java BinaryDecimal.java SQLDecimal.java
Date Sat, 04 Jun 2005 21:55:52 GMT
Author: djd
Date: Sat Jun  4 14:55:51 2005
New Revision: 180029

URL: http://svn.apache.org/viewcvs?rev=180029&view=rev
Log:
More updates to J2ME's DECIMAL implementation, fix the clone
method, implement toString and hashCode.

Modified:
    incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/BigIntegerDecimal.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/BinaryDecimal.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/BigIntegerDecimal.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/BigIntegerDecimal.java?rev=180029&r1=180028&r2=180029&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/BigIntegerDecimal.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/BigIntegerDecimal.java
Sat Jun  4 14:55:51 2005
@@ -131,8 +131,32 @@
 				if (dot > ePosition)
 					throw invalidFormat();
 				
+				// Integer.parseInt does not handle a + sign in
+				// front of the number, while the format for the
+				// exponent allows it. Need to strip it off.
+				
+				int expOffset = ePosition + 1;
+
+				if (expOffset >= theValue.length())
+					throw invalidFormat();
+				
+				if (theValue.charAt(expOffset) == '+')
+				{
+					// strip the plus but must ensure the next character
+					// is not a - sign. Any other invalid sign will be handled
+					// by Integer.parseInt.
+					expOffset++;
+					if (expOffset >= theValue.length())
+						throw invalidFormat();
+					if (theValue.charAt(expOffset) == '-')
+						throw invalidFormat();
+				}
+				
+				String exponent = theValue.substring(expOffset);
+				
+				
 				//	TODO Need to handle a + sign in the exponent
-				scale = -1 * Integer.parseInt(theValue.substring(ePosition + 1));
+				scale = -1 * Integer.parseInt(exponent);
 				theValue = theValue.substring(0, ePosition);
 			}
 			
@@ -157,8 +181,6 @@
 			data2c = bi.toByteArray();
 			sqlScale = scale;
 			
-			//System.out.println("setValue unscaled " + bi + "scale " + sqlScale);
-
 		} catch (NumberFormatException nfe) 
 		{
 		    throw invalidFormat();
@@ -176,8 +198,7 @@
 		
 		// TODO - correct impl
 		String unscaled = new BigInteger(data2c).toString();
-		//System.out.println("Scale" + sqlScale + " unv " + unscaled);
-		
+				
 		if (sqlScale == 0)
 			return unscaled;
 
@@ -217,13 +238,15 @@
 		if (this.isNegative())
 			precision--;
 		
+		if (precision < sqlScale)
+			return sqlScale;
+		
 		return precision;
 	}
 	
 
 	/**
 	 * Compare two non-null NumberDataValues using DECIMAL arithmetic.
-	 * Uses add() to perform the calculation.
 	 */
 	protected int typeCompare(DataValueDescriptor arg) throws StandardException {
 		
@@ -232,7 +255,7 @@
 		// need to align scales to perform comparisions
 		int tscale = getDecimalValueScale();
 		int oscale = obid.getDecimalValueScale();
-		
+	
 		BigInteger tbi = new BigInteger(data2c);
 		BigInteger obi = new BigInteger(obid.data2c);
 		
@@ -240,7 +263,7 @@
 			tbi = BigIntegerDecimal.rescale(tbi, oscale - tscale);
 		else if (oscale < tscale)
 			obi = BigIntegerDecimal.rescale(obi, tscale - oscale);
-		
+	
 		return tbi.compareTo(obi);
 	}
 
@@ -497,5 +520,15 @@
 				bi = bi.divide(BigIntegerDecimal.TEN);
 		}
 		return bi;
+	}
+	/*
+	 * String display of value
+	 */
+	public String toString()
+	{
+		if (isNull())
+			return "NULL";
+		else
+			return getString();
 	}
 }

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/BinaryDecimal.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/BinaryDecimal.java?rev=180029&r1=180028&r2=180029&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/BinaryDecimal.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/BinaryDecimal.java
Sat Jun  4 14:55:51 2005
@@ -662,8 +662,13 @@
 	public DataValueDescriptor getClone() {
 		BinaryDecimal dvd = (BinaryDecimal) getNewNull();
 		
-		dvd.data2c = this.data2c;
-		dvd.sqlScale = this.sqlScale;
+		if (this.data2c != null)
+		{
+			dvd.data2c = new byte[data2c.length];
+			System.arraycopy(data2c, 0, dvd.data2c, 0, data2c.length);
+			dvd.sqlScale = sqlScale;
+		}
+		
 		return dvd;
 	}
 
@@ -682,5 +687,18 @@
 	public int estimateMemoryUsage() {
 		// TODO Auto-generated method stub
 		return 0;
+	}
+	
+	public int hashCode()
+	{
+		if (isNull())
+			return 0;
+
+		try {
+			return (int) Double.doubleToLongBits(getDouble());
+		} catch (StandardException se)
+		{
+			return 0;
+		}
 	}
 }

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java?rev=180029&r1=180028&r2=180029&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java Sat
Jun  4 14:55:51 2005
@@ -561,7 +561,6 @@
 	protected int typeCompare(DataValueDescriptor arg) throws StandardException
 	{
 		BigDecimal otherValue = SQLDecimal.getBigDecimal(arg);
-
 		return getBigDecimal().compareTo(otherValue);
 	}
 
@@ -1008,7 +1007,7 @@
 		if (isNull())
 			return "NULL";
 		else
-			return getBigDecimal().toString();
+			return getString();
 	}
 
 	/*



Mime
View raw message