You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2012/05/07 18:54:49 UTC
svn commit: r1335123 - in
/jena/Scratch/AFS/Dev/trunk/src/main/java/projects/nodevalue: NV2.java
NodeValueOps.java TestNodeValueOps.java
Author: andy
Date: Mon May 7 16:54:49 2012
New Revision: 1335123
URL: http://svn.apache.org/viewvc?rev=1335123&view=rev
Log:
General NodeValue operations + - * /
Added:
jena/Scratch/AFS/Dev/trunk/src/main/java/projects/nodevalue/NodeValueOps.java
Modified:
jena/Scratch/AFS/Dev/trunk/src/main/java/projects/nodevalue/NV2.java
jena/Scratch/AFS/Dev/trunk/src/main/java/projects/nodevalue/TestNodeValueOps.java
Modified: jena/Scratch/AFS/Dev/trunk/src/main/java/projects/nodevalue/NV2.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Dev/trunk/src/main/java/projects/nodevalue/NV2.java?rev=1335123&r1=1335122&r2=1335123&view=diff
==============================================================================
--- jena/Scratch/AFS/Dev/trunk/src/main/java/projects/nodevalue/NV2.java (original)
+++ jena/Scratch/AFS/Dev/trunk/src/main/java/projects/nodevalue/NV2.java Mon May 7 16:54:49 2012
@@ -18,12 +18,6 @@
package projects.nodevalue;
-import static com.hp.hpl.jena.datatypes.xsd.XSDDatatype.XSD ;
-import static com.hp.hpl.jena.sparql.expr.ValueSpaceClassification.* ;
-import static com.hp.hpl.jena.sparql.expr.ValueSpaceClassification.VSPACE_NUM ;
-import static com.hp.hpl.jena.sparql.expr.ValueSpaceClassification.VSPACE_STRING ;
-import static javax.xml.datatype.DatatypeConstants.FIELD_UNDEFINED ;
-
import java.util.GregorianCalendar ;
import javax.xml.datatype.DatatypeConfigurationException ;
@@ -31,14 +25,9 @@ import javax.xml.datatype.DatatypeFactor
import javax.xml.datatype.Duration ;
import javax.xml.datatype.XMLGregorianCalendar ;
-import com.hp.hpl.jena.datatypes.xsd.XSDDatatype ;
import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.query.ARQ ;
import com.hp.hpl.jena.sparql.ARQInternalErrorException ;
-import com.hp.hpl.jena.sparql.expr.ExprEvalTypeException ;
import com.hp.hpl.jena.sparql.expr.NodeValue ;
-import com.hp.hpl.jena.sparql.expr.ValueSpaceClassification ;
-import com.hp.hpl.jena.sparql.expr.nodevalue.XSDFuncOp ;
import com.hp.hpl.jena.sparql.util.NodeFactory ;
public class NV2
@@ -95,6 +84,7 @@ public class NV2
(xsd:duration, xsd:double) -> xsd:duration
10.6.8 op:multiply-dayTimeDuration
10.6.9 op:divide-dayTimeDuration
+
(xsd:duration, xsd:duration) -> xsd:decimal
10.6.10 op:divide-dayTimeDuration-by-dayTimeDuration
*/
@@ -140,7 +130,7 @@ http://www.w3.org/TR/xmlschema11-2/#dt-d
NodeValue nv1 = NodeValue.parse(s1) ;
NodeValue nv2 = NodeValue.parse(s2) ;
System.out.printf("+(%s, %s)\n", nv1, nv2) ;
- NodeValue nv3 = addNV(nv1, nv2) ;
+ NodeValue nv3 = NodeValueOps.additionNV(nv1, nv2) ;
System.out.printf(" %s\n", nv3) ;
} catch (Exception ex)
{
@@ -155,7 +145,7 @@ http://www.w3.org/TR/xmlschema11-2/#dt-d
NodeValue nv1 = NodeValue.parse(s1) ;
NodeValue nv2 = NodeValue.parse(s2) ;
System.out.printf("- (%s, %s)\n", nv1, nv2) ;
- NodeValue nv3 = subNV(nv1, nv2) ;
+ NodeValue nv3 = NodeValueOps.subtractionNV(nv1, nv2) ;
System.out.printf(" %s\n", nv3) ;
} catch (Exception ex)
{
@@ -164,143 +154,6 @@ http://www.w3.org/TR/xmlschema11-2/#dt-d
}
}
- private static final String dtXSDdateTimeStamp = XSD+"#dateTimeStamp" ;
- private static final String dtXSDdayTimeDuration = XSD+"#dayTimeDuration" ;
- private static final String dtXSDyearMonthDuration = XSD+"#yearMonthDuration" ;
-
- public static NodeValue addNV(NodeValue nv1, NodeValue nv2)
- {
- ValueSpaceClassification vs1 = nv1.getValueSpace() ;
- ValueSpaceClassification vs2 = nv2.getValueSpace() ;
-
- if ( vs1.equals(VSPACE_NUM) && vs2.equals(VSPACE_NUM) )
- return XSDFuncOp.numAdd(nv1, nv2) ;
- if ( ARQ.isStrictMode() )
- throw new ExprEvalTypeException("Operator '+' requires two numbers: got: "+nv1+" and "+nv2) ;
-
- if ( vs1.equals(VSPACE_STRING) && vs2.equals(VSPACE_STRING) )
- return NodeValue.makeString(nv1.asString()+nv2.asString()) ;
- if ( vs1.equals(VSPACE_DURATION) && vs2.equals(VSPACE_DURATION) )
- {
- // A lot of testing to keep it as derived types.
- boolean isDTDur = dtXSDdayTimeDuration.equals(nv1.getDatatypeURI()) &&
- dtXSDdayTimeDuration.equals(nv2.getDatatypeURI()) ;
- boolean isYMDur = dtXSDyearMonthDuration.equals(nv1.getDatatypeURI()) &&
- dtXSDyearMonthDuration.equals(nv2.getDatatypeURI()) ;
- Duration d3 = nv1.getDuration().add(nv2.getDuration()) ;
- String lex = d3.toString() ;
- Node n ;
- if ( isDTDur )
- n = NodeFactory.createLiteralNode(lex, null, dtXSDdayTimeDuration) ;
- else if ( isYMDur )
- n = NodeFactory.createLiteralNode(lex, null, dtXSDyearMonthDuration) ;
- else
- n = Node.createLiteral(lex, XSDDatatype.XSDduration) ;
- return NodeValue.makeNodeDuration(d3, n) ;
- }
-
- // Loose style. Add any duration to any date or time value.
- if ( vs1.equals(VSPACE_DATETIME) && vs2.equals(VSPACE_DURATION) )
- {
- XMLGregorianCalendar cal = nv1.getDateTime() ;
- XMLGregorianCalendar result = xsd_add(cal, nv2.getDuration()) ;
- NodeValue r = NodeValue.makeDateTime(result) ;
- return r ;
- }
- // Loose style. Add any duration to any date or time value.
- if ( vs1.equals(VSPACE_DATE) && vs2.equals(VSPACE_DURATION) )
- {
- XMLGregorianCalendar cal = nv1.getDateTime() ;
- XMLGregorianCalendar result = xsd_add(cal, nv2.getDuration()) ;
- NodeValue r = NodeValue.makeDate(result) ;
- return r ;
- }
- // Loose style. Add any duration to any date or time value.
- if ( vs1.equals(VSPACE_TIME) && vs2.equals(VSPACE_DURATION) )
- {
- XMLGregorianCalendar cal = nv1.getDateTime() ;
- XMLGregorianCalendar result = xsd_add(cal, nv2.getDuration()) ;
- NodeValue r = NodeValue.makeNode(result.toXMLFormat(), XSDDatatype.XSDtime) ;
- return r ;
- }
-
- if ( isDT(vs2) && vs1.equals(VSPACE_DURATION) )
- // Carefully ...
- return addNV(nv2, nv1) ;
- throw new ExprEvalTypeException("Operator '+' : Undefined addition: "+nv1+" and "+nv2) ;
- }
-
- // NodeFunctions
- public static NodeValue subNV(NodeValue nv1, NodeValue nv2)
- {
- ValueSpaceClassification vs1 = nv1.getValueSpace() ;
- ValueSpaceClassification vs2 = nv2.getValueSpace() ;
-
- if ( vs1.equals(VSPACE_NUM) && vs2.equals(VSPACE_NUM) )
- return XSDFuncOp.numSubtract(nv1, nv2) ;
- if ( ARQ.isStrictMode() )
- throw new ExprEvalTypeException("Operator '-' requires two numbers: got: "+nv1+" and "+nv2) ;
-
- if ( vs1.equals(VSPACE_DURATION) && vs2.equals(VSPACE_DURATION) )
- {
- // A lot of testing to keep it as derived types.
- boolean isDTDur = dtXSDdayTimeDuration.equals(nv1.getDatatypeURI()) &&
- dtXSDdayTimeDuration.equals(nv2.getDatatypeURI()) ;
- boolean isYMDur = dtXSDyearMonthDuration.equals(nv1.getDatatypeURI()) &&
- dtXSDyearMonthDuration.equals(nv2.getDatatypeURI()) ;
- Duration d3 = nv1.getDuration().subtract(nv2.getDuration()) ;
- String lex = d3.toString() ;
- Node n ;
- if ( isDTDur )
- n = NodeFactory.createLiteralNode(lex, null, dtXSDdayTimeDuration) ;
- else if ( isYMDur )
- n = NodeFactory.createLiteralNode(lex, null, dtXSDyearMonthDuration) ;
- else
- n = Node.createLiteral(lex, XSDDatatype.XSDduration) ;
- return NodeValue.makeNodeDuration(d3, n) ;
- }
-
- if ( isDT(vs1) && isDT(vs2) )
- {
- XMLGregorianCalendar cal1 = nv1.getDateTime() ;
- XMLGregorianCalendar cal2 = nv2.getDateTime() ;
- boolean isDef1 = ( cal1.getTimezone() == FIELD_UNDEFINED ) ;
- boolean isDef2 = ( cal2.getTimezone() == FIELD_UNDEFINED ) ;
- if ( ( isDef1 && !isDef2 ) || ( !isDef1 && isDef2 ) )
- throw new ExprEvalTypeException("Operator '-': can't substract timezone/non-timezone values") ;
- // Inspect duration and force to better type? xsd:dayTimeDuration
- return NodeValue.makeDuration(xsd_substract(cal1, cal2));
- }
-
- // Loose style. Subtract any duration to any date or time value.
- if ( vs1.equals(VSPACE_DATETIME) && vs2.equals(VSPACE_DURATION) )
- {
- XMLGregorianCalendar cal = nv1.getDateTime() ;
- // add-negation
- XMLGregorianCalendar result = xsd_subtract(cal, nv2.getDuration()) ;
- NodeValue r = NodeValue.makeDateTime(result) ;
- return r ;
- }
- if ( vs1.equals(VSPACE_DATE) && vs2.equals(VSPACE_DURATION) )
- {
- XMLGregorianCalendar cal = nv1.getDateTime() ;
- // add-negation
- XMLGregorianCalendar result = xsd_subtract(cal, nv2.getDuration()) ;
- NodeValue r = NodeValue.makeDate(result) ;
- return r ;
- }
- if ( vs1.equals(VSPACE_TIME) && vs2.equals(VSPACE_DURATION) )
- {
- XMLGregorianCalendar cal = nv1.getDateTime() ;
- // add-negation
- XMLGregorianCalendar result = xsd_subtract(cal, nv2.getDuration()) ;
- NodeValue r = NodeValue.makeNode(result.toXMLFormat(), XSDDatatype.XSDtime) ;
- return r ;
- }
-
- throw new ExprEvalTypeException("Operator '-' : Undefined subtraction: "+nv1+" and "+nv2) ;
- }
-
// XSDFuncOps
public static XMLGregorianCalendar xsd_add(XMLGregorianCalendar cal, Duration duration)
{
@@ -328,24 +181,6 @@ http://www.w3.org/TR/xmlschema11-2/#dt-d
return datatypefactory.newDuration(x1-x2) ;
}
- // XSDFuncOps
- private static boolean isDT(ValueSpaceClassification vs)
- {
- switch (vs)
- {
- case VSPACE_DATETIME:
- case VSPACE_DATE:
- case VSPACE_TIME:
- case VSPACE_G_YEAR:
- case VSPACE_G_YEARMONTH:
- case VSPACE_G_MONTHDAY:
- case VSPACE_G_MONTH:
- case VSPACE_G_DAY:
- return true ;
- default:
- return false ;
- }
- }
}
Added: jena/Scratch/AFS/Dev/trunk/src/main/java/projects/nodevalue/NodeValueOps.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Dev/trunk/src/main/java/projects/nodevalue/NodeValueOps.java?rev=1335123&view=auto
==============================================================================
--- jena/Scratch/AFS/Dev/trunk/src/main/java/projects/nodevalue/NodeValueOps.java (added)
+++ jena/Scratch/AFS/Dev/trunk/src/main/java/projects/nodevalue/NodeValueOps.java Mon May 7 16:54:49 2012
@@ -0,0 +1,241 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package projects.nodevalue;
+
+import static com.hp.hpl.jena.datatypes.xsd.XSDDatatype.XSD ;
+import static com.hp.hpl.jena.sparql.expr.ValueSpaceClassification.VSPACE_DATE ;
+import static com.hp.hpl.jena.sparql.expr.ValueSpaceClassification.VSPACE_DATETIME ;
+import static com.hp.hpl.jena.sparql.expr.ValueSpaceClassification.VSPACE_DURATION ;
+import static com.hp.hpl.jena.sparql.expr.ValueSpaceClassification.VSPACE_NUM ;
+import static com.hp.hpl.jena.sparql.expr.ValueSpaceClassification.VSPACE_STRING ;
+import static com.hp.hpl.jena.sparql.expr.ValueSpaceClassification.VSPACE_TIME ;
+import static javax.xml.datatype.DatatypeConstants.FIELD_UNDEFINED ;
+
+import java.math.BigDecimal ;
+
+import javax.xml.datatype.Duration ;
+import javax.xml.datatype.XMLGregorianCalendar ;
+
+import com.hp.hpl.jena.datatypes.xsd.XSDDatatype ;
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.query.ARQ ;
+import com.hp.hpl.jena.sparql.expr.ExprEvalTypeException ;
+import com.hp.hpl.jena.sparql.expr.NodeValue ;
+import com.hp.hpl.jena.sparql.expr.ValueSpaceClassification ;
+import com.hp.hpl.jena.sparql.expr.nodevalue.XSDFuncOp ;
+import com.hp.hpl.jena.sparql.util.NodeFactory ;
+
+public class NodeValueOps
+{
+ private static final String dtXSDdateTimeStamp = XSD+"#dateTimeStamp" ;
+ private static final String dtXSDdayTimeDuration = XSD+"#dayTimeDuration" ;
+ private static final String dtXSDyearMonthDuration = XSD+"#yearMonthDuration" ;
+
+ public static NodeValue additionNV(NodeValue nv1, NodeValue nv2)
+ {
+ ValueSpaceClassification vs1 = nv1.getValueSpace() ;
+ ValueSpaceClassification vs2 = nv2.getValueSpace() ;
+
+ if ( vs1.equals(VSPACE_NUM) && vs2.equals(VSPACE_NUM) )
+ return XSDFuncOp.numAdd(nv1, nv2) ;
+ if ( ARQ.isStrictMode() )
+ throw new ExprEvalTypeException("Operator '+' requires two numbers: got: "+nv1+" and "+nv2) ;
+
+ if ( vs1.equals(VSPACE_STRING) && vs2.equals(VSPACE_STRING) )
+ return NodeValue.makeString(nv1.asString()+nv2.asString()) ;
+ if ( vs1.equals(VSPACE_DURATION) && vs2.equals(VSPACE_DURATION) )
+ {
+ // A lot of testing to keep it as derived types.
+ boolean isDTDur = dtXSDdayTimeDuration.equals(nv1.getDatatypeURI()) &&
+ dtXSDdayTimeDuration.equals(nv2.getDatatypeURI()) ;
+ boolean isYMDur = dtXSDyearMonthDuration.equals(nv1.getDatatypeURI()) &&
+ dtXSDyearMonthDuration.equals(nv2.getDatatypeURI()) ;
+ Duration d3 = nv1.getDuration().add(nv2.getDuration()) ;
+ String lex = d3.toString() ;
+ Node n ;
+ if ( isDTDur )
+ n = NodeFactory.createLiteralNode(lex, null, dtXSDdayTimeDuration) ;
+ else if ( isYMDur )
+ n = NodeFactory.createLiteralNode(lex, null, dtXSDyearMonthDuration) ;
+ else
+ n = Node.createLiteral(lex, XSDDatatype.XSDduration) ;
+ return NodeValue.makeNodeDuration(d3, n) ;
+ }
+
+ // Loose style. Add any duration to any date or time value.
+ if ( vs1.equals(VSPACE_DATETIME) && vs2.equals(VSPACE_DURATION) )
+ {
+ XMLGregorianCalendar cal = nv1.getDateTime() ;
+ XMLGregorianCalendar result = NV2.xsd_add(cal, nv2.getDuration()) ;
+ NodeValue r = NodeValue.makeDateTime(result) ;
+ return r ;
+ }
+ // Loose style. Add any duration to any date or time value.
+ if ( vs1.equals(VSPACE_DATE) && vs2.equals(VSPACE_DURATION) )
+ {
+ XMLGregorianCalendar cal = nv1.getDateTime() ;
+ XMLGregorianCalendar result = NV2.xsd_add(cal, nv2.getDuration()) ;
+ NodeValue r = NodeValue.makeDate(result) ;
+ return r ;
+ }
+ // Loose style. Add any duration to any date or time value.
+ if ( vs1.equals(VSPACE_TIME) && vs2.equals(VSPACE_DURATION) )
+ {
+ // ONLY dayTime.
+ XMLGregorianCalendar cal = nv1.getDateTime() ;
+ XMLGregorianCalendar result = NV2.xsd_add(cal, nv2.getDuration()) ;
+ NodeValue r = NodeValue.makeNode(result.toXMLFormat(), XSDDatatype.XSDtime) ;
+ return r ;
+ }
+
+ if ( isDT(vs2) && vs1.equals(VSPACE_DURATION) )
+ // Carefully ...
+ return additionNV(nv2, nv1) ;
+ throw new ExprEvalTypeException("Operator '+' : Undefined addition: "+nv1+" and "+nv2) ;
+ }
+
+ // NodeFunctions
+ public static NodeValue subtractionNV(NodeValue nv1, NodeValue nv2)
+ {
+ ValueSpaceClassification vs1 = nv1.getValueSpace() ;
+ ValueSpaceClassification vs2 = nv2.getValueSpace() ;
+
+ if ( vs1.equals(VSPACE_NUM) && vs2.equals(VSPACE_NUM) )
+ return XSDFuncOp.numSubtract(nv1, nv2) ;
+ if ( ARQ.isStrictMode() )
+ throw new ExprEvalTypeException("Operator '-' requires two numbers: got: "+nv1+" and "+nv2) ;
+
+ if ( vs1.equals(VSPACE_DURATION) && vs2.equals(VSPACE_DURATION) )
+ {
+ // A lot of testing to keep it as derived types.
+ boolean isDTDur = dtXSDdayTimeDuration.equals(nv1.getDatatypeURI()) &&
+ dtXSDdayTimeDuration.equals(nv2.getDatatypeURI()) ;
+ boolean isYMDur = dtXSDyearMonthDuration.equals(nv1.getDatatypeURI()) &&
+ dtXSDyearMonthDuration.equals(nv2.getDatatypeURI()) ;
+ Duration d3 = nv1.getDuration().subtract(nv2.getDuration()) ;
+ String lex = d3.toString() ;
+ Node n ;
+ if ( isDTDur )
+ n = NodeFactory.createLiteralNode(lex, null, dtXSDdayTimeDuration) ;
+ else if ( isYMDur )
+ n = NodeFactory.createLiteralNode(lex, null, dtXSDyearMonthDuration) ;
+ else
+ n = Node.createLiteral(lex, XSDDatatype.XSDduration) ;
+ return NodeValue.makeNodeDuration(d3, n) ;
+ }
+
+ if ( isDT(vs1) && isDT(vs2) )
+ {
+ XMLGregorianCalendar cal1 = nv1.getDateTime() ;
+ XMLGregorianCalendar cal2 = nv2.getDateTime() ;
+ boolean isDef1 = ( cal1.getTimezone() == FIELD_UNDEFINED ) ;
+ boolean isDef2 = ( cal2.getTimezone() == FIELD_UNDEFINED ) ;
+ if ( ( isDef1 && !isDef2 ) || ( !isDef1 && isDef2 ) )
+ throw new ExprEvalTypeException("Operator '-': can't substract timezone/non-timezone values") ;
+ // Inspect duration and force to better type? xsd:dayTimeDuration
+ return NodeValue.makeDuration(NV2.xsd_substract(cal1, cal2));
+ }
+
+ // Loose style. Subtract any duration to any date or time value.
+ if ( vs1.equals(VSPACE_DATETIME) && vs2.equals(VSPACE_DURATION) )
+ {
+ XMLGregorianCalendar cal = nv1.getDateTime() ;
+ // add-negation
+ XMLGregorianCalendar result = NV2.xsd_subtract(cal, nv2.getDuration()) ;
+ NodeValue r = NodeValue.makeDateTime(result) ;
+ return r ;
+ }
+ if ( vs1.equals(VSPACE_DATE) && vs2.equals(VSPACE_DURATION) )
+ {
+ XMLGregorianCalendar cal = nv1.getDateTime() ;
+ // add-negation
+ XMLGregorianCalendar result = NV2.xsd_subtract(cal, nv2.getDuration()) ;
+ NodeValue r = NodeValue.makeDate(result) ;
+ return r ;
+ }
+ if ( vs1.equals(VSPACE_TIME) && vs2.equals(VSPACE_DURATION) )
+ {
+ XMLGregorianCalendar cal = nv1.getDateTime() ;
+ // add-negation
+ XMLGregorianCalendar result = NV2.xsd_subtract(cal, nv2.getDuration()) ;
+ NodeValue r = NodeValue.makeNode(result.toXMLFormat(), XSDDatatype.XSDtime) ;
+ return r ;
+ }
+
+ throw new ExprEvalTypeException("Operator '-' : Undefined subtraction: "+nv1+" and "+nv2) ;
+ }
+
+ public static NodeValue multiplicationNV(NodeValue nv1, NodeValue nv2)
+ {
+ ValueSpaceClassification vs1 = nv1.getValueSpace() ;
+ ValueSpaceClassification vs2 = nv2.getValueSpace() ;
+
+ if ( vs1.equals(VSPACE_NUM) && vs2.equals(VSPACE_NUM) )
+ return XSDFuncOp.numMultiply(nv1, nv2) ;
+ if ( ARQ.isStrictMode() )
+ throw new ExprEvalTypeException("Operator '*' requires two numbers: got: "+nv1+" and "+nv2) ;
+ if ( vs1.equals(VSPACE_DURATION) && vs2.equals(VSPACE_NUM) )
+ {
+ // ONLY defined for dayTime.
+ Duration dur = nv1.getDuration() ;
+ boolean valid = XSDFuncOp.isDayTime(dur) ;
+ if ( ! valid )
+ throw new ExprEvalTypeException("Operator '*': only dayTime duration. Got: "+nv1) ;
+ BigDecimal dec = nv2.getDecimal() ;
+ Duration r = dur.multiply(dec) ;
+ Node n = NodeFactory.createLiteralNode(r.toString(), null, dtXSDdayTimeDuration) ;
+ return NodeValue.makeNodeDuration(r, n) ;
+ }
+ throw new ExprEvalTypeException("Operator '*' : Undefined multiply: "+nv1+" and "+nv2) ;
+ }
+
+ public static NodeValue divisionNV(NodeValue nv1, NodeValue nv2)
+ {
+ ValueSpaceClassification vs1 = nv1.getValueSpace() ;
+ ValueSpaceClassification vs2 = nv2.getValueSpace() ;
+
+ if ( vs1.equals(VSPACE_NUM) && vs2.equals(VSPACE_NUM) )
+ return XSDFuncOp.numDivide(nv1, nv2) ;
+// if ( ARQ.isStrictMode() )
+// throw new ExprEvalTypeException("Operator '*' requires two numbers: got: "+nv1+" and "+nv2) ;
+ throw new ExprEvalTypeException("Operator '/' : Undefined division: "+nv1+" and "+nv2) ;
+ }
+
+
+ // XSDFuncOps
+ private static boolean isDT(ValueSpaceClassification vs)
+ {
+ switch (vs)
+ {
+ case VSPACE_DATETIME:
+ case VSPACE_DATE:
+ case VSPACE_TIME:
+ case VSPACE_G_YEAR:
+ case VSPACE_G_YEARMONTH:
+ case VSPACE_G_MONTHDAY:
+ case VSPACE_G_MONTH:
+ case VSPACE_G_DAY:
+ return true ;
+ default:
+ return false ;
+ }
+ }
+
+}
+
Modified: jena/Scratch/AFS/Dev/trunk/src/main/java/projects/nodevalue/TestNodeValueOps.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Dev/trunk/src/main/java/projects/nodevalue/TestNodeValueOps.java?rev=1335123&r1=1335122&r2=1335123&view=diff
==============================================================================
--- jena/Scratch/AFS/Dev/trunk/src/main/java/projects/nodevalue/TestNodeValueOps.java (original)
+++ jena/Scratch/AFS/Dev/trunk/src/main/java/projects/nodevalue/TestNodeValueOps.java Mon May 7 16:54:49 2012
@@ -26,6 +26,7 @@ import org.openjena.atlas.junit.BaseTest
public class TestNodeValueOps extends BaseTest
{
+ // ** Addition
// Numerics
@Test public void nv_add_1() { testAdd("12", "13", "'25'^^xsd:integer" ) ; }
@Test public void nv_add_2() { testAdd("'12'^^xsd:decimal", "13", "'25'^^xsd:decimal" ) ; }
@@ -64,7 +65,7 @@ public class TestNodeValueOps extends Ba
@Test(expected=ExprEvalException.class)
public void nv_add_52() { testAdd("'2012-04-05'^^xsd:date", "'2012-04-05'^^xsd:date") ; }
-
+ // ** Subtraction
// Numerics
@Test public void nv_sub_1() { testSub("12", "13", "-1" ) ; }
@Test public void nv_sub_2() { testSub("12", "13.0", "-1.0" ) ; }
@@ -96,6 +97,17 @@ public class TestNodeValueOps extends Ba
@Test(expected=ExprEvalException.class)
public void nv_sub_50() { testSub("'12'", "'13'" ) ; }
+ // ** Multiplication
+
+ @Test public void nv_mult_1() { testMult("12", "13", "156" ) ; }
+ @Test public void nv_mult_2() { testMult("-12", "13.0", "-156.0" ) ; }
+ @Test public void nv_mult_3() { testMult("'PT1H2M'^^xsd:duration", "2", "'PT2H4M'^^xsd:dayTimeDuration") ; }
+
+ // ** Division
+ @Test public void nv_div_1() { testDiv("12", "2", "6." ) ; }
+ @Test public void nv_div_2() { testDiv("12", "2e0", "6.0e0" ) ; }
+
+ // == Workers
static void testAdd(String s1, String s2, String s3)
{
@@ -108,7 +120,7 @@ public class TestNodeValueOps extends Ba
{
NodeValue nv1 = NodeValue.parse(s1) ;
NodeValue nv2 = NodeValue.parse(s2) ;
- return NV2.addNV(nv1, nv2) ;
+ return NodeValueOps.additionNV(nv1, nv2) ;
}
static void testSub(String s1, String s2, String s3)
@@ -122,7 +134,35 @@ public class TestNodeValueOps extends Ba
{
NodeValue nv1 = NodeValue.parse(s1) ;
NodeValue nv2 = NodeValue.parse(s2) ;
- return NV2.subNV(nv1, nv2) ;
+ return NodeValueOps.subtractionNV(nv1, nv2) ;
+ }
+
+ static void testMult(String s1, String s2, String s3)
+ {
+ NodeValue nv3 = NodeValue.parse(s3) ;
+ NodeValue nv = testMult(s1, s2) ;
+ assertEquals(nv3, nv) ;
+ }
+
+ static NodeValue testMult(String s1, String s2)
+ {
+ NodeValue nv1 = NodeValue.parse(s1) ;
+ NodeValue nv2 = NodeValue.parse(s2) ;
+ return NodeValueOps.multiplicationNV(nv1, nv2) ;
+ }
+
+ static void testDiv(String s1, String s2, String s3)
+ {
+ NodeValue nv3 = NodeValue.parse(s3) ;
+ NodeValue nv = testDiv(s1, s2) ;
+ assertEquals(nv3, nv) ;
+ }
+
+ static NodeValue testDiv(String s1, String s2)
+ {
+ NodeValue nv1 = NodeValue.parse(s1) ;
+ NodeValue nv2 = NodeValue.parse(s2) ;
+ return NodeValueOps.divisionNV(nv1, nv2) ;
}
}