incubator-vxquery-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prest...@apache.org
Subject svn commit: r1388170 - in /incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions: cast/CastToStringOperation.java util/FunctionHelper.java
Date Thu, 20 Sep 2012 19:28:45 GMT
Author: prestonc
Date: Thu Sep 20 19:28:45 2012
New Revision: 1388170

URL: http://svn.apache.org/viewvc?rev=1388170&view=rev
Log:
Added a function to print the UFT8 String Pointable. Helpful in some testing situations.

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

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToStringOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToStringOperation.java?rev=1388170&r1=1388169&r2=1388170&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToStringOperation.java
(original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToStringOperation.java
Thu Sep 20 19:28:45 2012
@@ -682,14 +682,6 @@ public class CastToStringOperation exten
 
     @Override
     public void convertString(UTF8StringPointable stringp, DataOutput dOut) throws SystemException,
IOException {
-        //        System.err.println(" convertString in CastToString length = " + stringp.getUTFLength());
-        //        ICharacterIterator charIterator = new UTF8StringCharacterIterator(stringp);
-        //        charIterator.reset();
-        //        for (int c = charIterator.next(); c != ICharacterIterator.EOS_CHAR; c =
charIterator.next()) {
-        //            System.err.println("   parse value '" + c + "' as '" + Character.valueOf((char)
c) + "'");
-        //        }
-        //        System.err.println(" convertString in CastToString AFTER");
-
         dOut.write(returnTag);
         dOut.write(stringp.getByteArray(), stringp.getStartOffset(), stringp.getLength());
     }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/util/FunctionHelper.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/util/FunctionHelper.java?rev=1388170&r1=1388169&r2=1388170&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/util/FunctionHelper.java
(original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/util/FunctionHelper.java
Thu Sep 20 19:28:45 2012
@@ -35,6 +35,8 @@ import org.apache.vxquery.datamodel.valu
 import org.apache.vxquery.exceptions.ErrorCode;
 import org.apache.vxquery.exceptions.SystemException;
 import org.apache.vxquery.runtime.functions.comparison.AbstractValueComparisonOperation;
+import org.apache.vxquery.runtime.functions.strings.ICharacterIterator;
+import org.apache.vxquery.runtime.functions.strings.UTF8StringCharacterIterator;
 import org.apache.vxquery.types.BuiltinTypeConstants;
 import org.apache.vxquery.types.BuiltinTypeRegistry;
 
@@ -68,409 +70,108 @@ public class FunctionHelper {
         public XSQNamePointable qnamep = (XSQNamePointable) XSQNamePointable.FACTORY.createPointable();
     }
 
-    public static int getBaseTypeForArithmetics(int tid) throws SystemException {
-        if (tid >= BuiltinTypeConstants.BUILTIN_TYPE_COUNT) {
-            throw new SystemException(ErrorCode.XPTY0004);
-        }
-        while (true) {
-            switch (tid) {
-                case ValueTag.XS_STRING_TAG:
+    public static boolean compareTaggedValues(AbstractValueComparisonOperation aOp, TaggedValuePointable
tvp1,
+            TaggedValuePointable tvp2, DynamicContext dCtx) throws SystemException {
+        final TypedPointables tp1 = new TypedPointables();
+        final TypedPointables tp2 = new TypedPointables();
+
+        boolean booleanResult = false;
+        int tid1 = getBaseTypeForComparisons(tvp1.getTag());
+        int tid2 = getBaseTypeForComparisons(tvp2.getTag());
+        try {
+            switch (tid1) {
                 case ValueTag.XS_DECIMAL_TAG:
-                case ValueTag.XS_INTEGER_TAG:
-                case ValueTag.XS_FLOAT_TAG:
-                case ValueTag.XS_DOUBLE_TAG:
-                case ValueTag.XS_ANY_URI_TAG:
-                case ValueTag.XS_BOOLEAN_TAG:
-                case ValueTag.XS_DATE_TAG:
-                case ValueTag.XS_DATETIME_TAG:
-                case ValueTag.XS_TIME_TAG:
-                case ValueTag.XS_DAY_TIME_DURATION_TAG:
-                case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
-                case ValueTag.XS_BASE64_BINARY_TAG:
-                case ValueTag.XS_HEX_BINARY_TAG:
-                case ValueTag.XS_QNAME_TAG:
-                case ValueTag.XS_G_DAY_TAG:
-                case ValueTag.XS_G_MONTH_DAY_TAG:
-                case ValueTag.XS_G_MONTH_TAG:
-                case ValueTag.XS_G_YEAR_MONTH_TAG:
-                case ValueTag.XS_G_YEAR_TAG:
-                case ValueTag.XS_UNTYPED_ATOMIC_TAG:
-                    return tid;
+                    tvp1.getValue(tp1.decp);
+                    switch (tid2) {
+                        case ValueTag.XS_DECIMAL_TAG:
+                            tvp2.getValue(tp2.decp);
+                            booleanResult = aOp.operateDecimalDecimal(tp1.decp, tp2.decp);
+                            break;
 
-                case ValueTag.XS_LONG_TAG:
-                case ValueTag.XS_NEGATIVE_INTEGER_TAG:
-                case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
-                case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
-                case ValueTag.XS_POSITIVE_INTEGER_TAG:
-                case ValueTag.XS_UNSIGNED_INT_TAG:
-                case ValueTag.XS_UNSIGNED_LONG_TAG:
-                case ValueTag.XS_INT_TAG:
-                case ValueTag.XS_UNSIGNED_SHORT_TAG:
-                case ValueTag.XS_SHORT_TAG:
-                case ValueTag.XS_UNSIGNED_BYTE_TAG:
-                case ValueTag.XS_BYTE_TAG:
-                    return ValueTag.XS_INTEGER_TAG;
+                        case ValueTag.XS_INTEGER_TAG:
+                            tvp2.getValue(tp2.longp);
+                            booleanResult = aOp.operateDecimalInteger(tp1.decp, tp2.longp);
+                            break;
 
-                case ValueTag.XS_ANY_ATOMIC_TAG:
-                    throw new SystemException(ErrorCode.XPTY0004);
+                        case ValueTag.XS_FLOAT_TAG:
+                            tvp2.getValue(tp2.floatp);
+                            booleanResult = aOp.operateDecimalFloat(tp1.decp, tp2.floatp);
+                            break;
 
-                default:
-                    tid = BuiltinTypeRegistry.INSTANCE.getSchemaTypeById(tid).getBaseType().getTypeId();
-                    return tid;
-            }
-        }
-    }
+                        case ValueTag.XS_DOUBLE_TAG:
+                            tvp2.getValue(tp2.doublep);
+                            booleanResult = aOp.operateDecimalDouble(tp1.decp, tp2.doublep);
+                            break;
+                    }
+                    break;
 
-    public static int getBaseTypeForComparisons(int tid) throws SystemException {
-        while (true) {
-            switch (tid) {
-                case ValueTag.XS_ANY_URI_TAG:
-                case ValueTag.XS_BASE64_BINARY_TAG:
-                case ValueTag.XS_BOOLEAN_TAG:
-                case ValueTag.XS_DATE_TAG:
-                case ValueTag.XS_DATETIME_TAG:
-                case ValueTag.XS_DAY_TIME_DURATION_TAG:
-                case ValueTag.XS_DECIMAL_TAG:
-                case ValueTag.XS_DOUBLE_TAG:
-                case ValueTag.XS_DURATION_TAG:
-                case ValueTag.XS_FLOAT_TAG:
-                case ValueTag.XS_HEX_BINARY_TAG:
                 case ValueTag.XS_INTEGER_TAG:
-                case ValueTag.XS_G_DAY_TAG:
-                case ValueTag.XS_G_MONTH_DAY_TAG:
-                case ValueTag.XS_G_MONTH_TAG:
-                case ValueTag.XS_G_YEAR_MONTH_TAG:
-                case ValueTag.XS_G_YEAR_TAG:
-                case ValueTag.XS_QNAME_TAG:
-                case ValueTag.XS_STRING_TAG:
-                case ValueTag.XS_TIME_TAG:
-                case ValueTag.XS_UNTYPED_ATOMIC_TAG:
-                case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
-                    return tid;
+                    tvp1.getValue(tp1.longp);
+                    switch (tid2) {
+                        case ValueTag.XS_DECIMAL_TAG:
+                            tvp2.getValue(tp2.decp);
+                            booleanResult = aOp.operateIntegerDecimal(tp1.longp, tp2.decp);
+                            break;
 
-                case ValueTag.XS_LONG_TAG:
-                case ValueTag.XS_NEGATIVE_INTEGER_TAG:
-                case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
-                case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
-                case ValueTag.XS_POSITIVE_INTEGER_TAG:
-                case ValueTag.XS_UNSIGNED_INT_TAG:
-                case ValueTag.XS_UNSIGNED_LONG_TAG:
-                case ValueTag.XS_INT_TAG:
-                case ValueTag.XS_UNSIGNED_SHORT_TAG:
-                case ValueTag.XS_SHORT_TAG:
-                case ValueTag.XS_UNSIGNED_BYTE_TAG:
-                case ValueTag.XS_BYTE_TAG:
-                    return ValueTag.XS_INTEGER_TAG;
+                        case ValueTag.XS_INTEGER_TAG:
+                            tvp2.getValue(tp2.longp);
+                            booleanResult = aOp.operateIntegerInteger(tp1.longp, tp2.longp);
+                            break;
 
-                case ValueTag.XS_ANY_ATOMIC_TAG:
-                    throw new SystemException(ErrorCode.XPTY0004);
+                        case ValueTag.XS_FLOAT_TAG:
+                            tvp2.getValue(tp2.floatp);
+                            booleanResult = aOp.operateIntegerFloat(tp1.longp, tp2.floatp);
+                            break;
 
-                default:
-                    tid = BuiltinTypeRegistry.INSTANCE.getSchemaTypeById(tid).getBaseType().getTypeId();
-            }
-        }
-    }
+                        case ValueTag.XS_DOUBLE_TAG:
+                            tvp2.getValue(tp2.doublep);
+                            booleanResult = aOp.operateIntegerDouble(tp1.longp, tp2.doublep);
+                            break;
+                    }
+                    break;
 
-    public static int getBaseTypeForGeneralComparisons(int tid) throws SystemException {
-        while (true) {
-            switch (tid) {
-                case ValueTag.XS_ANY_URI_TAG:
-                case ValueTag.XS_BASE64_BINARY_TAG:
-                case ValueTag.XS_BOOLEAN_TAG:
-                case ValueTag.XS_DATE_TAG:
-                case ValueTag.XS_DATETIME_TAG:
-                case ValueTag.XS_DAY_TIME_DURATION_TAG:
-                case ValueTag.XS_DURATION_TAG:
-                case ValueTag.XS_HEX_BINARY_TAG:
-                case ValueTag.XS_G_DAY_TAG:
-                case ValueTag.XS_G_MONTH_DAY_TAG:
-                case ValueTag.XS_G_MONTH_TAG:
-                case ValueTag.XS_G_YEAR_MONTH_TAG:
-                case ValueTag.XS_G_YEAR_TAG:
-                case ValueTag.XS_QNAME_TAG:
-                case ValueTag.XS_STRING_TAG:
-                case ValueTag.XS_TIME_TAG:
-                case ValueTag.XS_UNTYPED_ATOMIC_TAG:
-                case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
-                    return tid;
-                case ValueTag.XS_DECIMAL_TAG:
-                case ValueTag.XS_DOUBLE_TAG:
                 case ValueTag.XS_FLOAT_TAG:
-                case ValueTag.XS_INTEGER_TAG:
-                case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
-                case ValueTag.XS_NEGATIVE_INTEGER_TAG:
-                case ValueTag.XS_LONG_TAG:
-                case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
-                case ValueTag.XS_UNSIGNED_LONG_TAG:
-                case ValueTag.XS_POSITIVE_INTEGER_TAG:
-                case ValueTag.XS_INT_TAG:
-                case ValueTag.XS_UNSIGNED_INT_TAG:
-                case ValueTag.XS_SHORT_TAG:
-                case ValueTag.XS_UNSIGNED_SHORT_TAG:
-                case ValueTag.XS_BYTE_TAG:
-                case ValueTag.XS_UNSIGNED_BYTE_TAG:
-                    return ValueTag.XS_DOUBLE_TAG;
+                    tvp1.getValue(tp1.floatp);
+                    switch (tid2) {
+                        case ValueTag.XS_DECIMAL_TAG:
+                            tvp2.getValue(tp2.decp);
+                            booleanResult = aOp.operateFloatDecimal(tp1.floatp, tp2.decp);
+                            break;
 
-                case ValueTag.XS_ANY_ATOMIC_TAG:
-                    throw new SystemException(ErrorCode.XPTY0004);
+                        case ValueTag.XS_INTEGER_TAG:
+                            tvp2.getValue(tp2.longp);
+                            booleanResult = aOp.operateFloatInteger(tp1.floatp, tp2.longp);
+                            break;
 
-                default:
-                    tid = BuiltinTypeRegistry.INSTANCE.getSchemaTypeById(tid).getBaseType().getTypeId();
-            }
-        }
-    }
+                        case ValueTag.XS_FLOAT_TAG:
+                            tvp2.getValue(tp2.floatp);
+                            booleanResult = aOp.operateFloatFloat(tp1.floatp, tp2.floatp);
+                            break;
 
-    public static void getDoublePointable(TaggedValuePointable tvp, DataOutput dOut) throws
SystemException,
-            IOException {
-        TypedPointables tp = new TypedPointables();
-        double value;
-        switch (tvp.getTag()) {
-            case ValueTag.XS_DECIMAL_TAG:
-                tvp.getValue(tp.decp);
-                value = tp.decp.doubleValue();
-                break;
+                        case ValueTag.XS_DOUBLE_TAG:
+                            tvp2.getValue(tp2.doublep);
+                            booleanResult = aOp.operateFloatDouble(tp1.floatp, tp2.doublep);
+                            break;
+                    }
+                    break;
 
-            case ValueTag.XS_DOUBLE_TAG:
-                tvp.getValue(tp.doublep);
-                value = tp.doublep.doubleValue();
-                break;
+                case ValueTag.XS_DOUBLE_TAG:
+                    tvp1.getValue(tp1.doublep);
+                    switch (tid2) {
+                        case ValueTag.XS_DECIMAL_TAG:
+                            tvp2.getValue(tp2.decp);
+                            booleanResult = aOp.operateDoubleDecimal(tp1.doublep, tp2.decp);
+                            break;
 
-            case ValueTag.XS_FLOAT_TAG:
-                tvp.getValue(tp.floatp);
-                value = tp.floatp.doubleValue();
-                break;
+                        case ValueTag.XS_INTEGER_TAG:
+                            tvp2.getValue(tp2.longp);
+                            booleanResult = aOp.operateDoubleInteger(tp1.doublep, tp2.longp);
+                            break;
 
-            case ValueTag.XS_INTEGER_TAG:
-            case ValueTag.XS_LONG_TAG:
-            case ValueTag.XS_NEGATIVE_INTEGER_TAG:
-            case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
-            case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
-            case ValueTag.XS_POSITIVE_INTEGER_TAG:
-            case ValueTag.XS_UNSIGNED_INT_TAG:
-            case ValueTag.XS_UNSIGNED_LONG_TAG:
-                tvp.getValue(tp.longp);
-                value = tp.longp.doubleValue();
-                break;
-
-            case ValueTag.XS_INT_TAG:
-            case ValueTag.XS_UNSIGNED_SHORT_TAG:
-                tvp.getValue(tp.intp);
-                value = tp.intp.doubleValue();
-                break;
-
-            case ValueTag.XS_SHORT_TAG:
-            case ValueTag.XS_UNSIGNED_BYTE_TAG:
-                tvp.getValue(tp.shortp);
-                value = tp.shortp.doubleValue();
-                break;
-
-            case ValueTag.XS_BYTE_TAG:
-                tvp.getValue(tp.bytep);
-                value = tp.bytep.doubleValue();
-                break;
-
-            default:
-                value = 0;
-        }
-        dOut.write(ValueTag.XS_DOUBLE_TAG);
-        dOut.writeDouble(value);
-    }
-
-    public static void getIntegerPointable(TaggedValuePointable tvp, DataOutput dOut) throws
SystemException,
-            IOException {
-        TypedPointables tp = new TypedPointables();
-        long value;
-        switch (tvp.getTag()) {
-            case ValueTag.XS_INTEGER_TAG:
-            case ValueTag.XS_LONG_TAG:
-            case ValueTag.XS_NEGATIVE_INTEGER_TAG:
-            case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
-            case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
-            case ValueTag.XS_POSITIVE_INTEGER_TAG:
-            case ValueTag.XS_UNSIGNED_INT_TAG:
-            case ValueTag.XS_UNSIGNED_LONG_TAG:
-                tvp.getValue(tp.longp);
-                value = tp.longp.longValue();
-                break;
-
-            case ValueTag.XS_INT_TAG:
-            case ValueTag.XS_UNSIGNED_SHORT_TAG:
-                tvp.getValue(tp.intp);
-                value = tp.intp.longValue();
-                break;
-
-            case ValueTag.XS_SHORT_TAG:
-            case ValueTag.XS_UNSIGNED_BYTE_TAG:
-                tvp.getValue(tp.shortp);
-                value = tp.shortp.longValue();
-                break;
-
-            case ValueTag.XS_BYTE_TAG:
-                tvp.getValue(tp.bytep);
-                value = tp.bytep.longValue();
-                break;
-
-            default:
-                value = 0;
-        }
-        dOut.write(ValueTag.XS_INTEGER_TAG);
-        dOut.writeLong(value);
-    }
-
-    public static long getTimezone(ITimezone timezonep) {
-        return timezonep.getTimezoneHour() * DateTime.CHRONON_OF_HOUR + timezonep.getTimezoneMinute()
-                * DateTime.CHRONON_OF_MINUTE;
-    }
-
-    public static boolean isDerivedFromDouble(int tid) {
-        switch (tid) {
-            case ValueTag.XS_DECIMAL_TAG:
-            case ValueTag.XS_DOUBLE_TAG:
-            case ValueTag.XS_FLOAT_TAG:
-                return true;
-        }
-        return isDerivedFromInteger(tid);
-    }
-
-    public static boolean isDerivedFromInteger(int tid) {
-        switch (tid) {
-            case ValueTag.XS_INTEGER_TAG:
-            case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
-            case ValueTag.XS_NEGATIVE_INTEGER_TAG:
-            case ValueTag.XS_LONG_TAG:
-            case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
-            case ValueTag.XS_UNSIGNED_LONG_TAG:
-            case ValueTag.XS_POSITIVE_INTEGER_TAG:
-            case ValueTag.XS_INT_TAG:
-            case ValueTag.XS_UNSIGNED_INT_TAG:
-            case ValueTag.XS_SHORT_TAG:
-            case ValueTag.XS_UNSIGNED_SHORT_TAG:
-            case ValueTag.XS_BYTE_TAG:
-            case ValueTag.XS_UNSIGNED_BYTE_TAG:
-                return true;
-        }
-        return false;
-    }
-
-    public static boolean isDerivedFromString(int tid) {
-        switch (tid) {
-            case ValueTag.XS_STRING_TAG:
-            case ValueTag.XS_NORMALIZED_STRING_TAG:
-            case ValueTag.XS_TOKEN_TAG:
-            case ValueTag.XS_LANGUAGE_TAG:
-            case ValueTag.XS_NMTOKEN_TAG:
-            case ValueTag.XS_NAME_TAG:
-            case ValueTag.XS_NCNAME_TAG:
-            case ValueTag.XS_ID_TAG:
-            case ValueTag.XS_IDREF_TAG:
-            case ValueTag.XS_ENTITY_TAG:
-                return true;
-        }
-        return false;
-    }
-
-    public static boolean compareTaggedValues(AbstractValueComparisonOperation aOp, TaggedValuePointable
tvp1,
-            TaggedValuePointable tvp2, DynamicContext dCtx) throws SystemException {
-        final TypedPointables tp1 = new TypedPointables();
-        final TypedPointables tp2 = new TypedPointables();
-
-        boolean booleanResult = false;
-        int tid1 = getBaseTypeForComparisons(tvp1.getTag());
-        int tid2 = getBaseTypeForComparisons(tvp2.getTag());
-        try {
-            switch (tid1) {
-                case ValueTag.XS_DECIMAL_TAG:
-                    tvp1.getValue(tp1.decp);
-                    switch (tid2) {
-                        case ValueTag.XS_DECIMAL_TAG:
-                            tvp2.getValue(tp2.decp);
-                            booleanResult = aOp.operateDecimalDecimal(tp1.decp, tp2.decp);
-                            break;
-
-                        case ValueTag.XS_INTEGER_TAG:
-                            tvp2.getValue(tp2.longp);
-                            booleanResult = aOp.operateDecimalInteger(tp1.decp, tp2.longp);
-                            break;
-
-                        case ValueTag.XS_FLOAT_TAG:
-                            tvp2.getValue(tp2.floatp);
-                            booleanResult = aOp.operateDecimalFloat(tp1.decp, tp2.floatp);
-                            break;
-
-                        case ValueTag.XS_DOUBLE_TAG:
-                            tvp2.getValue(tp2.doublep);
-                            booleanResult = aOp.operateDecimalDouble(tp1.decp, tp2.doublep);
-                            break;
-                    }
-                    break;
-
-                case ValueTag.XS_INTEGER_TAG:
-                    tvp1.getValue(tp1.longp);
-                    switch (tid2) {
-                        case ValueTag.XS_DECIMAL_TAG:
-                            tvp2.getValue(tp2.decp);
-                            booleanResult = aOp.operateIntegerDecimal(tp1.longp, tp2.decp);
-                            break;
-
-                        case ValueTag.XS_INTEGER_TAG:
-                            tvp2.getValue(tp2.longp);
-                            booleanResult = aOp.operateIntegerInteger(tp1.longp, tp2.longp);
-                            break;
-
-                        case ValueTag.XS_FLOAT_TAG:
-                            tvp2.getValue(tp2.floatp);
-                            booleanResult = aOp.operateIntegerFloat(tp1.longp, tp2.floatp);
-                            break;
-
-                        case ValueTag.XS_DOUBLE_TAG:
-                            tvp2.getValue(tp2.doublep);
-                            booleanResult = aOp.operateIntegerDouble(tp1.longp, tp2.doublep);
-                            break;
-                    }
-                    break;
-
-                case ValueTag.XS_FLOAT_TAG:
-                    tvp1.getValue(tp1.floatp);
-                    switch (tid2) {
-                        case ValueTag.XS_DECIMAL_TAG:
-                            tvp2.getValue(tp2.decp);
-                            booleanResult = aOp.operateFloatDecimal(tp1.floatp, tp2.decp);
-                            break;
-
-                        case ValueTag.XS_INTEGER_TAG:
-                            tvp2.getValue(tp2.longp);
-                            booleanResult = aOp.operateFloatInteger(tp1.floatp, tp2.longp);
-                            break;
-
-                        case ValueTag.XS_FLOAT_TAG:
-                            tvp2.getValue(tp2.floatp);
-                            booleanResult = aOp.operateFloatFloat(tp1.floatp, tp2.floatp);
-                            break;
-
-                        case ValueTag.XS_DOUBLE_TAG:
-                            tvp2.getValue(tp2.doublep);
-                            booleanResult = aOp.operateFloatDouble(tp1.floatp, tp2.doublep);
-                            break;
-                    }
-                    break;
-
-                case ValueTag.XS_DOUBLE_TAG:
-                    tvp1.getValue(tp1.doublep);
-                    switch (tid2) {
-                        case ValueTag.XS_DECIMAL_TAG:
-                            tvp2.getValue(tp2.decp);
-                            booleanResult = aOp.operateDoubleDecimal(tp1.doublep, tp2.decp);
-                            break;
-
-                        case ValueTag.XS_INTEGER_TAG:
-                            tvp2.getValue(tp2.longp);
-                            booleanResult = aOp.operateDoubleInteger(tp1.doublep, tp2.longp);
-                            break;
-
-                        case ValueTag.XS_FLOAT_TAG:
-                            tvp2.getValue(tp2.floatp);
-                            booleanResult = aOp.operateDoubleFloat(tp1.doublep, tp2.floatp);
-                            break;
+                        case ValueTag.XS_FLOAT_TAG:
+                            tvp2.getValue(tp2.floatp);
+                            booleanResult = aOp.operateDoubleFloat(tp1.doublep, tp2.floatp);
+                            break;
 
                         case ValueTag.XS_DOUBLE_TAG:
                             tvp2.getValue(tp2.doublep);
@@ -720,4 +421,315 @@ public class FunctionHelper {
             throw new SystemException(ErrorCode.SYSE0001, e);
         }
     }
+
+    public static int getBaseTypeForArithmetics(int tid) throws SystemException {
+        if (tid >= BuiltinTypeConstants.BUILTIN_TYPE_COUNT) {
+            throw new SystemException(ErrorCode.XPTY0004);
+        }
+        while (true) {
+            switch (tid) {
+                case ValueTag.XS_STRING_TAG:
+                case ValueTag.XS_DECIMAL_TAG:
+                case ValueTag.XS_INTEGER_TAG:
+                case ValueTag.XS_FLOAT_TAG:
+                case ValueTag.XS_DOUBLE_TAG:
+                case ValueTag.XS_ANY_URI_TAG:
+                case ValueTag.XS_BOOLEAN_TAG:
+                case ValueTag.XS_DATE_TAG:
+                case ValueTag.XS_DATETIME_TAG:
+                case ValueTag.XS_TIME_TAG:
+                case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
+                case ValueTag.XS_BASE64_BINARY_TAG:
+                case ValueTag.XS_HEX_BINARY_TAG:
+                case ValueTag.XS_QNAME_TAG:
+                case ValueTag.XS_G_DAY_TAG:
+                case ValueTag.XS_G_MONTH_DAY_TAG:
+                case ValueTag.XS_G_MONTH_TAG:
+                case ValueTag.XS_G_YEAR_MONTH_TAG:
+                case ValueTag.XS_G_YEAR_TAG:
+                case ValueTag.XS_UNTYPED_ATOMIC_TAG:
+                    return tid;
+
+                case ValueTag.XS_LONG_TAG:
+                case ValueTag.XS_NEGATIVE_INTEGER_TAG:
+                case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
+                case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
+                case ValueTag.XS_POSITIVE_INTEGER_TAG:
+                case ValueTag.XS_UNSIGNED_INT_TAG:
+                case ValueTag.XS_UNSIGNED_LONG_TAG:
+                case ValueTag.XS_INT_TAG:
+                case ValueTag.XS_UNSIGNED_SHORT_TAG:
+                case ValueTag.XS_SHORT_TAG:
+                case ValueTag.XS_UNSIGNED_BYTE_TAG:
+                case ValueTag.XS_BYTE_TAG:
+                    return ValueTag.XS_INTEGER_TAG;
+
+                case ValueTag.XS_ANY_ATOMIC_TAG:
+                    throw new SystemException(ErrorCode.XPTY0004);
+
+                default:
+                    tid = BuiltinTypeRegistry.INSTANCE.getSchemaTypeById(tid).getBaseType().getTypeId();
+                    return tid;
+            }
+        }
+    }
+
+    public static int getBaseTypeForComparisons(int tid) throws SystemException {
+        while (true) {
+            switch (tid) {
+                case ValueTag.XS_ANY_URI_TAG:
+                case ValueTag.XS_BASE64_BINARY_TAG:
+                case ValueTag.XS_BOOLEAN_TAG:
+                case ValueTag.XS_DATE_TAG:
+                case ValueTag.XS_DATETIME_TAG:
+                case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                case ValueTag.XS_DECIMAL_TAG:
+                case ValueTag.XS_DOUBLE_TAG:
+                case ValueTag.XS_DURATION_TAG:
+                case ValueTag.XS_FLOAT_TAG:
+                case ValueTag.XS_HEX_BINARY_TAG:
+                case ValueTag.XS_INTEGER_TAG:
+                case ValueTag.XS_G_DAY_TAG:
+                case ValueTag.XS_G_MONTH_DAY_TAG:
+                case ValueTag.XS_G_MONTH_TAG:
+                case ValueTag.XS_G_YEAR_MONTH_TAG:
+                case ValueTag.XS_G_YEAR_TAG:
+                case ValueTag.XS_QNAME_TAG:
+                case ValueTag.XS_STRING_TAG:
+                case ValueTag.XS_TIME_TAG:
+                case ValueTag.XS_UNTYPED_ATOMIC_TAG:
+                case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
+                    return tid;
+
+                case ValueTag.XS_LONG_TAG:
+                case ValueTag.XS_NEGATIVE_INTEGER_TAG:
+                case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
+                case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
+                case ValueTag.XS_POSITIVE_INTEGER_TAG:
+                case ValueTag.XS_UNSIGNED_INT_TAG:
+                case ValueTag.XS_UNSIGNED_LONG_TAG:
+                case ValueTag.XS_INT_TAG:
+                case ValueTag.XS_UNSIGNED_SHORT_TAG:
+                case ValueTag.XS_SHORT_TAG:
+                case ValueTag.XS_UNSIGNED_BYTE_TAG:
+                case ValueTag.XS_BYTE_TAG:
+                    return ValueTag.XS_INTEGER_TAG;
+
+                case ValueTag.XS_ANY_ATOMIC_TAG:
+                    throw new SystemException(ErrorCode.XPTY0004);
+
+                default:
+                    tid = BuiltinTypeRegistry.INSTANCE.getSchemaTypeById(tid).getBaseType().getTypeId();
+            }
+        }
+    }
+
+    public static int getBaseTypeForGeneralComparisons(int tid) throws SystemException {
+        while (true) {
+            switch (tid) {
+                case ValueTag.XS_ANY_URI_TAG:
+                case ValueTag.XS_BASE64_BINARY_TAG:
+                case ValueTag.XS_BOOLEAN_TAG:
+                case ValueTag.XS_DATE_TAG:
+                case ValueTag.XS_DATETIME_TAG:
+                case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                case ValueTag.XS_DURATION_TAG:
+                case ValueTag.XS_HEX_BINARY_TAG:
+                case ValueTag.XS_G_DAY_TAG:
+                case ValueTag.XS_G_MONTH_DAY_TAG:
+                case ValueTag.XS_G_MONTH_TAG:
+                case ValueTag.XS_G_YEAR_MONTH_TAG:
+                case ValueTag.XS_G_YEAR_TAG:
+                case ValueTag.XS_QNAME_TAG:
+                case ValueTag.XS_STRING_TAG:
+                case ValueTag.XS_TIME_TAG:
+                case ValueTag.XS_UNTYPED_ATOMIC_TAG:
+                case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
+                    return tid;
+                case ValueTag.XS_DECIMAL_TAG:
+                case ValueTag.XS_DOUBLE_TAG:
+                case ValueTag.XS_FLOAT_TAG:
+                case ValueTag.XS_INTEGER_TAG:
+                case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
+                case ValueTag.XS_NEGATIVE_INTEGER_TAG:
+                case ValueTag.XS_LONG_TAG:
+                case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
+                case ValueTag.XS_UNSIGNED_LONG_TAG:
+                case ValueTag.XS_POSITIVE_INTEGER_TAG:
+                case ValueTag.XS_INT_TAG:
+                case ValueTag.XS_UNSIGNED_INT_TAG:
+                case ValueTag.XS_SHORT_TAG:
+                case ValueTag.XS_UNSIGNED_SHORT_TAG:
+                case ValueTag.XS_BYTE_TAG:
+                case ValueTag.XS_UNSIGNED_BYTE_TAG:
+                    return ValueTag.XS_DOUBLE_TAG;
+
+                case ValueTag.XS_ANY_ATOMIC_TAG:
+                    throw new SystemException(ErrorCode.XPTY0004);
+
+                default:
+                    tid = BuiltinTypeRegistry.INSTANCE.getSchemaTypeById(tid).getBaseType().getTypeId();
+            }
+        }
+    }
+
+    public static void getDoublePointable(TaggedValuePointable tvp, DataOutput dOut) throws
SystemException,
+            IOException {
+        TypedPointables tp = new TypedPointables();
+        double value;
+        switch (tvp.getTag()) {
+            case ValueTag.XS_DECIMAL_TAG:
+                tvp.getValue(tp.decp);
+                value = tp.decp.doubleValue();
+                break;
+
+            case ValueTag.XS_DOUBLE_TAG:
+                tvp.getValue(tp.doublep);
+                value = tp.doublep.doubleValue();
+                break;
+
+            case ValueTag.XS_FLOAT_TAG:
+                tvp.getValue(tp.floatp);
+                value = tp.floatp.doubleValue();
+                break;
+
+            case ValueTag.XS_INTEGER_TAG:
+            case ValueTag.XS_LONG_TAG:
+            case ValueTag.XS_NEGATIVE_INTEGER_TAG:
+            case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
+            case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
+            case ValueTag.XS_POSITIVE_INTEGER_TAG:
+            case ValueTag.XS_UNSIGNED_INT_TAG:
+            case ValueTag.XS_UNSIGNED_LONG_TAG:
+                tvp.getValue(tp.longp);
+                value = tp.longp.doubleValue();
+                break;
+
+            case ValueTag.XS_INT_TAG:
+            case ValueTag.XS_UNSIGNED_SHORT_TAG:
+                tvp.getValue(tp.intp);
+                value = tp.intp.doubleValue();
+                break;
+
+            case ValueTag.XS_SHORT_TAG:
+            case ValueTag.XS_UNSIGNED_BYTE_TAG:
+                tvp.getValue(tp.shortp);
+                value = tp.shortp.doubleValue();
+                break;
+
+            case ValueTag.XS_BYTE_TAG:
+                tvp.getValue(tp.bytep);
+                value = tp.bytep.doubleValue();
+                break;
+
+            default:
+                value = 0;
+        }
+        dOut.write(ValueTag.XS_DOUBLE_TAG);
+        dOut.writeDouble(value);
+    }
+
+    public static void getIntegerPointable(TaggedValuePointable tvp, DataOutput dOut) throws
SystemException,
+            IOException {
+        TypedPointables tp = new TypedPointables();
+        long value;
+        switch (tvp.getTag()) {
+            case ValueTag.XS_INTEGER_TAG:
+            case ValueTag.XS_LONG_TAG:
+            case ValueTag.XS_NEGATIVE_INTEGER_TAG:
+            case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
+            case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
+            case ValueTag.XS_POSITIVE_INTEGER_TAG:
+            case ValueTag.XS_UNSIGNED_INT_TAG:
+            case ValueTag.XS_UNSIGNED_LONG_TAG:
+                tvp.getValue(tp.longp);
+                value = tp.longp.longValue();
+                break;
+
+            case ValueTag.XS_INT_TAG:
+            case ValueTag.XS_UNSIGNED_SHORT_TAG:
+                tvp.getValue(tp.intp);
+                value = tp.intp.longValue();
+                break;
+
+            case ValueTag.XS_SHORT_TAG:
+            case ValueTag.XS_UNSIGNED_BYTE_TAG:
+                tvp.getValue(tp.shortp);
+                value = tp.shortp.longValue();
+                break;
+
+            case ValueTag.XS_BYTE_TAG:
+                tvp.getValue(tp.bytep);
+                value = tp.bytep.longValue();
+                break;
+
+            default:
+                value = 0;
+        }
+        dOut.write(ValueTag.XS_INTEGER_TAG);
+        dOut.writeLong(value);
+    }
+
+    public static long getTimezone(ITimezone timezonep) {
+        return timezonep.getTimezoneHour() * DateTime.CHRONON_OF_HOUR + timezonep.getTimezoneMinute()
+                * DateTime.CHRONON_OF_MINUTE;
+    }
+
+    public static boolean isDerivedFromDouble(int tid) {
+        switch (tid) {
+            case ValueTag.XS_DECIMAL_TAG:
+            case ValueTag.XS_DOUBLE_TAG:
+            case ValueTag.XS_FLOAT_TAG:
+                return true;
+        }
+        return isDerivedFromInteger(tid);
+    }
+
+    public static boolean isDerivedFromInteger(int tid) {
+        switch (tid) {
+            case ValueTag.XS_INTEGER_TAG:
+            case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
+            case ValueTag.XS_NEGATIVE_INTEGER_TAG:
+            case ValueTag.XS_LONG_TAG:
+            case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
+            case ValueTag.XS_UNSIGNED_LONG_TAG:
+            case ValueTag.XS_POSITIVE_INTEGER_TAG:
+            case ValueTag.XS_INT_TAG:
+            case ValueTag.XS_UNSIGNED_INT_TAG:
+            case ValueTag.XS_SHORT_TAG:
+            case ValueTag.XS_UNSIGNED_SHORT_TAG:
+            case ValueTag.XS_BYTE_TAG:
+            case ValueTag.XS_UNSIGNED_BYTE_TAG:
+                return true;
+        }
+        return false;
+    }
+
+    public static boolean isDerivedFromString(int tid) {
+        switch (tid) {
+            case ValueTag.XS_STRING_TAG:
+            case ValueTag.XS_NORMALIZED_STRING_TAG:
+            case ValueTag.XS_TOKEN_TAG:
+            case ValueTag.XS_LANGUAGE_TAG:
+            case ValueTag.XS_NMTOKEN_TAG:
+            case ValueTag.XS_NAME_TAG:
+            case ValueTag.XS_NCNAME_TAG:
+            case ValueTag.XS_ID_TAG:
+            case ValueTag.XS_IDREF_TAG:
+            case ValueTag.XS_ENTITY_TAG:
+                return true;
+        }
+        return false;
+    }
+
+    public static void printUTF8String(UTF8StringPointable stringp) {
+        System.err.println(" printUTF8String START length = " + stringp.getUTFLength());
+        ICharacterIterator charIterator = new UTF8StringCharacterIterator(stringp);
+        charIterator.reset();
+        for (int c = charIterator.next(); c != ICharacterIterator.EOS_CHAR; c = charIterator.next())
{
+            System.err.println("   parse value '" + c + "' as '" + Character.valueOf((char)
c) + "'");
+        }
+        System.err.println(" printUTF8String END");
+    }
 }



Mime
View raw message