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/09/05 23:18:01 UTC
svn commit: r1381378 -
/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnSubsequenceScalarEvaluatorFactory.java
Author: prestonc
Date: Wed Sep 5 21:18:01 2012
New Revision: 1381378
URL: http://svn.apache.org/viewvc?rev=1381378&view=rev
Log:
Added a function to simply the function and reduce code duplication.
Modified:
incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnSubsequenceScalarEvaluatorFactory.java
Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnSubsequenceScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnSubsequenceScalarEvaluatorFactory.java?rev=1381378&r1=1381377&r2=1381378&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnSubsequenceScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnSubsequenceScalarEvaluatorFactory.java Wed Sep 5 21:18:01 2012
@@ -48,24 +48,7 @@ public class FnSubsequenceScalarEvaluato
try {
long startingLoc;
TaggedValuePointable tvp2 = args[1];
- // XQuery Specification calls for double value. Integer and Decimal are allowed to cut down
- // on casting.
- if (tvp2.getTag() == ValueTag.XS_DOUBLE_TAG) {
- tvp2.getValue(doublep);
- abvsRound.reset();
- round.operateDouble(doublep, abvsRound.getDataOutput());
- doublep.set(abvsRound.getByteArray(), abvsRound.getStartOffset() + 1,
- DoublePointable.TYPE_TRAITS.getFixedLength());
- startingLoc = doublep.longValue();
- } else if (tvp2.getTag() == ValueTag.XS_INTEGER_TAG) {
- tvp2.getValue(longp);
- startingLoc = longp.longValue();
- } else if (tvp2.getTag() == ValueTag.XS_DECIMAL_TAG) {
- tvp2.getValue(decp);
- startingLoc = decp.longValue();
- } else {
- throw new SystemException(ErrorCode.FORG0006);
- }
+ startingLoc = getLongFromArgument(tvp2);
if (startingLoc < 1) {
startingLoc = 1;
}
@@ -74,24 +57,7 @@ public class FnSubsequenceScalarEvaluato
long endingLoc = Long.MAX_VALUE;
if (args.length > 2) {
TaggedValuePointable tvp3 = args[2];
- // XQuery Specification calls for double value. Integer and Decimal are allowed to cut down
- // on casting.
- if (tvp3.getTag() == ValueTag.XS_DOUBLE_TAG) {
- tvp3.getValue(doublep);
- abvsRound.reset();
- round.operateDouble(doublep, abvsRound.getDataOutput());
- doublep.set(abvsRound.getByteArray(), abvsRound.getStartOffset() + 1,
- DoublePointable.TYPE_TRAITS.getFixedLength());
- endingLoc = startingLoc + doublep.longValue();
- } else if (tvp3.getTag() == ValueTag.XS_INTEGER_TAG) {
- tvp3.getValue(longp);
- endingLoc = startingLoc + longp.longValue();
- } else if (tvp3.getTag() == ValueTag.XS_DECIMAL_TAG) {
- tvp3.getValue(decp);
- endingLoc = startingLoc + decp.longValue();
- } else {
- throw new SystemException(ErrorCode.FORG0006);
- }
+ endingLoc = getLongFromArgument(tvp3) + startingLoc;
}
abvs.reset();
@@ -125,6 +91,33 @@ public class FnSubsequenceScalarEvaluato
throw new SystemException(ErrorCode.SYSE0001);
}
}
+
+ /**
+ * XQuery Specification calls for double value. Integer and Decimal are allowed to cut down on casting.
+ *
+ * @param tvp
+ * @return
+ * @throws SystemException
+ * @throws IOException
+ */
+ public long getLongFromArgument(TaggedValuePointable tvp) throws SystemException, IOException {
+ if (tvp.getTag() == ValueTag.XS_DOUBLE_TAG) {
+ tvp.getValue(doublep);
+ abvsRound.reset();
+ round.operateDouble(doublep, abvsRound.getDataOutput());
+ doublep.set(abvsRound.getByteArray(), abvsRound.getStartOffset() + 1,
+ DoublePointable.TYPE_TRAITS.getFixedLength());
+ return doublep.longValue();
+ } else if (tvp.getTag() == ValueTag.XS_INTEGER_TAG) {
+ tvp.getValue(longp);
+ return longp.longValue();
+ } else if (tvp.getTag() == ValueTag.XS_DECIMAL_TAG) {
+ tvp.getValue(decp);
+ return decp.longValue();
+ } else {
+ throw new SystemException(ErrorCode.FORG0006);
+ }
+ }
};
}
}
\ No newline at end of file