reformatted code
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/5ee4c293 Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/5ee4c293 Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/5ee4c293 Branch: refs/heads/master Commit: 5ee4c293ce7c5a03e0bcaba12b90154c80515725 Parents: 67db96f Author: Sergio Fernández <wik...@apache.org> Authored: Sat Apr 4 09:36:34 2015 +0200 Committer: Sergio Fernández <wik...@apache.org> Committed: Sat Apr 4 09:36:34 2015 +0200 ---------------------------------------------------------------------- api/pom.xml | 4 +- .../org/apache/commons/rdf/api/BlankNode.java | 114 ++- .../java/org/apache/commons/rdf/api/Graph.java | 233 +++--- .../java/org/apache/commons/rdf/api/IRI.java | 92 ++- .../org/apache/commons/rdf/api/Literal.java | 172 ++--- .../org/apache/commons/rdf/api/RDFTerm.java | 2 +- .../apache/commons/rdf/api/RDFTermFactory.java | 433 +++++------ .../java/org/apache/commons/rdf/api/Triple.java | 129 ++-- .../commons/rdf/api/AbstractBlankNodeTest.java | 393 +++++----- .../commons/rdf/api/AbstractGraphTest.java | 482 ++++++------ .../rdf/api/AbstractRDFTermFactoryTest.java | 753 +++++++++---------- .../rdf/api/DefaultRDFTermFactoryTest.java | 11 +- pom.xml | 67 +- simple/pom.xml | 62 +- .../commons/rdf/simple/BlankNodeImpl.java | 120 +-- .../apache/commons/rdf/simple/GraphImpl.java | 296 ++++---- .../org/apache/commons/rdf/simple/IRIImpl.java | 75 +- .../apache/commons/rdf/simple/LiteralImpl.java | 213 +++--- .../rdf/simple/SimpleRDFTermFactory.java | 87 +-- .../apache/commons/rdf/simple/TripleImpl.java | 108 ++- .../org/apache/commons/rdf/simple/Types.java | 642 +++++++++------- .../apache/commons/rdf/simple/package-info.java | 2 +- .../commons/rdf/simple/BlankNodeImplTest.java | 21 +- .../commons/rdf/simple/DefaultGraphTest.java | 35 +- .../commons/rdf/simple/SimpleGraphTest.java | 9 +- .../SimpleNoRelativeIRIRDFTermFactoryTest.java | 33 +- .../rdf/simple/SimpleRDFTermFactoryTest.java | 9 +- .../commons/rdf/simple/TestWritingGraph.java | 239 +++--- .../apache/commons/rdf/simple/TypesTest.java | 79 +- 29 files changed, 2453 insertions(+), 2462 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5ee4c293/api/pom.xml ---------------------------------------------------------------------- diff --git a/api/pom.xml b/api/pom.xml index 8e2139d..1e1a7b5 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -32,12 +32,12 @@ <name>Commons RDF: API</name> <description>Commons Java API for RDF 1.1</description> - + <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> - </dependency> + </dependency> </dependencies> </project> http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5ee4c293/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 a8283c9..0239416 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 @@ -24,13 +24,13 @@ import java.util.UUID; * Blank Node</a>, as defined by <a href= * "http://www.w3.org/TR/rdf11-concepts/#section-blank-nodes" >RDF-1.1 Concepts * and Abstract Syntax</a>, a W3C Recommendation published on 25 February 2014.<br> - * <p> + * * Note: <blockquote> <a * href="http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node">Blank nodes</a> * are disjoint from IRIs and literals. Otherwise, the set of possible blank * nodes is arbitrary. RDF makes no reference to any internal structure of blank * nodes. </blockquote> - * <p> + * * Also note that: <blockquote> <a * href="http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node-identifier">Blank * node identifiers</a> are local identifiers that are used in some concrete RDF @@ -41,17 +41,17 @@ import java.util.UUID; * on the concrete syntax or implementation. The syntactic restrictions on blank * node identifiers, if any, therefore also depend on the concrete RDF syntax or * implementation. - * <p> + * * Implementations that handle blank node identifiers in concrete syntaxes need * to be careful not to create the same blank node from multiple occurrences of * the same blank node identifier except in situations where this is supported * by the syntax. </blockquote> - * <p> + * * A BlankNode object created through the * {@link RDFTermFactory#createBlankNode()} method must be universally unique, * and SHOULD contain a {@link UUID} as part of its * {@link #internalIdentifier()}. - * <p> + * * A BlankNode object created through the * {@link RDFTermFactory#createBlankNode(String)} method must be universally * unique, but also produce the same {@link #internalIdentifier()} as any @@ -61,65 +61,63 @@ import java.util.UUID; * {@link UUID#nameUUIDFromBytes(byte[])} using a constant salt for each * instance of {@link RDFTermFactory}, with the given identifier joined to that * salt in a consistent manner. - * <p> + * * * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node">RDF-1.1 - * Blank Node</a> + * Blank Node</a> */ public interface BlankNode extends BlankNodeOrIRI { - /** - * Return a <a href= - * "http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node-identifier" >unique - * label</a> for the blank node. This label is generated by either - * {@link RDFTermFactory#createBlankNode()} or - * {@link RDFTermFactory#createBlankNode(String)} and is unique within the - * context of the instance of the factory. In particular, successive calls - * to the {@link RDFTermFactory#createBlankNode(String)} method on a single - * factory with the same parameters MUST return BlankNode objects with - * identical internalIdentifiers, but the identifiers SHOULD be mapped to - * unique values in the context of the factory instance. - * <p> - * IMPORTANT: This is not a serialization/syntax label, and there are no - * guarantees that it is a valid identifier in any concrete syntax. For an - * N-Triples compatible identifier use {@link #ntriplesString()}. For all - * other syntaxes, the result of this method must be sanitized to produce a - * valid concrete identifier if one is needed. - * <p> - * - * @return An internal, system identifier for the {@link BlankNode} that is - * used primarily to check whether two BlankNode's are equivalent. - */ - String internalIdentifier(); + /** + * Return a <a href= + * "http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node-identifier" >unique + * label</a> for the blank node. This label is generated by either + * {@link RDFTermFactory#createBlankNode()} or + * {@link RDFTermFactory#createBlankNode(String)} and is unique within the + * context of the instance of the factory. In particular, successive calls + * to the {@link RDFTermFactory#createBlankNode(String)} method on a single + * factory with the same parameters MUST return BlankNode objects with + * identical internalIdentifiers, but the identifiers SHOULD be mapped to + * unique values in the context of the factory instance. + * + * IMPORTANT: This is not a serialization/syntax label, and there are no + * guarantees that it is a valid identifier in any concrete syntax. For an + * N-Triples compatible identifier use {@link #ntriplesString()}. For all + * other syntaxes, the result of this method must be sanitized to produce a + * valid concrete identifier if one is needed. + * + * @return An internal, system identifier for the {@link BlankNode} that is + * used primarily to check whether two BlankNode's are equivalent. + */ + String internalIdentifier(); - /** - * Check it this BlankNode is equal to another BlankNode. Two BlankNodes - * MUST be equal if, and only if, they have the same - * {@link #internalIdentifier()}. - * <p> - * Implementations MUST also override {@link #hashCode()} so that two equal - * Literals produce the same hash code. - * - * @param other - * Another object - * @return true if other is a BlankNode, is in the same local scope and is - * equal to this BlankNode - * @see Object#equals(Object) - */ - @Override - public boolean equals(Object other); + /** + * Check it this BlankNode is equal to another BlankNode. Two BlankNodes + * MUST be equal if, and only if, they have the same + * {@link #internalIdentifier()}. + * + * Implementations MUST also override {@link #hashCode()} so that two equal + * Literals produce the same hash code. + * + * @param other Another object + * @return true if other is a BlankNode, is in the same local scope and is + * equal to this BlankNode + * @see Object#equals(Object) + */ + @Override + public boolean equals(Object other); - /** - * Calculate a hash code for this BlankNode. - * <p> - * This method MUST be implemented in conjunction with - * {@link #equals(Object)} so that two equal BlankNodes produce the same - * hash code. - * - * @return a hash code value for this BlankNode. - * @see Object#hashCode() - */ - @Override - public int hashCode(); + /** + * Calculate a hash code for this BlankNode. + * + * This method MUST be implemented in conjunction with + * {@link #equals(Object)} so that two equal BlankNodes produce the same + * hash code. + * + * @return a hash code value for this BlankNode. + * @see Object#hashCode() + */ + @Override + public int hashCode(); } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5ee4c293/api/src/main/java/org/apache/commons/rdf/api/Graph.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/commons/rdf/api/Graph.java b/api/src/main/java/org/apache/commons/rdf/api/Graph.java index f23d6d1..a1e8cf1 100644 --- a/api/src/main/java/org/apache/commons/rdf/api/Graph.java +++ b/api/src/main/java/org/apache/commons/rdf/api/Graph.java @@ -27,138 +27,123 @@ import java.util.stream.Stream; */ public interface Graph extends AutoCloseable { - /** - * Add a triple to the graph, possibly mapping any of the components of the - * Triple to those supported by this Graph. - * - * @param triple - * The triple to add - */ - void add(Triple triple); + /** + * Add a triple to the graph, possibly mapping any of the components of the + * Triple to those supported by this Graph. + * + * @param triple The triple to add + */ + void add(Triple triple); - /** - * Add a triple to the graph, possibly mapping any of the components to - * those supported by this Graph. - * - * @param subject - * The triple subject - * @param predicate - * The triple predicate - * @param object - * The triple object - */ - void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object); + /** + * Add a triple to the graph, possibly mapping any of the components to + * those supported by this Graph. + * + * @param subject The triple subject + * @param predicate The triple predicate + * @param object The triple object + */ + void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object); - /** - * Check if graph contains triple. - * - * @param triple - * The triple to check. - * @return True if the Graph contains the given Triple. - */ - boolean contains(Triple triple); + /** + * Check if graph contains triple. + * + * @param triple The triple to check. + * @return True if the Graph contains the given Triple. + */ + boolean contains(Triple triple); - /** - * Check if graph contains a pattern of triples. - * - * @param subject - * The triple subject (null is a wildcard) - * @param predicate - * The triple predicate (null is a wildcard) - * @param object - * The triple object (null is a wildcard) - * @return True if the Graph contains any Triples that match the given - * pattern. - */ - boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object); + /** + * Check if graph contains a pattern of triples. + * + * @param subject The triple subject (null is a wildcard) + * @param predicate The triple predicate (null is a wildcard) + * @param object The triple object (null is a wildcard) + * @return True if the Graph contains any Triples that match the given + * pattern. + */ + boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object); - /** - * Close the graph, relinquishing any underlying resources. - * <p> - * For example, this would close any open file and network streams and free - * database locks held by the Graph implementation. - * <p> - * The behaviour of the other Graph methods are undefined after closing the - * graph. - * <p> - * Implementations might not need {@link #close()}, hence the default - * implementation does nothing. - */ - @Override - default void close() throws Exception { - } + /** + * Close the graph, relinquishing any underlying resources. + * + * For example, this would close any open file and network streams and free + * database locks held by the Graph implementation. + * + * The behaviour of the other Graph methods are undefined after closing the + * graph. + * + * Implementations might not need {@link #close()}, hence the default + * implementation does nothing. + */ + @Override + default void close() throws Exception { + } - /** - * Remove a concrete triple from the graph. - * - * @param triple - * triple to remove - */ - void remove(Triple triple); + /** + * Remove a concrete triple from the graph. + * + * @param triple triple to remove + */ + void remove(Triple triple); - /** - * Remove a concrete pattern of triples from the graph. - * - * @param subject - * The triple subject (null is a wildcard) - * @param predicate - * The triple predicate (null is a wildcard) - * @param object - * The triple object (null is a wildcard) - */ - void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object); + /** + * Remove a concrete pattern of triples from the graph. + * + * @param subject The triple subject (null is a wildcard) + * @param predicate The triple predicate (null is a wildcard) + * @param object The triple object (null is a wildcard) + */ + void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object); - /** - * Clear the graph, removing all triples. - */ - void clear(); + /** + * Clear the graph, removing all triples. + */ + void clear(); - /** - * Number of triples contained by the graph. - * <p> - * The count of a set does not include duplicates, as determined by the - * equals method for each {@link Triple}. - * - * @return The number of triples in the graph - */ - long size(); + /** + * Number of triples contained by the graph. + * + * The count of a set does not include duplicates, as determined by the + * equals method for each {@link Triple}. + * + * @return The number of triples in the graph + */ + long size(); - /** - * Get all triples contained by the graph.<br> - * <p> - * The iteration SHOULD NOT contain any duplicate triples, as determined by - * the equals method for each {@link Triple}. - * <p> - * The behaviour of the Stream is not specified if add, remove, or clear, - * are called on the Stream before it terminates.<br> - * <p> - * Implementations may throw ConcurrentModificationException from Stream - * methods if they detect a conflict while the Stream is active. - * - * @return A {@link Stream} over all of the triples in the graph - */ - Stream<? extends Triple> getTriples(); + /** + * Get all triples contained by the graph.<br> + * + * The iteration SHOULD NOT contain any duplicate triples, as determined by + * the equals method for each {@link Triple}. + * + * The behaviour of the Stream is not specified if add, remove, or clear, + * are called on the Stream before it terminates.<br> + * + * Implementations may throw ConcurrentModificationException from Stream + * methods if they detect a conflict while the Stream is active. + * + * @return A {@link Stream} over all of the triples in the graph + */ + Stream<? extends Triple> getTriples(); - /** - * Get all triples contained by the graph matched with the pattern. - * <p> - * The iteration does not contain any duplicate triples, as determined by - * the equals method for each {@link Triple}. - * <p> - * The behaviour of the Stream is not specified if add, remove, or clear, - * are called on the Stream before it terminates.<br> - * <p> - * Implementations may throw ConcurrentModificationException from Stream - * methods if they detect a conflict while the Stream is active. - * - * @param subject - * The triple subject (null is a wildcard) - * @param predicate - * The triple predicate (null is a wildcard) - * @param object - * The triple object (null is a wildcard) - * @return A {@link Stream} over the matched triples. - */ - Stream<? extends Triple> getTriples(BlankNodeOrIRI subject, IRI predicate, - RDFTerm object); + /** + * Get all triples contained by the graph matched with the pattern. + * + * The iteration does not contain any duplicate triples, as determined by + * the equals method for each {@link Triple}. + * + * The behaviour of the Stream is not specified if add, remove, or clear, + * are called on the Stream before it terminates.<br> + * + * Implementations may throw ConcurrentModificationException from Stream + * methods if they detect a conflict while the Stream is active. + * + * @param subject The triple subject (null is a wildcard) + * @param predicate The triple predicate (null is a wildcard) + * @param object The triple object (null is a wildcard) + * @return A {@link Stream} over the matched triples. + */ + Stream<? extends Triple> getTriples(BlankNodeOrIRI subject, IRI predicate, + RDFTerm object); } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5ee4c293/api/src/main/java/org/apache/commons/rdf/api/IRI.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/commons/rdf/api/IRI.java b/api/src/main/java/org/apache/commons/rdf/api/IRI.java index 5887983..20ed071 100644 --- a/api/src/main/java/org/apache/commons/rdf/api/IRI.java +++ b/api/src/main/java/org/apache/commons/rdf/api/IRI.java @@ -21,58 +21,52 @@ package org.apache.commons.rdf.api; * An <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-iri" >RDF-1.1 IRI</a>, * as defined by <a href= "http://www.w3.org/TR/rdf11-concepts/" >RDF-1.1 * Concepts and Abstract Syntax</a>, a W3C Recommendation published on 25 - * February 2014.<br> + * February 2014. */ public interface IRI extends BlankNodeOrIRI { - /** - * Return the IRI encoded as a native Unicode String.<br> - * - * The returned string must not include URL-encoding to escape non-ASCII - * characters. - * - * @return The IRI encoded as a native Unicode String. - */ - String getIRIString(); + /** + * Return the IRI encoded as a native Unicode String.<br> + * + * The returned string must not include URL-encoding to escape non-ASCII + * characters. + * + * @return The IRI encoded as a native Unicode String. + */ + String getIRIString(); - /** - * Check it this IRI is equal to another IRI. <blockquote> <a - * href="http://www.w3.org/TR/rdf11-concepts/#section-IRIs">IRI - * equality</a>: Two IRIs are equal if and only if they are equivalent under - * Simple String Comparison according to section 5.1 of [RFC3987]. Further - * normalization MUST NOT be performed when comparing IRIs for equality. - * </blockquote> - * <p> - * Two IRIs are equal are in the same local scope and their - * {@link #getIRIString()} are equal. - * </p> - * <p> - * Implementations MAY check the local scope for IRI comparison. - * </p> - * <p> - * Implementations MUST also override {@link #hashCode()} so that two equal - * IRIs produce the same hash code. - * </p> - * - * @see Object#equals(Object) - * - * @param other - * Another object - * @return true if other is an IRI and is equal to this - */ - @Override - public boolean equals(Object other); + /** + * Check it this IRI is equal to another IRI. <blockquote> <a + * href="http://www.w3.org/TR/rdf11-concepts/#section-IRIs">IRI + * equality</a>: Two IRIs are equal if and only if they are equivalent under + * Simple String Comparison according to section 5.1 of [RFC3987]. Further + * normalization MUST NOT be performed when comparing IRIs for equality. + * </blockquote> + * + * Two IRIs are equal are in the same local scope and their + * {@link #getIRIString()} are equal. + * + * Implementations MAY check the local scope for IRI comparison. + * + * Implementations MUST also override {@link #hashCode()} so that two equal + * IRIs produce the same hash code. + * + * @param other Another object + * @return true if other is an IRI and is equal to this + * @see Object#equals(Object) + */ + @Override + public boolean equals(Object other); - /** - * Calculate a hash code for this IRI. - * <p> - * This method MUST be implemented when implementing {@link #equals(Object)} - * so that two equal IRIs produce the same hash code. - * - * @see Object#hashCode() - * - * @return a hash code value for this IRI. - */ - @Override - public int hashCode(); + /** + * Calculate a hash code for this IRI. + * + * This method MUST be implemented when implementing {@link #equals(Object)} + * so that two equal IRIs produce the same hash code. + * + * @return a hash code value for this IRI. + * @see Object#hashCode() + */ + @Override + public int hashCode(); } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5ee4c293/api/src/main/java/org/apache/commons/rdf/api/Literal.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/commons/rdf/api/Literal.java b/api/src/main/java/org/apache/commons/rdf/api/Literal.java index 6f348f0..8e22acb 100644 --- a/api/src/main/java/org/apache/commons/rdf/api/Literal.java +++ b/api/src/main/java/org/apache/commons/rdf/api/Literal.java @@ -28,98 +28,92 @@ import java.util.Optional; */ public interface Literal extends RDFTerm { - /** - * The lexical form of this literal, represented by a <a - * href="http://www.unicode.org/versions/latest/">Unicode string</a>. - * - * @return The lexical form of this literal. - * @see <a - * href="http://www.w3.org/TR/rdf11-concepts/#dfn-lexical-form">RDF-1.1 - * Literal lexical form</a> - */ - String getLexicalForm(); + /** + * The lexical form of this literal, represented by a <a + * href="http://www.unicode.org/versions/latest/">Unicode string</a>. + * + * @return The lexical form of this literal. + * @see <a + * href="http://www.w3.org/TR/rdf11-concepts/#dfn-lexical-form">RDF-1.1 + * Literal lexical form</a> + */ + String getLexicalForm(); - /** - * The IRI identifying the datatype that determines how the lexical form - * maps to a literal value. - * <p> - * If the datatype IRI is <a - * href="http://www.w3.org/1999/02/22-rdf-syntax-ns#langString" - * >http://www.w3.org/1999/02/22-rdf-syntax-ns#langString</a>, - * {@link #getLanguageTag()} must not return {@link Optional#empty()}, and - * it must return a valid <a - * href="http://tools.ietf.org/html/bcp47">BCP47</a> language tag. - * - * @return The datatype IRI for this literal. - * @see <a - * href="http://www.w3.org/TR/rdf11-concepts/#dfn-datatype-iri">RDF-1.1 - * Literal datatype IRI</a> - */ - IRI getDatatype(); + /** + * The IRI identifying the datatype that determines how the lexical form + * maps to a literal value. + * + * If the datatype IRI is <a + * href="http://www.w3.org/1999/02/22-rdf-syntax-ns#langString" + * >http://www.w3.org/1999/02/22-rdf-syntax-ns#langString</a>, + * {@link #getLanguageTag()} must not return {@link Optional#empty()}, and + * it must return a valid <a + * href="http://tools.ietf.org/html/bcp47">BCP47</a> language tag. + * + * @return The datatype IRI for this literal. + * @see <a + * href="http://www.w3.org/TR/rdf11-concepts/#dfn-datatype-iri">RDF-1.1 + * Literal datatype IRI</a> + */ + IRI getDatatype(); - /** - * If and only if the datatype IRI is <a - * href="http://www.w3.org/1999/02/22-rdf-syntax-ns#langString" - * >http://www.w3.org/1999/02/22-rdf-syntax-ns#langString</a>, the language - * tag for this Literal is a non-empty language tag as defined by <a - * href="http://tools.ietf.org/html/bcp47">BCP47</a>.<br> - * If the datatype IRI is not <a - * href="http://www.w3.org/1999/02/22-rdf-syntax-ns#langString" - * >http://www.w3.org/1999/02/22-rdf-syntax-ns#langString</a>, this method - * must return {@link Optional#empty()}. - * <p> - * Implementor note: If your application requires {@link Serializable} - * objects, it is best not to store an {@link Optional} in a field. It is - * recommended to use {@link Optional#ofNullable(Object)} to create the - * return value for this method. - * - * @return The {@link Optional} language tag for this literal. If - * {@link Optional#isPresent()} returns true, the value returned by - * {@link Optional#get()} must be a non-empty string conforming to - * BCP47. - * @see <a - * href="http://www.w3.org/TR/rdf11-concepts/#dfn-language-tag">RDF-1.1 - * Literal language tag</a> - */ - Optional<String> getLanguageTag(); + /** + * If and only if the datatype IRI is <a + * href="http://www.w3.org/1999/02/22-rdf-syntax-ns#langString" + * >http://www.w3.org/1999/02/22-rdf-syntax-ns#langString</a>, the language + * tag for this Literal is a non-empty language tag as defined by <a + * href="http://tools.ietf.org/html/bcp47">BCP47</a>.<br> + * If the datatype IRI is not <a + * href="http://www.w3.org/1999/02/22-rdf-syntax-ns#langString" + * >http://www.w3.org/1999/02/22-rdf-syntax-ns#langString</a>, this method + * must return {@link Optional#empty()}. + * + * Implementation note: If your application requires {@link Serializable} + * objects, it is best not to store an {@link Optional} in a field. It is + * recommended to use {@link Optional#ofNullable(Object)} to create the + * return value for this method. + * + * @return The {@link Optional} language tag for this literal. If + * {@link Optional#isPresent()} returns true, the value returned by + * {@link Optional#get()} must be a non-empty string conforming to + * BCP47. + * @see <a + * href="http://www.w3.org/TR/rdf11-concepts/#dfn-language-tag">RDF-1.1 + * Literal language tag</a> + */ + Optional<String> getLanguageTag(); - /** - * Check it this Literal is equal to another Literal. <blockquote> <a - * href="http://www.w3.org/TR/rdf11-concepts/#dfn-literal-term">Literal term - * equality</a>: Two literals are term-equal (the same RDF literal) if and - * only if the two lexical forms, the two datatype IRIs, and the two - * language tags (if any) compare equal, character by character. Thus, two - * literals can have the same value without being the same RDF term. - * </blockquote> - * <p> - * Implementations MAY check the local scope for Literal comparison. - * </p> - * <p> - * Implementations MUST also override {@link #hashCode()} so that two equal - * Literals produce the same hash code. - * </p> - * - * @see Object#equals(Object) - * - * @param other - * Another object - * @return true if other is a Literal and is equal to this - */ - @Override - public boolean equals(Object other); + /** + * Check it this Literal is equal to another Literal. <blockquote> <a + * href="http://www.w3.org/TR/rdf11-concepts/#dfn-literal-term">Literal term + * equality</a>: Two literals are term-equal (the same RDF literal) if and + * only if the two lexical forms, the two datatype IRIs, and the two + * language tags (if any) compare equal, character by character. Thus, two + * literals can have the same value without being the same RDF term. + * </blockquote> + * + * Implementations MAY check the local scope for Literal comparison. + * + * Implementations MUST also override {@link #hashCode()} so that two equal + * Literals produce the same hash code. + * + * @param other Another object + * @return true if other is a Literal and is equal to this + * @see Object#equals(Object) + */ + @Override + public boolean equals(Object other); - /** - * Calculate a hash code for this Literal. - * <p> - * This method MUST be implemented when implementing {@link #equals(Object)} - * so that two equal Literals produce the same hash code. - * </p> - * - * @see Object#hashCode() - * - * @return a hash code value for this Literal. - */ - @Override - public int hashCode(); + /** + * Calculate a hash code for this Literal. + * + * This method MUST be implemented when implementing {@link #equals(Object)} + * so that two equal Literals produce the same hash code. + * + * @return a hash code value for this Literal. + * @see Object#hashCode() + */ + @Override + public int hashCode(); } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5ee4c293/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java b/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java index b869fd8..731d7cc 100644 --- a/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java +++ b/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java @@ -33,7 +33,7 @@ public interface RDFTerm { * * @return The term serialised as RDF-1.1 N-Triples. * @see <a href="http://www.w3.org/TR/n-triples/#canonical-ntriples"> - * RDF-1.1 N-Triples Canonical form</a> + * RDF-1.1 N-Triples Canonical form</a> */ String ntriplesString(); http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5ee4c293/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 1140e4a..5189bee 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 @@ -22,254 +22,229 @@ import java.util.UUID; /** * Factory for creating RDFTerm and Graph instances. - * <p> + * * It is not specified how an implementation should provide a RDFTermFactory. - * <p> + * * If an implementation does not support a particular method (e.g. it requires * additional parameters or can't create graphs), then it MAY throw * UnsupportedOperationException, as provided by the default implementations * here. - * <p> + * * If a factory method does not allow or support a provided parameter, e.g. * because an IRI is considered invalid, then it SHOULD throw * IllegalArgumentException. - * + * * @see RDFTerm * @see Graph - * */ public interface RDFTermFactory { - /** - * Create a new blank node. - * <p> - * All pairs of {@link BlankNode}s created with this method MUST NOT be - * equal. - * <p> - * If supported, the {@link BlankNode#internalIdentifier()} of the returned - * blank node MUST be a universally unique value across both this and any - * other {@link RDFTermFactory} objects running in the JVM when compared - * with both past and future calls both to this method, and calls to - * {@link #createBlankNode(String)} with any inputs. - * - * @return A new {@link BlankNode} - * @throws UnsupportedOperationException - * If the operation is not supported. - */ - default BlankNode createBlankNode() throws UnsupportedOperationException { - throw new UnsupportedOperationException( - "createBlankNode() not supported"); - } + /** + * Create a new blank node. + * + * All pairs of {@link BlankNode}s created with this method MUST NOT be + * equal. + * + * If supported, the {@link BlankNode#internalIdentifier()} of the returned + * blank node MUST be a universally unique value across both this and any + * other {@link RDFTermFactory} objects running in the JVM when compared + * with both past and future calls both to this method, and calls to + * {@link #createBlankNode(String)} with any inputs. + * + * @return A new {@link BlankNode} + * @throws UnsupportedOperationException If the operation is not supported. + */ + default BlankNode createBlankNode() throws UnsupportedOperationException { + throw new UnsupportedOperationException( + "createBlankNode() not supported"); + } - /** - * Create a blank node based on the given identifier. - * <p> - * All BlankNodes created using this method with the same parameter for a - * single instance of RDFTermFactory MUST be equivalent. Ie, - * {@link BlankNode#equals(Object)} MUST return true. A BlankNode object - * created through the {@link RDFTermFactory#createBlankNode()} method must - * be universally unique, and SHOULD contain a {@link UUID} as part of its - * {@link BlankNode#internalIdentifier()}. - * <p> - * A BlankNode object created through the - * {@link RDFTermFactory#createBlankNode(String)} method must be universally - * unique, but also produce the same {@link BlankNode#internalIdentifier()} as any - * previous or future calls to that method on that factory with the same - * parameters. In addition, it SHOULD contain a {@link UUID} as part of its - * {@link BlankNode#internalIdentifier()}, created using - * {@link UUID#nameUUIDFromBytes(byte[])} using a constant salt for each - * instance of {@link RDFTermFactory}, with the given identifier joined to - * that salt in a consistent manner. - * <p> - * BlankNodes created using this method with the same parameter, for - * different instances of RDFTermFactory, SHOULD NOT be equivalent. - * - * @param identifier - * A non-empty, non-null, String that is unique to this blank - * node in the context of this {@link RDFTermFactory}. - * @return A BlankNode for the given identifier - * @throws UnsupportedOperationException - * If the operation is not supported. - */ - default BlankNode createBlankNode(String identifier) - throws UnsupportedOperationException { - throw new UnsupportedOperationException( - "createBlankNode(String) not supported"); - } + /** + * Create a blank node based on the given identifier. + * + * All BlankNodes created using this method with the same parameter for a + * single instance of RDFTermFactory MUST be equivalent. Ie, + * {@link BlankNode#equals(Object)} MUST return true. A BlankNode object + * created through the {@link RDFTermFactory#createBlankNode()} method must + * be universally unique, and SHOULD contain a {@link UUID} as part of its + * {@link BlankNode#internalIdentifier()}. + * + * A BlankNode object created through the + * {@link RDFTermFactory#createBlankNode(String)} method must be universally + * unique, but also produce the same {@link BlankNode#internalIdentifier()} as any + * previous or future calls to that method on that factory with the same + * parameters. In addition, it SHOULD contain a {@link UUID} as part of its + * {@link BlankNode#internalIdentifier()}, created using + * {@link UUID#nameUUIDFromBytes(byte[])} using a constant salt for each + * instance of {@link RDFTermFactory}, with the given identifier joined to + * that salt in a consistent manner. + * + * BlankNodes created using this method with the same parameter, for + * different instances of RDFTermFactory, SHOULD NOT be equivalent. + * + * @param identifier A non-empty, non-null, String that is unique to this blank + * node in the context of this {@link RDFTermFactory}. + * @return A BlankNode for the given identifier + * @throws UnsupportedOperationException If the operation is not supported. + */ + default BlankNode createBlankNode(String identifier) + throws UnsupportedOperationException { + throw new UnsupportedOperationException( + "createBlankNode(String) not supported"); + } - /** - * Create a new graph. - * <p> - * It is undefined if the graph will be persisted by any underlying storage - * mechanism. - * <p> - * {@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 - * the parameter, before they are inserted into the Graph. - * - * @return A new Graph - * @throws UnsupportedOperationException - * If the operation is not supported. - */ - default Graph createGraph() throws UnsupportedOperationException { - throw new UnsupportedOperationException("createGraph() not supported"); - } + /** + * Create a new graph. + * + * It is undefined if the graph will be persisted by any underlying storage + * mechanism. + * + * {@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 + * the parameter, before they are inserted into the Graph. + * + * @return A new Graph + * @throws UnsupportedOperationException If the operation is not supported. + */ + default Graph createGraph() throws UnsupportedOperationException { + throw new UnsupportedOperationException("createGraph() not supported"); + } - /** - * Create an IRI from a (possibly escaped) String. - * <p> - * The provided iri string MUST be valid according to the <a - * href="http://www.w3.org/TR/rdf11-concepts/#dfn-iri">W3C RDF-1.1 IRI</a> - * definition. - * - * @param iri - * Internationalized Resource Identifier - * @return A new IRI - * @throws IllegalArgumentException - * If the provided string is not acceptable, e.g. does not - * conform to the RFC3987 syntax. - * @throws UnsupportedOperationException - * If the operation is not supported. - */ - default IRI createIRI(String iri) throws IllegalArgumentException, - UnsupportedOperationException { - throw new UnsupportedOperationException( - "createIRI(String) not supported"); - } + /** + * Create an IRI from a (possibly escaped) String. + * + * The provided iri string MUST be valid according to the <a + * href="http://www.w3.org/TR/rdf11-concepts/#dfn-iri">W3C RDF-1.1 IRI</a> + * definition. + * + * @param iri Internationalized Resource Identifier + * @return A new IRI + * @throws IllegalArgumentException If the provided string is not acceptable, e.g. does not + * conform to the RFC3987 syntax. + * @throws UnsupportedOperationException If the operation is not supported. + */ + default IRI createIRI(String iri) throws IllegalArgumentException, + UnsupportedOperationException { + throw new UnsupportedOperationException( + "createIRI(String) not supported"); + } - /** - * Create a simple literal. - * <p> - * The provided lexical form should not be escaped in any sense, e.g. should - * not include "quotes" unless those are part of the literal value. - * <p> - * The returned Literal MUST have a {@link Literal#getLexicalForm()} that is - * equal to the provided lexical form, MUST NOT have a - * {@link Literal#getLanguageTag()} present, and SHOULD return a - * {@link Literal#getDatatype()} that is equal to the IRI - * <code>http://www.w3.org/2001/XMLSchema#string</code>. - * - * - * @param lexicalForm - * The literal value in plain text - * @return The created Literal - * @throws IllegalArgumentException - * If the provided lexicalForm is not acceptable, e.g. because - * it is too large for an underlying storage. - * @throws UnsupportedOperationException - * If the operation is not supported. - */ - default Literal createLiteral(String lexicalForm) - throws IllegalArgumentException, UnsupportedOperationException { - throw new UnsupportedOperationException( - "createLiteral(String) not supported"); - } + /** + * Create a simple literal. + * + * The provided lexical form should not be escaped in any sense, e.g. should + * not include "quotes" unless those are part of the literal value. + * + * The returned Literal MUST have a {@link Literal#getLexicalForm()} that is + * equal to the provided lexical form, MUST NOT have a + * {@link Literal#getLanguageTag()} present, and SHOULD return a + * {@link Literal#getDatatype()} that is equal to the IRI + * <code>http://www.w3.org/2001/XMLSchema#string</code>. + * + * @param lexicalForm The literal value in plain text + * @return The created Literal + * @throws IllegalArgumentException If the provided lexicalForm is not acceptable, e.g. because + * it is too large for an underlying storage. + * @throws UnsupportedOperationException If the operation is not supported. + */ + default Literal createLiteral(String lexicalForm) + throws IllegalArgumentException, UnsupportedOperationException { + throw new UnsupportedOperationException( + "createLiteral(String) not supported"); + } - /** - * Create a literal with the specified data type. - * <p> - * The provided lexical form should not be escaped in any sense, e.g. should - * not include "quotes" unless those are part of the literal value. - * <p> - * It is RECOMMENDED that the provided dataType is one of the <a - * href="http://www.w3.org/TR/rdf11-concepts/#xsd-datatypes">RDF-compatible - * XSD types</a>. - * <p> - * The provided lexical form SHOULD be in the <a - * href="http://www.w3.org/TR/rdf11-concepts/#dfn-lexical-space">lexical - * space</a> of the provided dataType. - * <p> - * The returned Literal SHOULD have a {@link Literal#getLexicalForm()} that - * is equal to the provided lexicalForm, MUST NOT have a - * {@link Literal#getLanguageTag()} present, and MUST return a - * {@link Literal#getDatatype()} that is equivalent to the provided dataType - * IRI. - * - * @param lexicalForm - * The literal value - * @param dataType - * The data type IRI for the literal value, e.g. - * <code>http://www.w3.org/2001/XMLSchema#integer</code> - * @return The created Literal - * @throws IllegalArgumentException - * If any of the provided arguments are not acceptable, e.g. - * because the provided dataType is not permitted. - * @throws UnsupportedOperationException - * If the operation is not supported. - */ - default Literal createLiteral(String lexicalForm, IRI dataType) - throws IllegalArgumentException, UnsupportedOperationException { - throw new UnsupportedOperationException( - "createLiteral(String) not supported"); - } + /** + * Create a literal with the specified data type. + * + * The provided lexical form should not be escaped in any sense, e.g. should + * not include "quotes" unless those are part of the literal value. + * + * It is RECOMMENDED that the provided dataType is one of the <a + * href="http://www.w3.org/TR/rdf11-concepts/#xsd-datatypes">RDF-compatible + * XSD types</a>. + * + * The provided lexical form SHOULD be in the <a + * href="http://www.w3.org/TR/rdf11-concepts/#dfn-lexical-space">lexical + * space</a> of the provided dataType. + * + * The returned Literal SHOULD have a {@link Literal#getLexicalForm()} that + * is equal to the provided lexicalForm, MUST NOT have a + * {@link Literal#getLanguageTag()} present, and MUST return a + * {@link Literal#getDatatype()} that is equivalent to the provided dataType + * IRI. + * + * @param lexicalForm The literal value + * @param dataType The data type IRI for the literal value, e.g. + * <code>http://www.w3.org/2001/XMLSchema#integer</code> + * @return The created Literal + * @throws IllegalArgumentException If any of the provided arguments are not acceptable, e.g. + * because the provided dataType is not permitted. + * @throws UnsupportedOperationException If the operation is not supported. + */ + default Literal createLiteral(String lexicalForm, IRI dataType) + throws IllegalArgumentException, UnsupportedOperationException { + throw new UnsupportedOperationException( + "createLiteral(String) not supported"); + } - /** - * Create a language-tagged literal. - * <p> - * The provided lexical form should not be escaped in any sense, e.g. should - * not include "quotes" unless those are part of the literal value. - * <p> - * The provided language tag MUST be valid according to <a - * href="http://tools.ietf.org/html/bcp47">BCP47</a>, e.g. <code>en</code>. - * <p> - * The provided language tag <a - * href="http://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string" - * >MAY be converted to lower case</a>. - * <p> - * The returned Literal SHOULD have a {@link Literal#getLexicalForm()} which - * is equal to the provided lexicalForm, MUST return a - * {@link Literal#getDatatype()} that is equal to the IRI - * <code>http://www.w3.org/1999/02/22-rdf-syntax-ns#langString</code>, and - * MUST have a {@link Literal#getLanguageTag()} present which SHOULD be - * equal to the provided language tag (compared as - * {@link String#toLowerCase(Locale)} using {@link Locale#ENGLISH}). - * - * @param lexicalForm - * The literal value - * @param languageTag - * The non-empty language tag as defined by <a - * href="http://tools.ietf.org/html/bcp47">BCP47</a> - * @return The created Literal - * @throws IllegalArgumentException - * If the provided values are not acceptable, e.g. because the - * languageTag was syntactically invalid. - * @throws UnsupportedOperationException - * If the operation is not supported. - */ - default Literal createLiteral(String lexicalForm, String languageTag) - throws IllegalArgumentException, UnsupportedOperationException { - throw new UnsupportedOperationException( - "createLiteral(String,String) not supported"); - } + /** + * Create a language-tagged literal. + * + * The provided lexical form should not be escaped in any sense, e.g. should + * not include "quotes" unless those are part of the literal value. + * + * The provided language tag MUST be valid according to <a + * href="http://tools.ietf.org/html/bcp47">BCP47</a>, e.g. <code>en</code>. + * + * The provided language tag <a + * href="http://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string" + * >MAY be converted to lower case</a>. + * + * The returned Literal SHOULD have a {@link Literal#getLexicalForm()} which + * is equal to the provided lexicalForm, MUST return a + * {@link Literal#getDatatype()} that is equal to the IRI + * <code>http://www.w3.org/1999/02/22-rdf-syntax-ns#langString</code>, and + * MUST have a {@link Literal#getLanguageTag()} present which SHOULD be + * equal to the provided language tag (compared as + * {@link String#toLowerCase(Locale)} using {@link Locale#ENGLISH}). + * + * @param lexicalForm The literal value + * @param languageTag The non-empty language tag as defined by <a + * href="http://tools.ietf.org/html/bcp47">BCP47</a> + * @return The created Literal + * @throws IllegalArgumentException If the provided values are not acceptable, e.g. because the + * languageTag was syntactically invalid. + * @throws UnsupportedOperationException If the operation is not supported. + */ + default Literal createLiteral(String lexicalForm, String languageTag) + throws IllegalArgumentException, UnsupportedOperationException { + throw new UnsupportedOperationException( + "createLiteral(String,String) not supported"); + } - /** - * Create a triple. - * <p> - * The returned Triple SHOULD have a {@link Triple#getSubject()} that is - * equal to the provided subject, a {@link Triple#getPredicate()} that is - * equal to the provided predicate, and a {@link Triple#getObject()} that is - * equal to the provided object. - * - * @param subject - * The IRI or BlankNode that is the subject of the triple - * @param predicate - * The IRI that is the predicate of the triple - * @param object - * The IRI, BlankNode or Literal that is the object of the triple - * @return The created Triple - * @throws IllegalArgumentException - * If any of the provided arguments are not acceptable, e.g. - * because a Literal has a lexicalForm that is too large for an - * underlying storage. - * @throws UnsupportedOperationException - * If the operation is not supported. - */ - default Triple createTriple(BlankNodeOrIRI subject, IRI predicate, - RDFTerm object) throws IllegalArgumentException, - UnsupportedOperationException { - throw new UnsupportedOperationException( - "createTriple(BlankNodeOrIRI,IRI,RDFTerm) not supported"); - } + /** + * Create a triple. + * + * The returned Triple SHOULD have a {@link Triple#getSubject()} that is + * equal to the provided subject, a {@link Triple#getPredicate()} that is + * equal to the provided predicate, and a {@link Triple#getObject()} that is + * equal to the provided object. + * + * @param subject The IRI or BlankNode that is the subject of the triple + * @param predicate The IRI that is the predicate of the triple + * @param object The IRI, BlankNode or Literal that is the object of the triple + * @return The created Triple + * @throws IllegalArgumentException If any of the provided arguments are not acceptable, e.g. + * because a Literal has a lexicalForm that is too large for an + * underlying storage. + * @throws UnsupportedOperationException If the operation is not supported. + */ + default Triple createTriple(BlankNodeOrIRI subject, IRI predicate, + RDFTerm object) throws IllegalArgumentException, + UnsupportedOperationException { + throw new UnsupportedOperationException( + "createTriple(BlankNodeOrIRI,IRI,RDFTerm) not supported"); + } } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5ee4c293/api/src/main/java/org/apache/commons/rdf/api/Triple.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/commons/rdf/api/Triple.java b/api/src/main/java/org/apache/commons/rdf/api/Triple.java index e1dbfda..f7dcd39 100644 --- a/api/src/main/java/org/apache/commons/rdf/api/Triple.java +++ b/api/src/main/java/org/apache/commons/rdf/api/Triple.java @@ -24,78 +24,75 @@ package org.apache.commons.rdf.api; * 25 February 2014.<br> * * @see <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple" >RDF-1.1 - * Triple</a> + * Triple</a> */ public interface Triple { - /** - * The subject of this triple, which may be either a {@link BlankNode} or an - * {@link IRI}, which are represented in Commons RDF by the interface - * {@link BlankNodeOrIRI}. - * - * @return The subject {@link BlankNodeOrIRI} of this triple. - * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-subject">RDF-1.1 - * Triple subject</a> - */ - BlankNodeOrIRI getSubject(); + /** + * The subject of this triple, which may be either a {@link BlankNode} or an + * {@link IRI}, which are represented in Commons RDF by the interface + * {@link BlankNodeOrIRI}. + * + * @return The subject {@link BlankNodeOrIRI} of this triple. + * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-subject">RDF-1.1 + * Triple subject</a> + */ + BlankNodeOrIRI getSubject(); - /** - * The predicate {@link IRI} of this triple. - * - * @return The predicate {@link IRI} of this triple. - * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-predicate">RDF-1.1 - * Triple predicate</a> - */ - IRI getPredicate(); + /** + * The predicate {@link IRI} of this triple. + * + * @return The predicate {@link IRI} of this triple. + * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-predicate">RDF-1.1 + * Triple predicate</a> + */ + IRI getPredicate(); - /** - * The object of this triple, which may be either a {@link BlankNode}, an - * {@link IRI}, or a {@link Literal}, which are represented in Commons RDF - * by the interface {@link RDFTerm}. - * - * @return The object {@link RDFTerm} of this triple. - * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-object">RDF-1.1 - * Triple object</a> - */ - RDFTerm getObject(); + /** + * The object of this triple, which may be either a {@link BlankNode}, an + * {@link IRI}, or a {@link Literal}, which are represented in Commons RDF + * by the interface {@link RDFTerm}. + * + * @return The object {@link RDFTerm} of this triple. + * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-object">RDF-1.1 + * Triple object</a> + */ + RDFTerm getObject(); - /** - * Check it this Triple is equal to another Triple. - * <p> - * Two Triples are equal if and only if their {@link #getSubject()}, - * {@link #getPredicate()} and {@link #getObject()} are equal. - * </p> - * <p> - * Implementations MUST check the local scope for Triple comparison if - * either the subject or object is a BlankNode, and MAY check the local - * scope in other cases. - * </p> - * <p> - * Implementations MUST also override {@link #hashCode()} so that two equal - * Triples produce the same hash code. - * </p> - * - * @see Object#equals(Object) - * - * @param other - * Another object - * @return true if other is a Triple and is equal to this - */ - @Override - public boolean equals(Object other); + /** + * Check it this Triple is equal to another Triple. + * <p> + * Two Triples are equal if and only if their {@link #getSubject()}, + * {@link #getPredicate()} and {@link #getObject()} are equal. + * </p> + * <p> + * Implementations MUST check the local scope for Triple comparison if + * either the subject or object is a BlankNode, and MAY check the local + * scope in other cases. + * </p> + * <p> + * Implementations MUST also override {@link #hashCode()} so that two equal + * Triples produce the same hash code. + * </p> + * + * @param other Another object + * @return true if other is a Triple and is equal to this + * @see Object#equals(Object) + */ + @Override + public boolean equals(Object other); - /** - * Calculate a hash code for this Triple. - * <p> - * This method MUST be implemented when implementing {@link #equals(Object)} - * so that two equal IRIs produce the same hash code. - * </p> - * - * @see Object#hashCode() - * - * @return a hash code value for this Triple. - */ - @Override - public int hashCode(); + /** + * Calculate a hash code for this Triple. + * <p> + * This method MUST be implemented when implementing {@link #equals(Object)} + * so that two equal IRIs produce the same hash code. + * </p> + * + * @return a hash code value for this Triple. + * @see Object#hashCode() + */ + @Override + public int hashCode(); } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5ee4c293/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 38951cd..07de1fd 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 @@ -17,209 +17,208 @@ */ package org.apache.commons.rdf.api; -import static org.junit.Assert.*; - import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + /** * Abstract test class for the BlankNode interface. - * */ public abstract class AbstractBlankNodeTest { - protected abstract BlankNode getBlankNode(); - - /** - * Gets a new blank node object based on the given identifier. - * <p> - * Subsequent calls to this method during a single test with the same - * identifier must return BlankNode objects that are equals and have the - * same hashCode. The objects returned from successive calls during a single - * test may be the same object, or they may be different objects. - * </p> - * - * @param identifier - * The identifier to use as the reference for creating the blank - * node that is returned. - * @return A new blank node based on the - */ - protected abstract BlankNode getBlankNode(String identifier); - - /** - * Test method for - * {@link BlankNode#internalIdentifier()}. - */ - @Test - public final void testInternalIdentifier() { - BlankNode testNull = new BlankNode() { - @Override - public String ntriplesString() { - return null; - } - - @Override - public String internalIdentifier() { - return null; - } - }; - BlankNode testAutomatic1 = getBlankNode(); - BlankNode testAutomatic2 = getBlankNode(); - BlankNode testManual3a = getBlankNode("3"); - BlankNode testManual3b = getBlankNode("3"); - 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()); - - // 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()); - } - - /** - * Test method for - * {@link BlankNode#equals(java.lang.Object)}. - */ - @Test - public final void testEquals() { - BlankNode testNull = new BlankNode() { - @Override - public String ntriplesString() { - return null; - } - - @Override - public String internalIdentifier() { - return null; - } - }; - BlankNode testAutomatic1 = getBlankNode(); - BlankNode testAutomatic2 = getBlankNode(); - BlankNode testManual3a = getBlankNode("3"); - BlankNode testManual3b = getBlankNode("3"); - BlankNode testManual4 = getBlankNode("4"); - - // Test against our fake stub - assertNotEquals(testNull, testAutomatic1); - assertNotEquals(testAutomatic1, testNull); - assertNotEquals(testNull, testManual3a); - assertNotEquals(testManual3a, testNull); - - // Test the two imported instances against each other - assertEquals(testAutomatic1, testAutomatic1); - assertEquals(testAutomatic2, testAutomatic2); - assertNotEquals(testAutomatic1, testAutomatic2); - assertNotEquals(testAutomatic2, testAutomatic1); - assertNotEquals(testAutomatic1, testManual3a); - assertEquals(testManual3b, testManual3a); - assertNotEquals(testManual3a, testManual4); - } - - /** - * Test method for {@link BlankNode#hashCode()}. - */ - @Test - public final void testHashCode() { - BlankNode testNull = new BlankNode() { - @Override - public String ntriplesString() { - return null; - } - - @Override - public String internalIdentifier() { - return null; - } - }; - BlankNode testAutomatic1 = getBlankNode(); - BlankNode testAutomatic2 = getBlankNode(); - BlankNode testManual3a = getBlankNode("3"); - BlankNode testManual3b = getBlankNode("3"); - BlankNode testManual4 = getBlankNode("4"); - - // Test against our fake stub - assertNotEquals(testNull.hashCode(), testAutomatic1.hashCode()); - assertNotEquals(testAutomatic1.hashCode(), testNull.hashCode()); - assertNotEquals(testNull.hashCode(), testManual3a.hashCode()); - assertNotEquals(testManual3a.hashCode(), testNull.hashCode()); - - // Test the two imported instances against each other - assertEquals(testAutomatic1.hashCode(), testAutomatic1.hashCode()); - assertEquals(testAutomatic2.hashCode(), testAutomatic2.hashCode()); - assertNotEquals(testAutomatic1.hashCode(), testAutomatic2.hashCode()); - assertNotEquals(testAutomatic2.hashCode(), testAutomatic1.hashCode()); - assertNotEquals(testAutomatic1.hashCode(), testManual3a.hashCode()); - assertEquals(testManual3b.hashCode(), testManual3a.hashCode()); - assertNotEquals(testManual3a.hashCode(), testManual4.hashCode()); - } - - /** - * Test method for - * {@link RDFTerm#ntriplesString()}. - */ - @Test - public final void testNtriplesString() { - BlankNode testNull = new BlankNode() { - @Override - public String ntriplesString() { - return null; - } - - @Override - public String internalIdentifier() { - return null; - } - }; - BlankNode testAutomatic1 = getBlankNode(); - BlankNode testAutomatic2 = getBlankNode(); - BlankNode testManual3a = getBlankNode("3"); - BlankNode testManual3b = getBlankNode("3"); - BlankNode testManual4 = getBlankNode("4"); - - // Test against our fake stub - assertNotEquals(testNull.ntriplesString(), - testAutomatic1.ntriplesString()); - assertNotEquals(testAutomatic1.ntriplesString(), - testNull.ntriplesString()); - assertNotEquals(testNull.ntriplesString(), - testManual3a.ntriplesString()); - assertNotEquals(testManual3a.ntriplesString(), - testNull.ntriplesString()); - - // Test the two imported instances against each other - assertEquals(testAutomatic1.ntriplesString(), - testAutomatic1.ntriplesString()); - assertEquals(testAutomatic2.ntriplesString(), - testAutomatic2.ntriplesString()); - assertNotEquals(testAutomatic1.ntriplesString(), - testAutomatic2.ntriplesString()); - assertNotEquals(testAutomatic2.ntriplesString(), - testAutomatic1.ntriplesString()); - assertNotEquals(testAutomatic1.ntriplesString(), - testManual3a.ntriplesString()); - assertEquals(testManual3b.ntriplesString(), - testManual3a.ntriplesString()); - assertNotEquals(testManual3a.ntriplesString(), - testManual4.ntriplesString()); - } + protected abstract BlankNode getBlankNode(); + + /** + * Gets a new blank node object based on the given identifier. + * <p> + * Subsequent calls to this method during a single test with the same + * identifier must return BlankNode objects that are equals and have the + * same hashCode. The objects returned from successive calls during a single + * test may be the same object, or they may be different objects. + * </p> + * + * @param identifier The identifier to use as the reference for creating the blank + * node that is returned. + * @return A new blank node based on the + */ + protected abstract BlankNode getBlankNode(String identifier); + + /** + * Test method for + * {@link BlankNode#internalIdentifier()}. + */ + @Test + public final void testInternalIdentifier() { + BlankNode testNull = new BlankNode() { + @Override + public String ntriplesString() { + return null; + } + + @Override + public String internalIdentifier() { + return null; + } + }; + BlankNode testAutomatic1 = getBlankNode(); + BlankNode testAutomatic2 = getBlankNode(); + BlankNode testManual3a = getBlankNode("3"); + BlankNode testManual3b = getBlankNode("3"); + 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()); + + // 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()); + } + + /** + * Test method for + * {@link BlankNode#equals(java.lang.Object)}. + */ + @Test + public final void testEquals() { + BlankNode testNull = new BlankNode() { + @Override + public String ntriplesString() { + return null; + } + + @Override + public String internalIdentifier() { + return null; + } + }; + BlankNode testAutomatic1 = getBlankNode(); + BlankNode testAutomatic2 = getBlankNode(); + BlankNode testManual3a = getBlankNode("3"); + BlankNode testManual3b = getBlankNode("3"); + BlankNode testManual4 = getBlankNode("4"); + + // Test against our fake stub + assertNotEquals(testNull, testAutomatic1); + assertNotEquals(testAutomatic1, testNull); + assertNotEquals(testNull, testManual3a); + assertNotEquals(testManual3a, testNull); + + // Test the two imported instances against each other + assertEquals(testAutomatic1, testAutomatic1); + assertEquals(testAutomatic2, testAutomatic2); + assertNotEquals(testAutomatic1, testAutomatic2); + assertNotEquals(testAutomatic2, testAutomatic1); + assertNotEquals(testAutomatic1, testManual3a); + assertEquals(testManual3b, testManual3a); + assertNotEquals(testManual3a, testManual4); + } + + /** + * Test method for {@link BlankNode#hashCode()}. + */ + @Test + public final void testHashCode() { + BlankNode testNull = new BlankNode() { + @Override + public String ntriplesString() { + return null; + } + + @Override + public String internalIdentifier() { + return null; + } + }; + BlankNode testAutomatic1 = getBlankNode(); + BlankNode testAutomatic2 = getBlankNode(); + BlankNode testManual3a = getBlankNode("3"); + BlankNode testManual3b = getBlankNode("3"); + BlankNode testManual4 = getBlankNode("4"); + + // Test against our fake stub + assertNotEquals(testNull.hashCode(), testAutomatic1.hashCode()); + assertNotEquals(testAutomatic1.hashCode(), testNull.hashCode()); + assertNotEquals(testNull.hashCode(), testManual3a.hashCode()); + assertNotEquals(testManual3a.hashCode(), testNull.hashCode()); + + // Test the two imported instances against each other + assertEquals(testAutomatic1.hashCode(), testAutomatic1.hashCode()); + assertEquals(testAutomatic2.hashCode(), testAutomatic2.hashCode()); + assertNotEquals(testAutomatic1.hashCode(), testAutomatic2.hashCode()); + assertNotEquals(testAutomatic2.hashCode(), testAutomatic1.hashCode()); + assertNotEquals(testAutomatic1.hashCode(), testManual3a.hashCode()); + assertEquals(testManual3b.hashCode(), testManual3a.hashCode()); + assertNotEquals(testManual3a.hashCode(), testManual4.hashCode()); + } + + /** + * Test method for + * {@link RDFTerm#ntriplesString()}. + */ + @Test + public final void testNtriplesString() { + BlankNode testNull = new BlankNode() { + @Override + public String ntriplesString() { + return null; + } + + @Override + public String internalIdentifier() { + return null; + } + }; + BlankNode testAutomatic1 = getBlankNode(); + BlankNode testAutomatic2 = getBlankNode(); + BlankNode testManual3a = getBlankNode("3"); + BlankNode testManual3b = getBlankNode("3"); + BlankNode testManual4 = getBlankNode("4"); + + // Test against our fake stub + assertNotEquals(testNull.ntriplesString(), + testAutomatic1.ntriplesString()); + assertNotEquals(testAutomatic1.ntriplesString(), + testNull.ntriplesString()); + assertNotEquals(testNull.ntriplesString(), + testManual3a.ntriplesString()); + assertNotEquals(testManual3a.ntriplesString(), + testNull.ntriplesString()); + + // Test the two imported instances against each other + assertEquals(testAutomatic1.ntriplesString(), + testAutomatic1.ntriplesString()); + assertEquals(testAutomatic2.ntriplesString(), + testAutomatic2.ntriplesString()); + assertNotEquals(testAutomatic1.ntriplesString(), + testAutomatic2.ntriplesString()); + assertNotEquals(testAutomatic2.ntriplesString(), + testAutomatic1.ntriplesString()); + assertNotEquals(testAutomatic1.ntriplesString(), + testManual3a.ntriplesString()); + assertEquals(testManual3b.ntriplesString(), + testManual3a.ntriplesString()); + assertNotEquals(testManual3a.ntriplesString(), + testManual4.ntriplesString()); + } }