public interface Quad extends QuadLike<BlankNodeOrIRI>
A Quad
object in Commons RDF is considered
immutable, that is, over its life time it will have
consistent behaviour for its equals(Object)
, and the instances
returned from getGraphName()
, getSubject()
,
getPredicate()
, getObject()
and asTriple()
will
have consistent Object.equals(Object)
behaviour.
Note that Quad
methods are not required to return object
identical (==
) instances as long as they are equivalent
according to Object.equals(Object)
. Specialisations of
Quad
may provide additional methods that are documented to be
mutable.
Quad
methods are thread-safe, however
specialisations may provide additional methods that are documented to not be
thread-safe.
Quad
s can be safely used in hashing collections like
HashSet
and HashMap
.
Any Quad
can be used interchangeably across Commons RDF
implementations.
Dataset
,
RDF.createQuad(BlankNodeOrIRI,BlankNodeOrIRI,IRI,RDFTerm)
,
RDF
1.1: On Semantics of RDF Datasets,
Modifier and Type | Method and Description |
---|---|
default Triple |
asTriple()
Adapt this Quad to a Triple.
|
boolean |
equals(Object other)
Check it this Quad is equal to another Quad.
|
Optional<BlankNodeOrIRI> |
getGraphName()
The graph name (graph label) of this quad, if present.
|
RDFTerm |
getObject()
|
IRI |
getPredicate()
The predicate
IRI of this quad. |
BlankNodeOrIRI |
getSubject()
The subject of this quad, which may be either a
BlankNode or an
IRI , which are represented in Commons RDF by the interface
BlankNodeOrIRI . |
int |
hashCode()
Calculate a hash code for this Quad.
|
Optional<BlankNodeOrIRI> getGraphName()
Optional.isPresent()
, then the Optional.get()
is
either a BlankNode
or an IRI
, indicating the
graph
name of this Quad. If the graph name is not present, e.g. the value
is Optional.empty()
, it indicates that this Quad is in the
default
graph.getGraphName
in interface QuadLike<BlankNodeOrIRI>
Optional.isPresent()
, the graph name
BlankNodeOrIRI
of this quad, otherwise
Optional.empty()
, indicating the default graph.BlankNodeOrIRI getSubject()
BlankNode
or an
IRI
, which are represented in Commons RDF by the interface
BlankNodeOrIRI
.getSubject
in interface TripleLike
BlankNodeOrIRI
of this quad.IRI getPredicate()
IRI
of this quad.getPredicate
in interface TripleLike
IRI
of this quad.RDFTerm getObject()
BlankNode
, an
IRI
, or a Literal
, which are represented in Commons RDF
by the interface RDFTerm
.getObject
in interface TripleLike
RDFTerm
of this quad.default Triple asTriple()
The returned Triple
will have equivalent values returned from the
methods TripleLike.getSubject()
,
TripleLike.getPredicate()
and TripleLike.getObject()
.
The returned Triple
MUST NOT be equals(Object)
to this
Quad
, even if this quad has a default graph
getGraphName()
value of Optional.empty()
, but MUST
follow the Triple.equals(Object)
semantics. This means that the
following MUST be true:
Quad q1, q2; if (q1.equals(q2)) { assert (q1.asTriple().equals(q2.asTriple())); } else if (q1.asTriple().equals(q2.asTriple())) { assert (q1.getSubject().equals(q2.getSubject())); assert (q1.getPredicate().equals(q2.getPredicate())); assert (q1.getObject().equals(q2.getObject())); assert (!q1.getGraphName().equals(q2.getGraphName())); }The
default
implementation of this method return a proxy
Triple
instance that keeps a reference to this Quad
to
call the underlying TripleLike
methods, but supplies a
Triple
compatible implementation of Triple.equals(Object)
and Triple.hashCode()
. Implementations may override this method,
e.g. for a more efficient solution.Triple
that contains the same TripleLike
properties as this Quad.boolean equals(Object other)
Two Quads are equal if and only if their getGraphName()
,
getSubject()
, getPredicate()
and getObject()
are equal.
Implementations MUST also override hashCode()
so that two equal
Quads produce the same hash code.
Note that a Quad
MUST NOT be equal to a Triple
, even if
this Quad's getGraphName()
is Optional.empty()
. To test
triple-like equivalence, callers can use:
Quad q1; Triple t2; q1.asTriple().equals(t2));
equals
in class Object
other
- Another objectObject.equals(Object)
int hashCode()
The returned hash code MUST be equal to the result of
Objects.hash(Object...)
with the arguments getSubject()
,
getPredicate()
, getObject()
, getGraphName()
.
This method MUST be implemented in conjunction with
equals(Object)
so that two equal Quad
s produce the same
hash code.
hashCode
in class Object
Object.hashCode()
,
Objects.hash(Object...)
Copyright © 2015–2018 The Apache Software Foundation. All rights reserved.