db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1489348 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/types/SqlXmlUtil.java iapi/util/StringUtil.java impl/store/raw/data/OverflowInputStream.java
Date Tue, 04 Jun 2013 09:08:46 GMT
Author: kahatlen
Date: Tue Jun  4 09:08:45 2013
New Revision: 1489348

URL: http://svn.apache.org/r1489348
Log:
DERBY-6213: Deprecate support for Java 5 and CDC

Use Java 6 library methods to simplify logic in some cases.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/StringUtil.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/OverflowInputStream.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java?rev=1489348&r1=1489347&r2=1489348&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java Tue Jun  4
09:08:45 2013
@@ -720,31 +720,18 @@ public class SqlXmlUtil
             // BigDecimal doesn't know how to handle NaN or +/- infinity, so
             // use Double to handle those cases.
             return Double.toString(d);
+        } else if (d == 0.0d) {
+            // If the result is zero, return plain "0". This special case is
+            // needed because BigDecimal.stripTrailingZeros() does not remove
+            // trailing zeros from zero, and will end up producing "0.0", see
+            // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6480539
+            return "0";
         } else {
             // Otherwise, use BigDecimal to format the number the way we want.
-            // Ideally, we'd just return
-            // BigDecimal.valueOf(d).stripTrailingZeros().toPlainString(),
-            // but valueOf(double), stripTrailingZeros() and toPlainString()
-            // were all introduced in Java 5, and we still need to support
-            // older platforms.
-            BigDecimal dec = new BigDecimal(Double.toString(d));
-
-            // See how many trailing zeros we have after the decimal point.
-            long unscaledValue = dec.unscaledValue().longValue();
-            int scale = dec.scale();
-            while (scale > 0 && unscaledValue % 10 == 0) {
-                scale--;
-                unscaledValue /= 10;
-            }
-
-            // If we have trailing zeros after the decimal point, remove them.
-            if (scale != dec.scale()) {
-                dec = BigDecimal.valueOf(unscaledValue, scale);
-            }
-
-            // Finally, convert the value to a string. The method
-            // BigDecimal.toPlainString() formats the number the way we want.
-            return dec.toPlainString();
+            // We could have used Double to format it, but then the resulting
+            // string would have been in scientific format (like 1.0e-3), and
+            // we want it to be in plain format (like 0.001).
+            return BigDecimal.valueOf(d).stripTrailingZeros().toPlainString();
         }
     }
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/StringUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/StringUtil.java?rev=1489348&r1=1489347&r2=1489348&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/StringUtil.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/StringUtil.java Tue Jun  4
09:08:45 2013
@@ -462,29 +462,6 @@ public class StringUtil 
         return quoteString(string, '\'');
     }
 
-    /**
-     * Turn an array of ints into a printable string. Returns what's returned
-     * in Java 5 by java.util.Arrays.toString(int[]).
-     */
-    public  static  String  stringify( int[] raw )
-    {
-        if ( raw == null ) { return "null"; }
-        
-        StringBuffer    buffer = new StringBuffer();
-        int                 count = raw.length;
-
-        buffer.append( "[ " );
-        for ( int i = 0; i < count; i++ )
-        {
-            if ( i > 0 ) { buffer.append( ", " ); }
-            buffer.append( raw[ i ] );
-        }
-        buffer.append( " ]" );
-
-        return buffer.toString();
-    }
-
-
 	/**
 	 * Utility for formatting which bends a multi-line string into shape for
 	 * outputting it in a context where there is <i>depth</i> tabs. Trailing

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/OverflowInputStream.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/OverflowInputStream.java?rev=1489348&r1=1489347&r2=1489348&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/OverflowInputStream.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/OverflowInputStream.java
Tue Jun  4 09:08:45 2013
@@ -165,11 +165,7 @@ implements Resetable, CloneableStream
             }
             catch (StandardException se)
             {
-                // Simplify this code when we can use the Java 1.5 constructor
-                // taking the cause as an argument.
-                IOException ioe = new IOException(se.toString());
-                ioe.initCause(se);
-                throw ioe;
+                throw new IOException(se);
             }
 
             this.bh.startReading();



Mime
View raw message