001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.commons.rdf.api;
019
020import java.util.Objects;
021
022/**
023 * An <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple" >RDF-1.1
024 * Triple</a>, as defined by
025 * <a href= "http://www.w3.org/TR/rdf11-concepts/#section-triples" >RDF-1.1 Concepts and
026 * Abstract Syntax</a>, a W3C Recommendation published on 25 February 2014.
027 * <p>
028 * A <code>Triple</code> object in Commons RDF is considered
029 * <strong>immutable</strong>, that is, over its life time it will have
030 * consistent behaviour for its {@link #equals(Object)}, and the {@link RDFTerm}
031 * instances returned from {@link #getSubject()}, {@link #getPredicate()} and
032 * {@link #getObject()} will have consistent {@link RDFTerm#equals(Object)}
033 * behaviour.
034 * <p>
035 * Note that <code>Triple</code> methods are not required to return object
036 * identical (<code>==</code>) instances as long as they are equivalent
037 * according to {@link RDFTerm#equals(Object)}. Specialisations of
038 * <code>Triple</code> may provide additional methods that are documented to be
039 * mutable.
040 * <p>
041 * <code>Triple</code> methods are <strong>thread-safe</strong>, however
042 * specialisations may provide additional methods that are documented to not be
043 * thread-safe.
044 * <p>
045 * <code>Triple</code>s can be safely used in hashing collections like
046 * {@link java.util.HashSet} and {@link java.util.HashMap}.
047 * <p>
048 * Any <code>Triple</code> can be used interchangeably across Commons RDF
049 * implementations.
050 *
051 * @see Quad
052 * @see RDF#createTriple(BlankNodeOrIRI,IRI,RDFTerm)
053 * @see <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple" >RDF-1.1
054 *      Triple</a>
055 */
056public interface Triple extends TripleLike {
057
058    /**
059     * The subject of this triple, which may be either a {@link BlankNode} or an
060     * {@link IRI}, which are represented in Commons RDF by the interface
061     * {@link BlankNodeOrIRI}.
062     *
063     * @return The subject {@link BlankNodeOrIRI} of this triple.
064     * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-subject">RDF-1.1
065     *      Triple subject</a>
066     */
067    @Override
068    BlankNodeOrIRI getSubject();
069
070    /**
071     * The predicate {@link IRI} of this triple.
072     *
073     * @return The predicate {@link IRI} of this triple.
074     * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-predicate">RDF-1.1
075     *      Triple predicate</a>
076     */
077    @Override
078    IRI getPredicate();
079
080    /**
081     * The object of this triple, which may be either a {@link BlankNode}, an
082     * {@link IRI}, or a {@link Literal}, which are represented in Commons RDF
083     * by the interface {@link RDFTerm}.
084     *
085     * @return The object {@link RDFTerm} of this triple.
086     * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-object">RDF-1.1
087     *      Triple object</a>
088     */
089    @Override
090    RDFTerm getObject();
091
092    /**
093     * Check it this Triple is equal to another Triple.
094     * <p>
095     * Two Triples are equal if and only if their {@link #getSubject()},
096     * {@link #getPredicate()} and {@link #getObject()} are equal.
097     * </p>
098     * <p>
099     * 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    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    int hashCode();
128
129}