COMMONSRDF-6 BlankNode.internalIdentifier() -> uniqueReference
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/08c9f91f Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/08c9f91f Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/08c9f91f Branch: refs/heads/master Commit: 08c9f91f8b3491d82eb65a792b55fb53dd22b2ee Parents: 0a18eff Author: Stian Soiland-Reyes <st...@apache.org> Authored: Fri Apr 24 11:46:08 2015 +0100 Committer: Stian Soiland-Reyes <st...@apache.org> Committed: Fri Apr 24 11:49:54 2015 +0100 ---------------------------------------------------------------------- .../org/apache/commons/rdf/api/BlankNode.java | 8 +-- .../apache/commons/rdf/api/RDFTermFactory.java | 2 +- .../commons/rdf/api/AbstractBlankNodeTest.java | 54 ++++++++++---------- .../rdf/api/AbstractRDFTermFactoryTest.java | 8 +-- .../commons/rdf/simple/BlankNodeImpl.java | 28 +++++----- .../apache/commons/rdf/simple/GraphImpl.java | 2 +- .../rdf/simple/SimpleRDFTermFactory.java | 4 +- 7 files changed, 53 insertions(+), 53 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08c9f91f/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java b/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java index 52c472d..024b6a3 100644 --- a/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java +++ b/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java @@ -48,7 +48,7 @@ import java.util.UUID; * by the syntax. </blockquote> * * A BlankNode SHOULD contain a {@link UUID} string as part of its - * universally unique {@link #internalIdentifier()}. + * universally unique {@link #uniqueReference()}. * * @see RDFTermFactory#createBlankNode() * @see RDFTermFactory#createBlankNode(String) @@ -64,7 +64,7 @@ public interface BlankNode extends BlankNodeOrIRI { * separately in different JVMs or from different {@link RDFTermFactory} * instances MUST NOT have the same reference string. * <p> - * The {@link #internalIdentifier()} of two <code>BlankNode</code> instances + * The {@link #uniqueReference()} of two <code>BlankNode</code> instances * MUST be equal if and only if the two blank nodes are equal according to * {@link #equals(Object)}. * <p> @@ -80,12 +80,12 @@ public interface BlankNode extends BlankNodeOrIRI { * * @return A universally unique reference to identify this {@link BlankNode} */ - String internalIdentifier(); + String uniqueReference(); /** * Check it this BlankNode is equal to another BlankNode. Two BlankNodes * MUST be equal if, and only if, they have the same - * {@link #internalIdentifier()}. + * {@link #uniqueReference()}. * * Implementations MUST also override {@link #hashCode()} so that two equal * Literals produce the same hash code. http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08c9f91f/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java b/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java index 176a704..a4990e0 100644 --- a/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java +++ b/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java @@ -90,7 +90,7 @@ public interface RDFTermFactory { * * {@link BlankNode} objects added to the {@link Graph} returned from this * method SHOULD be mapped using the {@link #createBlankNode(String)} of - * this factory, called using the {@link BlankNode#internalIdentifier()} as + * this factory, called using the {@link BlankNode#uniqueReference()} as * the parameter, before they are inserted into the Graph. * * @return A new Graph http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08c9f91f/api/src/test/java/org/apache/commons/rdf/api/AbstractBlankNodeTest.java ---------------------------------------------------------------------- diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractBlankNodeTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractBlankNodeTest.java index 07de1fd..1556a03 100644 --- a/api/src/test/java/org/apache/commons/rdf/api/AbstractBlankNodeTest.java +++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractBlankNodeTest.java @@ -46,7 +46,7 @@ public abstract class AbstractBlankNodeTest { /** * Test method for - * {@link BlankNode#internalIdentifier()}. + * {@link BlankNode#uniqueReference()}. */ @Test public final void testInternalIdentifier() { @@ -57,7 +57,7 @@ public abstract class AbstractBlankNodeTest { } @Override - public String internalIdentifier() { + public String uniqueReference() { return null; } }; @@ -68,30 +68,30 @@ public abstract class AbstractBlankNodeTest { BlankNode testManual4 = getBlankNode("4"); // Test against our fake stub - assertNotEquals(testNull.internalIdentifier(), - testAutomatic1.internalIdentifier()); - assertNotEquals(testAutomatic1.internalIdentifier(), - testNull.internalIdentifier()); - assertNotEquals(testNull.internalIdentifier(), - testManual3a.internalIdentifier()); - assertNotEquals(testManual3a.internalIdentifier(), - testNull.internalIdentifier()); + assertNotEquals(testNull.uniqueReference(), + testAutomatic1.uniqueReference()); + assertNotEquals(testAutomatic1.uniqueReference(), + testNull.uniqueReference()); + assertNotEquals(testNull.uniqueReference(), + testManual3a.uniqueReference()); + assertNotEquals(testManual3a.uniqueReference(), + testNull.uniqueReference()); // Test the two imported instances against each other - assertEquals(testAutomatic1.internalIdentifier(), - testAutomatic1.internalIdentifier()); - assertEquals(testAutomatic2.internalIdentifier(), - testAutomatic2.internalIdentifier()); - assertNotEquals(testAutomatic1.internalIdentifier(), - testAutomatic2.internalIdentifier()); - assertNotEquals(testAutomatic2.internalIdentifier(), - testAutomatic1.internalIdentifier()); - assertNotEquals(testAutomatic1.internalIdentifier(), - testManual3a.internalIdentifier()); - assertEquals(testManual3b.internalIdentifier(), - testManual3a.internalIdentifier()); - assertNotEquals(testManual3a.internalIdentifier(), - testManual4.internalIdentifier()); + assertEquals(testAutomatic1.uniqueReference(), + testAutomatic1.uniqueReference()); + assertEquals(testAutomatic2.uniqueReference(), + testAutomatic2.uniqueReference()); + assertNotEquals(testAutomatic1.uniqueReference(), + testAutomatic2.uniqueReference()); + assertNotEquals(testAutomatic2.uniqueReference(), + testAutomatic1.uniqueReference()); + assertNotEquals(testAutomatic1.uniqueReference(), + testManual3a.uniqueReference()); + assertEquals(testManual3b.uniqueReference(), + testManual3a.uniqueReference()); + assertNotEquals(testManual3a.uniqueReference(), + testManual4.uniqueReference()); } /** @@ -107,7 +107,7 @@ public abstract class AbstractBlankNodeTest { } @Override - public String internalIdentifier() { + public String uniqueReference() { return null; } }; @@ -145,7 +145,7 @@ public abstract class AbstractBlankNodeTest { } @Override - public String internalIdentifier() { + public String uniqueReference() { return null; } }; @@ -184,7 +184,7 @@ public abstract class AbstractBlankNodeTest { } @Override - public String internalIdentifier() { + public String uniqueReference() { return null; } }; http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08c9f91f/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java ---------------------------------------------------------------------- diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java index b0a1152..99a7e0a 100644 --- a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java +++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java @@ -63,7 +63,7 @@ public abstract class AbstractRDFTermFactoryTest { BlankNode bnode2 = factory.createBlankNode(); assertNotEquals( "Second blank node has not got a unique internal identifier", - bnode.internalIdentifier(), bnode2.internalIdentifier()); + bnode.uniqueReference(), bnode2.uniqueReference()); } @Test @@ -102,12 +102,12 @@ public abstract class AbstractRDFTermFactoryTest { return; } // We don't know what the identifier is, but it MUST be the same - assertEquals(bnode1.internalIdentifier(), bnode2.internalIdentifier()); + assertEquals(bnode1.uniqueReference(), bnode2.uniqueReference()); // We don't know what the ntriplesString is, but it MUST be the same assertEquals(bnode1.ntriplesString(), bnode2.ntriplesString()); // and here it MUST differ - assertNotEquals(bnode1.internalIdentifier(), - bnode3.internalIdentifier()); + assertNotEquals(bnode1.uniqueReference(), + bnode3.uniqueReference()); assertNotEquals(bnode1.ntriplesString(), bnode3.ntriplesString()); } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08c9f91f/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java ---------------------------------------------------------------------- diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java index a1c75a1..cdfdc92 100644 --- a/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java +++ b/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java @@ -32,22 +32,22 @@ final class BlankNodeImpl implements BlankNode { private static final UUID SALT = UUID.randomUUID(); private static final AtomicLong COUNTER = new AtomicLong(); - private final String id; + private final String uniqueReference; public BlankNodeImpl() { this(SALT, Long.toString(COUNTER.incrementAndGet())); } - public BlankNodeImpl(UUID uuidSalt, String id) { - if (Objects.requireNonNull(id).isEmpty()) { - throw new IllegalArgumentException("Invalid blank node id: " + id); + public BlankNodeImpl(UUID uuidSalt, String name) { + if (Objects.requireNonNull(name).isEmpty()) { + throw new IllegalArgumentException("Invalid blank node id: " + name); } // Build a semi-URN - to be hashed for a name-based UUID below // Both the scope and the id are used to create the UUID, ensuring that // a caller can reliably create the same bnode if necessary by sending // in the same scope to RDFTermFactory.createBlankNode(String) - String uuidInput = "urn:uuid:" + uuidSalt + "#" + id; + String uuidInput = "urn:uuid:" + uuidSalt + "#" + name; // The above is not a good value for this.id, as the id // needs to be further escaped for @@ -56,7 +56,7 @@ final class BlankNodeImpl implements BlankNode { // Rather than implement ntriples escaping here, and knowing - // the internalIdentifier should contain a UUID anyway, we simply + // the uniqueReference() contain a UUID anyway, we simply // create another name-based UUID, and use it within both // internalIdentifier() and within ntriplesString(). // @@ -64,18 +64,18 @@ final class BlankNodeImpl implements BlankNode { // is not preserved or shown in ntriplesString. In a way // this is a feature, not a bug. as the contract for RDFTermFactory // has no such requirement. - this.id = UUID.nameUUIDFromBytes( + this.uniqueReference = UUID.nameUUIDFromBytes( uuidInput.getBytes(StandardCharsets.UTF_8)).toString(); } @Override - public String internalIdentifier() { - return id; + public String uniqueReference() { + return uniqueReference; } @Override public String ntriplesString() { - return "_:" + id; + return "_:" + uniqueReference; } @Override @@ -85,7 +85,7 @@ final class BlankNodeImpl implements BlankNode { @Override public int hashCode() { - return id.hashCode(); + return uniqueReference.hashCode(); } @Override @@ -101,11 +101,11 @@ final class BlankNodeImpl implements BlankNode { return false; } BlankNodeImpl other = (BlankNodeImpl) obj; - if (id == null) { - if (other.id != null) { + if (uniqueReference == null) { + if (other.uniqueReference != null) { return false; } - } else if (!id.equals(other.id)) { + } else if (!uniqueReference.equals(other.uniqueReference)) { return false; } return true; http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08c9f91f/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java ---------------------------------------------------------------------- diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java index 69ff96c..884f273 100644 --- a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java +++ b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java @@ -78,7 +78,7 @@ final class GraphImpl implements Graph { // this graph will generate a local object that is mapped to an // equivalent object, based on the code in the package private // BlankNodeImpl class - return factory.createBlankNode(blankNode.internalIdentifier()); + return factory.createBlankNode(blankNode.uniqueReference()); } else if (object instanceof IRI && !(object instanceof IRIImpl)) { IRI iri = (IRI) object; return factory.createIRI(iri.getIRIString()); http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08c9f91f/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java ---------------------------------------------------------------------- diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java index b84fcd5..97ad340 100644 --- a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java +++ b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java @@ -47,8 +47,8 @@ public class SimpleRDFTermFactory implements RDFTermFactory { } @Override - public BlankNode createBlankNode(String identifier) { - return new BlankNodeImpl(SALT, identifier); + public BlankNode createBlankNode(String name) { + return new BlankNodeImpl(SALT, name); } @Override