View Javadoc
1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.commons.rdf.api;
19  
20  import java.util.Objects;
21  
22  /**
23   * An <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple" >RDF-1.1
24   * Triple</a>, as defined by
25   * <a href= "http://www.w3.org/TR/rdf11-concepts/" >RDF-1.1 Concepts and
26   * Abstract Syntax</a>, a W3C Recommendation published on 25 February 2014.
27   * <p>
28   * A <code>Triple</code> object in Commons RDF is considered
29   * <strong>immutable</strong>, that is, over its life time it will have
30   * consistent behaviour for its {@link #equals(Object)}, and the {@link RDFTerm}
31   * instances returned from {@link #getSubject()}, {@link #getPredicate()} and
32   * {@link #getObject()} will have consistent {@link RDFTerm#equals(Object)}
33   * behaviour.
34   * <p>
35   * Note that <code>Triple</code> methods are not required to return object
36   * identical (<code>==</code>) instances as long as they are equivalent
37   * according to {@link RDFTerm#equals(Object)}. Specialisations of
38   * <code>Triple</code> may provide additional methods that are documented to be
39   * mutable.
40   * <p>
41   * <code>Triple</code> methods are <strong>thread-safe</strong>, however
42   * specialisations may provide additional methods that are documented to not be
43   * thread-safe.
44   * <p>
45   * <code>Triple</code>s can be safely used in hashing collections like
46   * {@link java.util.HashSet} and {@link java.util.HashMap}.
47   * <p>
48   * Any <code>Triple</code> can be used interchangeably across Commons RDF
49   * implementations.
50   *
51   * @see Quad
52   * @see RDF#createTriple(BlankNodeOrIRI,IRI,RDFTerm)
53   * @see <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple" >RDF-1.1
54   *      Triple</a>
55   */
56  public interface Triple extends TripleLike {
57  
58      /**
59       * The subject of this triple, which may be either a {@link BlankNode} or an
60       * {@link IRI}, which are represented in Commons RDF by the interface
61       * {@link BlankNodeOrIRI}.
62       *
63       * @return The subject {@link BlankNodeOrIRI} of this triple.
64       * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-subject">RDF-1.1
65       *      Triple subject</a>
66       */
67      @Override
68      BlankNodeOrIRI getSubject();
69  
70      /**
71       * The predicate {@link IRI} of this triple.
72       *
73       * @return The predicate {@link IRI} of this triple.
74       * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-predicate">RDF-1.1
75       *      Triple predicate</a>
76       */
77      @Override
78      IRI getPredicate();
79  
80      /**
81       * The object of this triple, which may be either a {@link BlankNode}, an
82       * {@link IRI}, or a {@link Literal}, which are represented in Commons RDF
83       * by the interface {@link RDFTerm}.
84       *
85       * @return The object {@link RDFTerm} of this triple.
86       * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-object">RDF-1.1
87       *      Triple object</a>
88       */
89      @Override
90      RDFTerm getObject();
91  
92      /**
93       * Check it this Triple is equal to another Triple.
94       * <p>
95       * Two Triples are equal if and only if their {@link #getSubject()},
96       * {@link #getPredicate()} and {@link #getObject()} are equal.
97       * </p>
98       * <p>
99       * Implementations MUST also override {@link #hashCode()} so that two equal
100      * Triples produce the same hash code.
101      * </p>
102      *
103      * @param other
104      *            Another object
105      * @return true if other is a Triple and is equal to this
106      * @see Object#equals(Object)
107      */
108     @Override
109     public boolean equals(Object other);
110 
111     /**
112      * Calculate a hash code for this Triple.
113      * <p>
114      * The returned hash code MUST be equal to the result of
115      * {@link Objects#hash(Object...)} with the arguments {@link #getSubject()},
116      * {@link #getPredicate()}, {@link #getObject()}.
117      * <p>
118      * This method MUST be implemented in conjunction with
119      * {@link #equals(Object)} so that two equal {@link Triple}s produce the
120      * same hash code.
121      *
122      * @return a hash code value for this Triple.
123      * @see Object#hashCode()
124      * @see Objects#hash(Object...)
125      */
126     @Override
127     public int hashCode();
128 
129 }