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 2014/12/07 18:10:15 UTC
jena git commit: NodeId.hasInlineDatatype
Repository: jena
Updated Branches:
refs/heads/master 06f1790ac -> 3dc84d3b5
NodeId.hasInlineDatatype
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/3dc84d3b
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/3dc84d3b
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/3dc84d3b
Branch: refs/heads/master
Commit: 3dc84d3b5e1b6dc6810fecc9ce3b64992cf7e1c8
Parents: 06f1790
Author: Andy Seaborne <an...@apache.org>
Authored: Sun Dec 7 17:09:50 2014 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Sun Dec 7 17:09:50 2014 +0000
----------------------------------------------------------------------
.../java/com/hp/hpl/jena/tdb/store/NodeId.java | 32 ++++++++++++++++++++
.../com/hp/hpl/jena/tdb/store/TestNodeId.java | 10 +++---
2 files changed, 38 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/3dc84d3b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/NodeId.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/NodeId.java b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/NodeId.java
index 4e1d537..cc82642 100644
--- a/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/NodeId.java
+++ b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/NodeId.java
@@ -25,6 +25,7 @@ import org.apache.jena.atlas.lib.BitsLong ;
import org.apache.jena.atlas.lib.Bytes ;
import org.apache.jena.atlas.logging.Log ;
+import com.hp.hpl.jena.datatypes.RDFDatatype ;
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype ;
import com.hp.hpl.jena.graph.Node ;
import com.hp.hpl.jena.graph.NodeFactory ;
@@ -172,6 +173,37 @@ public class NodeId
return null ;
}
}
+
+ /** Datatypes that are candidates for inlining */
+ private static RDFDatatype[] datatypes = {
+ XSDDatatype.XSDdecimal,
+ XSDDatatype.XSDinteger,
+
+ XSDDatatype.XSDlong,
+ XSDDatatype.XSDint,
+ XSDDatatype.XSDshort,
+ XSDDatatype.XSDbyte,
+
+ XSDDatatype.XSDunsignedLong,
+ XSDDatatype.XSDunsignedInt,
+ XSDDatatype.XSDunsignedShort,
+ XSDDatatype.XSDunsignedByte,
+
+ XSDDatatype.XSDdateTime,
+ XSDDatatype.XSDdate,
+ XSDDatatype.XSDboolean
+ } ;
+
+ /** Return true if this node has a datatype that look sliek it is inlineable.
+ * The node may still be out of range (e.g. very large integer).
+ * Only inline(Node)->NodeId can determine that.
+ */
+ public static boolean hasInlineDatatype(Node node) {
+ RDFDatatype dtn = node.getLiteralDatatype() ;
+ for ( RDFDatatype dt : datatypes )
+ if ( dt.equals(dtn) ) return true ;
+ return false ;
+ }
private static NodeId inline$(Node node)
{
http://git-wip-us.apache.org/repos/asf/jena/blob/3dc84d3b/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestNodeId.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestNodeId.java b/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestNodeId.java
index 439048a..4a80d18 100644
--- a/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestNodeId.java
+++ b/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestNodeId.java
@@ -225,10 +225,7 @@ public class TestNodeId extends BaseTest
@Test public void nodeId_boolean_4()
{ test("'0'^^xsd:boolean", NodeFactoryExtra.parseNode("'false'^^xsd:boolean")) ; }
- private void test(String x)
- {
- test(x, x) ;
- }
+ private void test(String x) { test(x, x) ; }
private void test(String x, String expected)
{
@@ -239,6 +236,11 @@ public class TestNodeId extends BaseTest
{
Node n = NodeFactoryExtra.parseNode(x) ;
NodeId nodeId = NodeId.inline(n) ;
+ boolean b = NodeId.hasInlineDatatype(n) ;
+
+ if ( nodeId != null )
+ assertTrue("Converted NodeId but datatype test was false", b) ;
+
if ( correct == null )
{
assertNull("Expected no encoding: got: "+nodeId, nodeId) ;