jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1331975 - in /incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql: expr/NodeValue.java expr/nodevalue/XSDFuncOp.java util/Utils.java
Date Sun, 29 Apr 2012 19:04:39 GMT
Author: andy
Date: Sun Apr 29 19:04:38 2012
New Revision: 1331975

URL: http://svn.apache.org/viewvc?rev=1331975&view=rev
Log:
Odds and ends

Modified:
    incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/expr/NodeValue.java
    incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/expr/nodevalue/XSDFuncOp.java
    incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/util/Utils.java

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/expr/NodeValue.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/expr/NodeValue.java?rev=1331975&r1=1331974&r2=1331975&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/expr/NodeValue.java
(original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/expr/NodeValue.java
Sun Apr 29 19:04:38 2012
@@ -151,6 +151,14 @@ public abstract class NodeValue extends 
     private static final String strForUnNode = "node value nothing" ;
     public static final NodeValue nvNothing = NodeValue.makeNode(Node.createAnon(new AnonId("node
value nothing"))) ;
     
+    private static DatatypeFactory datatypefactory = null ;
+    static
+    {
+        try { datatypefactory = DatatypeFactory.newInstance() ; }
+        catch (DatatypeConfigurationException ex)
+        { throw new ARQInternalErrorException("Can't create a javax.xml DatatypeFactory")
; }
+    }
+    
     // Use NodeValue.toNode(NodeValue) 
 //    public static Node asNode(NodeValue nv)
 //    {
@@ -182,8 +190,12 @@ public abstract class NodeValue extends 
     // ----------------------------------------------------------------
     // ---- Construct NodeValue without a graph node.
     
+    /** Convenience operation - parse a string to produce a NodeValue - common namespaces
like xsd: are built-in */
+    public static NodeValue parse(String string)
+    { return makeNode(NodeFactory.parseNode(string)) ; }
+    
     public static NodeValue makeInteger(long i)
-    { return new NodeValueInteger(i) ; }
+    { return new NodeValueInteger(BigInteger.valueOf(i)) ; }
     
     public static NodeValue makeInteger(BigInteger i)
     { return new NodeValueInteger(i) ; }
@@ -204,11 +216,10 @@ public abstract class NodeValue extends 
     { return new NodeValueDecimal(d) ; }
   
     public static NodeValue makeDecimal(long i)
-    //{ return new NodeValueDecimal(new BigDecimal(i)) ; } // Java 1.5-ism - the long constructor.
 If 1.4, type promotion to double :-( 
     { return new NodeValueDecimal(BigDecimal.valueOf(i)) ; }
   
     public static NodeValue makeDecimal(double d)
-    { return new NodeValueDecimal(new BigDecimal(d)) ; }   // java 1.5 ; use BigDecimal.valueOf(double)
+    { return new NodeValueDecimal(BigDecimal.valueOf(d)) ; } 
   
     public static NodeValue makeDecimal(String lexicalForm)
     { return NodeValue.makeNode(lexicalForm, XSDDatatype.XSDdecimal) ; }
@@ -235,6 +246,9 @@ public abstract class NodeValue extends 
         XSDDateTime xdt = new XSDDateTime(cal) ;
         return new NodeValueDate(xdt) ;
     }
+    
+    public static NodeValue makeDuration(String lexicalForm)
+    { return NodeValue.makeNode(lexicalForm, XSDDatatype.XSDduration) ; }
 
     public static NodeValue makeBoolean(boolean b)
     { return b ? NodeValue.TRUE : NodeValue.FALSE ; }
@@ -336,8 +350,6 @@ public abstract class NodeValue extends 
     
     public static NodeValue makeNodeDecimal(BigDecimal decimal)
     {
-        // Java 1.5-ism
-        //NodeValue nv = makeNode(decimal.toPlainString(), null, XSD.decimal.getURI()) ;
         NodeValue nv = makeNode(Utils.stringForm(decimal), null, XSD.decimal.getURI()) ;
         return nv ;
     }
@@ -356,7 +368,6 @@ public abstract class NodeValue extends 
     
     public static NodeValue makeNodeDateTime(Calendar date)
     {
-        //XSDDateTime dt = new XSDDateTime(date) ;
         String lex = Utils.calendarToXSDDateTimeString(date) ;
         NodeValue nv = makeNode(lex, XSDDatatype.XSDdateTime) ;
         return nv ;
@@ -1105,18 +1116,10 @@ public abstract class NodeValue extends 
     }
     
     // ----------------------------------------------------------------
-    
-    private static DatatypeFactory df = null ;
-    static
-    {
-        try { df = DatatypeFactory.newInstance() ; }
-        catch (DatatypeConfigurationException ex)
-        { throw new ARQInternalErrorException("Can't create a javax.xml DatatypeFactory")
; }
-    }
 
     private static Duration createDuration(String lex)
     {
-        return df.newDuration(lex) ;
+        return datatypefactory.newDuration(lex) ;
     }
     
     // Point to catch all exceptions.

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/expr/nodevalue/XSDFuncOp.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/expr/nodevalue/XSDFuncOp.java?rev=1331975&r1=1331974&r2=1331975&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/expr/nodevalue/XSDFuncOp.java
(original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/expr/nodevalue/XSDFuncOp.java
Sun Apr 29 19:04:38 2012
@@ -110,9 +110,6 @@ public class XSDFuncOp
         }
     }
     
-    // Java 1.4 does not have BigDecimal.ZERO
-    private static final BigDecimal BigDecimalZero = new BigDecimal(0e0) ;
-    
     /* Quote from XQuery/XPath F&O:
         For xs:float or xs:double values, a positive number divided by positive zero returns
INF.
         A negative number divided by positive zero returns -INF.
@@ -136,7 +133,7 @@ public class XSDFuncOp
             }
             case OP_DECIMAL:
             {
-                if ( nv2.getDecimal().compareTo(BigDecimalZero) == 0 )
+                if ( nv2.getDecimal().compareTo(BigDecimal.ZERO) == 0 )
                     throw new ExprEvalException("Divide by zero in decimal divide") ;
                 BigDecimal d1 = nv1.getDecimal() ;
                 BigDecimal d2 = nv2.getDecimal() ;

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/util/Utils.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/util/Utils.java?rev=1331975&r1=1331974&r2=1331975&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/util/Utils.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/util/Utils.java Sun
Apr 29 19:04:38 2012
@@ -48,14 +48,6 @@ public class Utils
         return tmp ;
     }
     
-    // See also:
-    // Java 1.5
-    // javax.xml.datatype.XMLGregorianCalendar
-    // javax.xml.datatype.DatatypeFactory.newXMLGregorianCalendar 
-
-    // warning all calendar based operations force the timezone
-    // to the default if not present. 
-    
     public static String nowAsXSDDateTimeString()
     {
         return calendarToXSDDateTimeString(new GregorianCalendar()) ;
@@ -148,14 +140,8 @@ public class Utils
         return sign+tzH_str+":"+tzM_str ;
     }
     
-    // Java 1.4 .toString == Java 1.5 .toPlainString
-    // Java 1.5 .toString => different to .toString 1.4
-    // Portable(?!) - round to scale 0 and get the toString
-    
     static public String stringForm(BigDecimal decimal)
     { 
-        // Java 1.5-ism -- 
-        //return decimal.toPlainString() ;
         return decimal.toPlainString() ;
     }
     



Mime
View raw message