You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vxquery.apache.org by pr...@apache.org on 2012/08/03 04:16:29 UTC

svn commit: r1368774 - /incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToBooleanOperation.java

Author: prestonc
Date: Fri Aug  3 02:16:29 2012
New Revision: 1368774

URL: http://svn.apache.org/viewvc?rev=1368774&view=rev
Log:
Updated class to be based on false (0) instead of true based on the specifications.

Modified:
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToBooleanOperation.java

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToBooleanOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToBooleanOperation.java?rev=1368774&r1=1368773&r2=1368774&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToBooleanOperation.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToBooleanOperation.java Fri Aug  3 02:16:29 2012
@@ -5,6 +5,7 @@ import java.io.IOException;
 
 import org.apache.vxquery.datamodel.accessors.atomic.XSDecimalPointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.exceptions.ErrorCode;
 import org.apache.vxquery.exceptions.SystemException;
 import org.apache.vxquery.runtime.functions.strings.ICharacterIterator;
 import org.apache.vxquery.runtime.functions.strings.LowerCaseCharacterIterator;
@@ -27,78 +28,97 @@ public class CastToBooleanOperation exte
     @Override
     public void convertDecimal(XSDecimalPointable decp, DataOutput dOut) throws SystemException, IOException {
         dOut.write(ValueTag.XS_BOOLEAN_TAG);
-        if (decp.getDecimalValue() == 1 && decp.getBeforeDecimalPlace() == 0) {
-            dOut.write(1);
-        } else {
+        if (decp.getDecimalValue() == 0 && decp.getBeforeDecimalPlace() == 0) {
             dOut.write(0);
+        } else {
+            dOut.write(1);
         }
     }
 
     @Override
     public void convertDouble(DoublePointable doublep, DataOutput dOut) throws SystemException, IOException {
         dOut.write(ValueTag.XS_BOOLEAN_TAG);
-        if (doublep.getDouble() == 1) {
-            dOut.write(1);
-        } else {
+        if (Double.isNaN(doublep.getDouble()) || doublep.getDouble() == 0) {
             dOut.write(0);
+        } else {
+            dOut.write(1);
         }
     }
 
     @Override
     public void convertFloat(FloatPointable floatp, DataOutput dOut) throws SystemException, IOException {
         dOut.write(ValueTag.XS_BOOLEAN_TAG);
-        if (floatp.getFloat() == 1) {
-            dOut.write(1);
-        } else {
+        if (Float.isNaN(floatp.getFloat()) || floatp.getFloat() == 0) {
             dOut.write(0);
+        } else {
+            dOut.write(1);
         }
     }
 
     @Override
     public void convertInteger(LongPointable longp, DataOutput dOut) throws SystemException, IOException {
         dOut.write(ValueTag.XS_BOOLEAN_TAG);
-        if (longp.getLong() == 1) {
-            dOut.write(1);
-        } else {
+        if (longp.getLong() == 0) {
             dOut.write(0);
+        } else {
+            dOut.write(1);
         }
     }
 
     @Override
     public void convertString(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
-        byte result = 0;
+        byte result = 2;
         ICharacterIterator charIterator = new LowerCaseCharacterIterator(new UTF8StringCharacterIterator(stringp));
         charIterator.reset();
         int c;
+        int checkValue = 2;
         search: for (int index = 0; (c = charIterator.next()) != ICharacterIterator.EOS_CHAR; ++index) {
             switch (index) {
                 case 0:
                     if (c == Character.valueOf('1')) {
                         result = 1;
-                    } else if (c != Character.valueOf('t')) {
+                    } else if (c == Character.valueOf('0')) {
+                        result = 0;
+                    } else if (c == Character.valueOf('t')) {
+                        checkValue = 1;
+                    } else if (c != Character.valueOf('f')) {
+                        checkValue = 0;
+                    } else {
                         break search;
                     }
                     break;
                 case 1:
-                    if (c != Character.valueOf('r')) {
+                    if ((checkValue == 1 && c != Character.valueOf('r'))
+                            || (checkValue == 0 && c != Character.valueOf('a'))) {
                         break search;
                     }
                     break;
                 case 2:
-                    if (c != Character.valueOf('u')) {
+                    if ((checkValue == 1 && c != Character.valueOf('u'))
+                            || (checkValue == 0 && c != Character.valueOf('l'))) {
                         break search;
                     }
                     break;
                 case 3:
-                    if (c == Character.valueOf('e')) {
+                    if (checkValue == 1 && c == Character.valueOf('e')) {
                         result = 1;
                     }
+                    if (checkValue == 0 && c != Character.valueOf('s')) {
+                        break search;
+                    }
+                    break;
+                case 4:
+                    if (checkValue == 0 && c == Character.valueOf('e')) {
+                        result = 0;
+                    }
                     break;
                 default:
-                    result = 0;
                     break search;
             }
         }
+        if (result == 2) {
+            throw new SystemException(ErrorCode.FORG0001);
+        }
         dOut.write(ValueTag.XS_BOOLEAN_TAG);
         dOut.write(result);
     }