Class QuadImpl
- java.lang.Object
-
- org.apache.commons.rdf.simple.QuadImpl
-
- All Implemented Interfaces:
Quad
,QuadLike<BlankNodeOrIRI>
,TripleLike
final class QuadImpl extends java.lang.Object implements Quad
A simple implementation of Quad.
-
-
Field Summary
Fields Modifier and Type Field Description private BlankNodeOrIRI
graphName
private RDFTerm
object
private IRI
predicate
private BlankNodeOrIRI
subject
-
Constructor Summary
Constructors Constructor Description QuadImpl(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
Construct Quad from its constituent parts.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Triple
asTriple()
Adapt this Quad to a Triple.boolean
equals(java.lang.Object obj)
Check it this Quad is equal to another Quad.java.util.Optional<BlankNodeOrIRI>
getGraphName()
The graph name (graph label) of this quad, if present.RDFTerm
getObject()
IRI
getPredicate()
The predicateIRI
of this quad.BlankNodeOrIRI
getSubject()
The subject of this quad, which may be either aBlankNode
or anIRI
, which are represented in Commons RDF by the interfaceBlankNodeOrIRI
.int
hashCode()
Calculate a hash code for this Quad.java.lang.String
toString()
-
-
-
Field Detail
-
graphName
private final BlankNodeOrIRI graphName
-
subject
private final BlankNodeOrIRI subject
-
predicate
private final IRI predicate
-
object
private final RDFTerm object
-
-
Constructor Detail
-
QuadImpl
public QuadImpl(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
Construct Quad from its constituent parts.The objects are not changed. All mapping of BNode objects is done in
SimpleRDF.createQuad(BlankNodeOrIRI, BlankNodeOrIRI, IRI, RDFTerm)
.- Parameters:
graphName
- graphName of triplesubject
- subject of triplepredicate
- predicate of tripleobject
- object of triple
-
-
Method Detail
-
getGraphName
public java.util.Optional<BlankNodeOrIRI> getGraphName()
Description copied from interface:Quad
The graph name (graph label) of this quad, if present. IfOptional.isPresent()
, then theOptional.get()
is either aBlankNode
or anIRI
, indicating the graph name of this Quad. If the graph name is not present, e.g. the value isOptional.empty()
, it indicates that this Quad is in the default graph.- Specified by:
getGraphName
in interfaceQuad
- Specified by:
getGraphName
in interfaceQuadLike<BlankNodeOrIRI>
- Returns:
- If
Optional.isPresent()
, the graph nameBlankNodeOrIRI
of this quad, otherwiseOptional.empty()
, indicating the default graph. - See Also:
- RDF- 1.1 Dataset
-
getSubject
public BlankNodeOrIRI getSubject()
Description copied from interface:Quad
The subject of this quad, which may be either aBlankNode
or anIRI
, which are represented in Commons RDF by the interfaceBlankNodeOrIRI
.- Specified by:
getSubject
in interfaceQuad
- Specified by:
getSubject
in interfaceTripleLike
- Returns:
- The subject
BlankNodeOrIRI
of this quad. - See Also:
- RDF-1.1 Triple subject
-
getPredicate
public IRI getPredicate()
Description copied from interface:Quad
The predicateIRI
of this quad.- Specified by:
getPredicate
in interfaceQuad
- Specified by:
getPredicate
in interfaceTripleLike
- Returns:
- The predicate
IRI
of this quad. - See Also:
- RDF-1.1 Triple predicate
-
getObject
public RDFTerm getObject()
Description copied from interface:Quad
The object of this quad, which may be either aBlankNode
, anIRI
, or aLiteral
, which are represented in Commons RDF by the interfaceRDFTerm
.- Specified by:
getObject
in interfaceQuad
- Specified by:
getObject
in interfaceTripleLike
- Returns:
- The object
RDFTerm
of this quad. - See Also:
- RDF-1.1 Triple object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hashCode
public int hashCode()
Description copied from interface:Quad
Calculate a hash code for this Quad.The returned hash code MUST be equal to the result of
Objects.hash(Object...)
with the argumentsQuad.getSubject()
,Quad.getPredicate()
,Quad.getObject()
,Quad.getGraphName()
.This method MUST be implemented in conjunction with
Quad.equals(Object)
so that two equalQuad
s produce the same hash code.
-
equals
public boolean equals(java.lang.Object obj)
Description copied from interface:Quad
Check it this Quad is equal to another Quad.Two Quads are equal if and only if their
Quad.getGraphName()
,Quad.getSubject()
,Quad.getPredicate()
andQuad.getObject()
are equal.Implementations MUST also override
Quad.hashCode()
so that two equal Quads produce the same hash code.Note that a
Quad
MUST NOT be equal to aTriple
, even if this Quad'sQuad.getGraphName()
isOptional.empty()
. To test triple-like equivalence, callers can use:Quad q1; Triple t2; q1.asTriple().equals(t2));
-
asTriple
public Triple asTriple()
Description copied from interface:Quad
Adapt this Quad to a Triple.The returned
Triple
will have equivalent values returned from the methodsTripleLike.getSubject()
,TripleLike.getPredicate()
andTripleLike.getObject()
.The returned
Triple
MUST NOT beQuad.equals(Object)
to thisQuad
, even if this quad has a default graphQuad.getGraphName()
value ofOptional.empty()
, but MUST follow theTriple.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())); }
Thedefault
implementation of this method return a proxyTriple
instance that keeps a reference to thisQuad
to call the underlyingTripleLike
methods, but supplies aTriple
compatible implementation ofTriple.equals(Object)
andTriple.hashCode()
. Implementations may override this method, e.g. for a more efficient solution.- Specified by:
asTriple
in interfaceQuad
- Returns:
- A
Triple
that contains the sameTripleLike
properties as this Quad.
-
-