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 2015/07/14 15:44:27 UTC
[2/8] jena git commit: JENA-986: BlankNodeId - graph-level bnode
system identifier.
JENA-986: BlankNodeId - graph-level bnode system identifier.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/da0ccfe3
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/da0ccfe3
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/da0ccfe3
Branch: refs/heads/master
Commit: da0ccfe394c3b92accc6fc35b2fe8eef32a964b0
Parents: fc598a9
Author: Andy Seaborne <an...@apache.org>
Authored: Mon Jul 13 11:37:23 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Mon Jul 13 11:37:23 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/jena/graph/BlankNodeId.java | 156 +++++++++++++++++++
1 file changed, 156 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/da0ccfe3/jena-core/src/main/java/org/apache/jena/graph/BlankNodeId.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/graph/BlankNodeId.java b/jena-core/src/main/java/org/apache/jena/graph/BlankNodeId.java
new file mode 100644
index 0000000..08a340c
--- /dev/null
+++ b/jena-core/src/main/java/org/apache/jena/graph/BlankNodeId.java
@@ -0,0 +1,156 @@
+/*
+ * 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 org.apache.jena.graph;
+
+import java.rmi.server.UID;
+import java.util.concurrent.atomic.AtomicInteger ;
+
+import org.apache.jena.rdf.model.AnonId ;
+import org.apache.jena.shared.impl.JenaParameters ;
+
+/** System identifier for a blank node.
+ *
+ * Blank nodes have identity (you can .equals them apart)
+ * but no external stable identifier like a URI.
+ * <p>
+ * Databases need a persistent identifier for blank nodes - BlankNodeId.
+ * <p>
+ * The equivalent concept for the API is {@link AnonId}.
+ * Historically, that has been in the org.apache.jena.rdf.model
+ * package.
+ *
+ *
+ * <p>This id is guaranteed to be unique on this machine.</p>
+ */
+
+public class BlankNodeId extends java.lang.Object {
+
+ // Support for running in environments, like Google App Engine, where
+ // java.rmi.server.UID is not available
+ // Will be obsoleted by improved AnonId handling
+ static boolean UIDok = true;
+ static {
+ try { new UID() ; }
+ catch (Throwable ex) { UIDok = false ; }
+ }
+
+ protected String id = null;
+
+ /**
+ * Support for debugging: global BlankNodeId counter. The intial value is
+ * just to make the output look prettier if it has lots (but not lots and
+ * lots) of bnodes in it.
+ */
+ private static AtomicInteger idCount = new AtomicInteger(100000) ;
+
+ public static BlankNodeId create()
+ { return new BlankNodeId(); }
+
+ public static BlankNodeId create( String id )
+ { return new BlankNodeId( id ); }
+
+ /**
+ * Creates new BlankNodeId. Normally this id is guaranteed to be unique on
+ * this machine: it is time-dependant. However, sometimes [incorrect] code
+ * is sensitive to bnode ordering and produces bizarre bugs. Hence the
+ * disableBNodeUIDGeneration flag, which allows bnode IDs to be predictable.
+ */
+ protected BlankNodeId() {
+ if (JenaParameters.disableBNodeUIDGeneration)
+ id = "A" + idCount.getAndIncrement();
+ else if (!UIDok)
+ id = java.util.UUID.randomUUID().toString();
+ else
+ id = (new UID()).toString();
+ }
+
+
+ /** Create a new BlankNodeId from the string argument supplied.
+ * @param id A string representation of the id to be created.
+ */
+ public BlankNodeId( String id ) {
+ this.id = id;
+ }
+
+ protected BlankNodeId( BlankNodeId id ) {
+ this.id = id.getLabelString();
+ }
+
+
+ //@Override
+ public int hashCode1() {
+ final int prime = 31 ;
+ int result = 1 ;
+ result = prime * result + ((id == null) ? 0 : id.hashCode()) ;
+ return result ;
+ }
+
+ /** return a hashcode for this id
+ * @return the hash code
+ */
+ @Override
+ public int hashCode() {
+ return id.hashCode();
+ }
+
+ /**
+ * Test whether two id's are the same
+ *
+ * @param other the object to be compared
+ * @return true if and only if the two id's are the same
+ */
+ @Override
+ public boolean equals( Object other ) {
+ return other instanceof BlankNodeId && id.equals( ((BlankNodeId) other).id );
+ }
+
+ //@Override
+ public boolean equals1(Object obj) {
+ if ( this == obj )
+ return true ;
+ if ( obj == null )
+ return false ;
+ if ( !(obj instanceof BlankNodeId) )
+ return false ;
+ BlankNodeId other = (BlankNodeId)obj ;
+ if ( id == null ) {
+ if ( other.id != null )
+ return false ;
+ } else if ( !id.equals(other.id) )
+ return false ;
+ return true ;
+ }
+
+
+ /** return a string representation of the id
+ * @return a string representation of the id
+ */
+ @Override
+ public String toString() {
+ return id;
+ }
+
+ /**
+ * Answer the label string of this BlankNodeId. To be used in preference to
+ * {@code toString}
+ */
+ public String getLabelString() {
+ return id;
+ }
+}