Module org.apache.jena.ontapi
Class OntListImpl<E extends org.apache.jena.rdf.model.RDFNode>
java.lang.Object
org.apache.jena.enhanced.Polymorphic<org.apache.jena.rdf.model.RDFNode>
org.apache.jena.enhanced.EnhNode
org.apache.jena.rdf.model.impl.ResourceImpl
org.apache.jena.ontapi.impl.objects.OntListImpl<E>
- All Implemented Interfaces:
org.apache.jena.graph.FrontsNode
,OntList<E>
,RDFNodeList<E>
,org.apache.jena.rdf.model.RDFNode
,org.apache.jena.rdf.model.Resource
public abstract class OntListImpl<E extends org.apache.jena.rdf.model.RDFNode>
extends org.apache.jena.rdf.model.impl.ResourceImpl
implements OntList<E>
Default OntList implementation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
The simplestiterator
over ardf:List
, whoseIterator.next()
method returns a batch oftriple
s in the form of standardJava List
.static class
An extendedOntListImpl.RDFListIterator
whoseIterator.next()
method does not throwNoSuchElementException
in case no element found, but returnsnull
instead. -
Field Summary
Fields inherited from class org.apache.jena.rdf.model.impl.ResourceImpl
factory, rdfNodeFactory
-
Method Summary
Modifier and TypeMethodDescriptionInserts the specified element at the beginning of this list.Adds the given value to the end of the list.<T extends org.apache.jena.rdf.model.RDFNode>
Torg.apache.jena.graph.Node
asNode()
static <N extends org.apache.jena.rdf.model.RDFNode>
OntListImpl<N>asOntList
(org.apache.jena.rdf.model.RDFList list, OntGraphModelImpl model, OntObject subject, org.apache.jena.rdf.model.Property predicate, org.apache.jena.rdf.model.Resource listType, Class<N> elementType) Wraps the existingRDFList
asOntList
.static <N extends org.apache.jena.rdf.model.RDFNode>
OntListImpl<N>asSafeOntList
(org.apache.jena.rdf.model.RDFList list, OntGraphModelImpl model, OntObject subject, org.apache.jena.rdf.model.Property predicate, org.apache.jena.rdf.model.Resource listType, Class<N> elementType) Wraps the existingRDFList
asOntList
.<X extends org.apache.jena.rdf.model.RDFNode>
booleanabstract E
cast
(org.apache.jena.rdf.model.RDFNode n) Makes anE
-resource from the givenRDF-Node
.static void
checkRequiredInputs
(OntObject s, org.apache.jena.rdf.model.Property p, org.apache.jena.rdf.model.RDFNode o, org.apache.jena.rdf.model.Resource listType, Class<?> elementType) static void
checkRequiredInputs
(OntObject s, org.apache.jena.rdf.model.Property p, org.apache.jena.rdf.model.Resource listType, Class<?> elementType) clear()
Removes all elements from this list.boolean
Answerstrue
if the []-list contains the specifiedelement
.content()
Returns the root statement plus spec.static <N extends org.apache.jena.rdf.model.RDFNode>
OntListImpl<N>create
(OntGraphModelImpl model, OntObject subject, org.apache.jena.rdf.model.Property predicate, org.apache.jena.rdf.model.Resource listType, Class<N> elementType, org.apache.jena.util.iterator.ExtendedIterator<N> elements) Creates a freshOntList
with the givenelementType
as a type constraint containing all content from the specifiedExtendedIterator
preserving the original order.Answers theIterator
of batches of triples that belong to this ONT-List.static org.apache.jena.rdf.model.RDFList
createTypedList
(org.apache.jena.enhanced.EnhGraph model, org.apache.jena.rdf.model.Resource type, Iterator<? extends org.apache.jena.rdf.model.RDFNode> members) Creates a typed []-list.get
(int index) Answers the list that is the tail of this list starting from the given position.default <X extends org.apache.jena.rdf.model.RDFNode>
XSafely converts this RDF resource to the giventype
interface, if it is possible.org.apache.jena.rdf.model.Statement
Finds the first statement with predicaterdf:rest
from this ONT-List.List<org.apache.jena.rdf.model.Statement>
Finds the first two statements with predicaterdf:rest
from this ONT-List.org.apache.jena.rdf.model.Statement
Finds the last statement with predicaterdf:rest
from this ONT-List.List<org.apache.jena.rdf.model.Statement>
Finds the last two statements with predicaterdf:rest
from this ONT-List.getModel()
boolean
isEmpty()
Answerstrue
if this list contains no elements of the typeE
.boolean
isNil()
Answerstrue
if it is a nil []-list.static boolean
isNil
(org.apache.jena.rdf.model.RDFNode list) Answerstrue
if the givenRDF-Node
is nil []-list.abstract boolean
isValid
(org.apache.jena.rdf.model.RDFNode n) Answerstrue
if the givenRDF-Node
is valid to be a typed element of this list.org.apache.jena.util.iterator.ExtendedIterator<OntStatement>
org.apache.jena.util.iterator.ExtendedIterator<E>
Lists all elements of typeE
from this list.org.apache.jena.util.iterator.ExtendedIterator<OntStatement>
listSpec()
members()
Lists all elements of the typeE
from this list.Removes and the first element from this list.Removes the last element from this list.spec()
Lists all statements related to this list.stream
(OntGraphModelImpl model, OntObject subject, org.apache.jena.rdf.model.Property predicate, Class<N> elementType) Lists all rdf-lists by subject and predicate in the form ofOntList
.Optional<org.apache.jena.rdf.model.Resource>
type()
Answers the resource-type of this ONT-list, if it is typed.Methods inherited from class org.apache.jena.rdf.model.impl.ResourceImpl
abort, addLiteral, addLiteral, addLiteral, addLiteral, addLiteral, addLiteral, addLiteral, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, asLiteral, asResource, begin, commit, getId, getLocalName, getNameSpace, getProperty, getProperty, getPropertyResourceValue, getRequiredProperty, getRequiredProperty, getStmtTerm, getURI, hasLiteral, hasLiteral, hasLiteral, hasLiteral, hasLiteral, hasLiteral, hasProperty, hasProperty, hasProperty, hasProperty, hasURI, inModel, listProperties, listProperties, listProperties, removeAll, removeProperties, toString, visitWith
Methods inherited from class org.apache.jena.enhanced.EnhNode
equals, getGraph, hashCode, isAnon, isLiteral, isResource, isStmtResource, isURIResource, isValid, viewAs
Methods inherited from class org.apache.jena.enhanced.Polymorphic
addView, supports
Methods inherited from interface org.apache.jena.rdf.model.RDFNode
asLiteral, asResource, isAnon, isLiteral, isResource, isStmtResource, isURIResource, visitWith
Methods inherited from interface org.apache.jena.ontapi.model.RDFNodeList
first, last, size
Methods inherited from interface org.apache.jena.rdf.model.Resource
abort, addLiteral, addLiteral, addLiteral, addLiteral, addLiteral, addLiteral, addLiteral, addProperty, addProperty, addProperty, addProperty, begin, commit, equals, getId, getLocalName, getNameSpace, getProperty, getProperty, getPropertyResourceValue, getRequiredProperty, getRequiredProperty, getStmtTerm, getURI, hasLiteral, hasLiteral, hasLiteral, hasLiteral, hasLiteral, hasLiteral, hasProperty, hasProperty, hasProperty, hasProperty, hasURI, inModel, listProperties, listProperties, listProperties, removeAll, removeProperties, toString
-
Method Details
-
create
public static <N extends org.apache.jena.rdf.model.RDFNode> OntListImpl<N> create(OntGraphModelImpl model, OntObject subject, org.apache.jena.rdf.model.Property predicate, org.apache.jena.rdf.model.Resource listType, Class<N> elementType, org.apache.jena.util.iterator.ExtendedIterator<N> elements) Creates a freshOntList
with the givenelementType
as a type constraint containing all content from the specifiedExtendedIterator
preserving the original order. The returned []-list will be attached to the model by the givensubject
andpredicate
.- Type Parameters:
N
- any subtype ofRDFNode
- Parameters:
model
-Ontology RDF Model Impl
, notnull
subject
-OntObject
a subject for new root statement, notnull
predicate
-Property
a predicate for new root statement, notnull
listType
-Resource
list type, must be a URI-Resource ornull
for default []-listelementType
- class-type ofOntList
elementselements
-Iterator
of elements to be added to the new rdf-list- Returns:
- a fresh
OntList
instance
-
asOntList
public static <N extends org.apache.jena.rdf.model.RDFNode> OntListImpl<N> asOntList(org.apache.jena.rdf.model.RDFList list, OntGraphModelImpl model, OntObject subject, org.apache.jena.rdf.model.Property predicate, org.apache.jena.rdf.model.Resource listType, Class<N> elementType) Wraps the existingRDFList
asOntList
.- Type Parameters:
N
- any subtype ofRDFNode
- Parameters:
list
-RDFList
an existing rdf-list, notnull
model
-Ontology RDF Model Impl
, notnull
subject
-OntObject
a subject for existing root statement, notnull
predicate
-Property
a predicate for existing root statement, notnull
listType
-Resource
list type, must be a URI-Resource ornull
for default []-listelementType
- class-type ofOntList
elements- Returns:
- a fresh
OntList
instance which wraps an existing []-list within the model Graph - See Also:
-
asSafeOntList
public static <N extends org.apache.jena.rdf.model.RDFNode> OntListImpl<N> asSafeOntList(org.apache.jena.rdf.model.RDFList list, OntGraphModelImpl model, OntObject subject, org.apache.jena.rdf.model.Property predicate, org.apache.jena.rdf.model.Resource listType, Class<N> elementType) Wraps the existingRDFList
asOntList
. This method creates an instance ofOntList
which takes care about possible graph-recursions. The method is used for class-expressions and data-ranges, because it is theoretically possible to have definition of some expression which relies on the definition of another (or the same) expression presenting that represents a graph-recursion.- Type Parameters:
N
- any subtype ofRDFNode
- Parameters:
list
-RDFList
an existing rdf-list, notnull
model
-Ontology RDF Model Impl
, notnull
subject
-OntObject
a subject for existing root statement, notnull
predicate
-Property
a predicate for existing root statement, notnull
listType
-Resource
list type, must be a URI-Resource ornull
for default []-listelementType
- class-type ofOntList
elements- Returns:
- a fresh
OntList
instance which wraps an existing []-list within the model Graph - See Also:
-
stream
public static <N extends org.apache.jena.rdf.model.RDFNode> Stream<OntList<N>> stream(OntGraphModelImpl model, OntObject subject, org.apache.jena.rdf.model.Property predicate, Class<N> elementType) Lists all rdf-lists by subject and predicate in the form ofOntList
.- Type Parameters:
N
-RDFNode
subtype- Parameters:
model
-OntGraphModelImpl
subject
-OntObject
a subject for existing root statement, notnull
predicate
-Property
a predicate for existing root statement, notnull
elementType
- class-type of OntList elements- Returns:
- Stream of
OntList
s
-
createTypedList
public static org.apache.jena.rdf.model.RDFList createTypedList(org.apache.jena.enhanced.EnhGraph model, org.apache.jena.rdf.model.Resource type, Iterator<? extends org.apache.jena.rdf.model.RDFNode> members) Creates a typed []-list. The example of a []-list with type<type>
and elements<A>
,<B>
(turtle):
or :[ rdf:type <type> ; rdf:first <A> ; rdf:rest [ rdf:type <type> ; rdf:first <B> ; rdf:rest rdf:nil ] ] .
_:x rdf:type <type> . _:x rdf:first <A> . _:x rdf:rest _:y . _:y rdf:type <type> . _:y rdf:first <B> . _:y rdf:rest rdf:nil .
- Parameters:
model
-EnhGraph
model, notnull
type
-Resource
URI-Resource, notnull
members
-Iterator
ofRDFNode
, notnull
- Returns:
- a typed []-list in the form of
RDFList
-
checkRequiredInputs
public static void checkRequiredInputs(OntObject s, org.apache.jena.rdf.model.Property p, org.apache.jena.rdf.model.Resource listType, Class<?> elementType) throws RuntimeException - Throws:
RuntimeException
-
checkRequiredInputs
public static void checkRequiredInputs(OntObject s, org.apache.jena.rdf.model.Property p, org.apache.jena.rdf.model.RDFNode o, org.apache.jena.rdf.model.Resource listType, Class<?> elementType) throws RuntimeException - Throws:
RuntimeException
-
isNil
public static boolean isNil(org.apache.jena.rdf.model.RDFNode list) Answerstrue
if the givenRDF-Node
is nil []-list.- Parameters:
list
-RDFNode
, notnull
- Returns:
- boolean
-
getMainStatement
-
type
Description copied from interface:OntList
Answers the resource-type of this ONT-list, if it is typed. A standard RDF-list does not require anyrdf:type
in its RDF-deeps, since predicatesrdf:first
,rdf:rest
andrdf:nil
are sufficient for its description. In this case the method returnsempty
result. But in some rare semantics (e.g. seeSWRL
), the []-list must to be typed. In that case this method returns a URI-Resource
(that is wrapped asOptional
) describing the []-list's type (for SWRL it isswrl:AtomList
). -
getModel
- Specified by:
getModel
in interfaceorg.apache.jena.rdf.model.RDFNode
- Overrides:
getModel
in classorg.apache.jena.rdf.model.impl.ResourceImpl
-
asNode
public org.apache.jena.graph.Node asNode()- Specified by:
asNode
in interfaceorg.apache.jena.graph.FrontsNode
- Overrides:
asNode
in classorg.apache.jena.enhanced.EnhNode
-
as
public <T extends org.apache.jena.rdf.model.RDFNode> T as(Class<T> t) throws org.apache.jena.enhanced.UnsupportedPolymorphismException - Specified by:
as
in interfaceorg.apache.jena.rdf.model.RDFNode
- Overrides:
as
in classorg.apache.jena.enhanced.EnhNode
- Throws:
org.apache.jena.enhanced.UnsupportedPolymorphismException
-
canAs
- Specified by:
canAs
in interfaceorg.apache.jena.rdf.model.RDFNode
- Overrides:
canAs
in classorg.apache.jena.enhanced.EnhNode
-
isEmpty
public boolean isEmpty()Description copied from interface:RDFNodeList
Answerstrue
if this list contains no elements of the typeE
. Anil
-list is always empty, but the reverse is not true.- Specified by:
isEmpty
in interfaceRDFNodeList<E extends org.apache.jena.rdf.model.RDFNode>
- Returns:
- boolean
- See Also:
-
isNil
public boolean isNil()Description copied from interface:RDFNodeList
Answerstrue
if it is a nil []-list. Please note: a non-nil list may also not contain elements of the typeE
and, therefore, beRDFNodeList.isEmpty()
empty.- Specified by:
isNil
in interfaceRDFNodeList<E extends org.apache.jena.rdf.model.RDFNode>
- Returns:
- boolean
- See Also:
-
members
Description copied from interface:RDFNodeList
Lists all elements of the typeE
from this list. Note: a real RDF-list may contain nodes with an incompatible type, in this case they will not be included in the resultStream
. To get allRDF Node
s use the standard list representation: the expressionIter.asStream(this.as(RDFList.class).iterator())
will return aStream
of nodes.- Specified by:
members
in interfaceRDFNodeList<E extends org.apache.jena.rdf.model.RDFNode>
- Returns:
Stream
ofE
-elements- See Also:
-
RDFNode.as(Class)
Iterators.asStream(java.util.Iterator)
-
listMembers
Lists all elements of typeE
from this list. Note: the list may contain nodes with incompatible type, in this case they will be skipped.- Returns:
ExtendedIterator
ofE
-elements
-
spec
Description copied from interface:OntList
Lists all statements related to this list. For nil-list an empty stream is expected. Note: it returns all statements even if the list contains incompatible types.- Specified by:
spec
in interfaceOntList<E extends org.apache.jena.rdf.model.RDFNode>
- Returns:
- Stream of
Ontology Statement
s that does not support annotations
-
listSpec
-
contains
Description copied from interface:RDFNodeList
Answerstrue
if the []-list contains the specifiedelement
. More formally, returnstrue
if and only if this RDF-list contains at least one elemente
of the typeE
such thatelement.equals(e)
.- Specified by:
contains
in interfaceRDFNodeList<E extends org.apache.jena.rdf.model.RDFNode>
- Parameters:
item
-E
, notnull
- Returns:
- boolean
-
listContent
-
content
Description copied from interface:OntList
Returns the root statement plus spec. Please note: only the first item (root) is allowed to be annotated.- Specified by:
content
in interfaceOntList<E extends org.apache.jena.rdf.model.RDFNode>
- Returns:
Stream
ofOntology Statement
s
-
createRDFListIterator
Answers theIterator
of batches of triples that belong to this ONT-List. -
isValid
public abstract boolean isValid(org.apache.jena.rdf.model.RDFNode n) Answerstrue
if the givenRDF-Node
is valid to be a typed element of this list.- Parameters:
n
-RDFNode
- Returns:
- boolean
-
cast
Makes anE
-resource from the givenRDF-Node
.- Parameters:
n
-RDFNode
- Returns:
RDFNode
of typeE
-
addLast
Description copied from interface:OntList
Adds the given value to the end of the list. -
addFirst
Description copied from interface:OntList
Inserts the specified element at the beginning of this list. As a rule, this operation is faster thanOntList.addLast(RDFNode)
, since it does not require iteration to the end of the list. -
removeLast
Description copied from interface:OntList
Removes the last element from this list. No-op in case of nil-list. Note: the removed element can be of any type, not necessarily of the typeE
.- Specified by:
removeLast
in interfaceOntList<E extends org.apache.jena.rdf.model.RDFNode>
- Returns:
- this list instance
- See Also:
-
removeFirst
Description copied from interface:OntList
Removes and the first element from this list. No-op in case of empty list. Note: the last element can be of any type, not necessarily of typeE
. As a rule, this operation is faster thanOntList.removeLast()
, since the last one requires iteration to the end of the list.- Specified by:
removeFirst
in interfaceOntList<E extends org.apache.jena.rdf.model.RDFNode>
- Returns:
- the first element from this list
- Throws:
org.apache.jena.shared.PropertyNotFoundException
-
clear
Description copied from interface:OntList
Removes all elements from this list. The list will be empty (nil) after this call returns. -
getFirstRestStatement
public org.apache.jena.rdf.model.Statement getFirstRestStatement()Finds the first statement with predicaterdf:rest
from this ONT-List.- Returns:
Statement
ornull
in case of nil-list
-
getLastRestStatement
public org.apache.jena.rdf.model.Statement getLastRestStatement()Finds the last statement with predicaterdf:rest
from this ONT-List.- Returns:
Statement
ornull
in case of nil-list
-
getFirstTwoRestStatements
Finds the first two statements with predicaterdf:rest
from this ONT-List.- Returns:
List
that contains two or oneStatement
s ornull
in case of nil-list
-
getLastTwoRestStatements
Finds the last two statements with predicaterdf:rest
from this ONT-List.- Returns:
List
that contains two or oneStatement
s ornull
in case of nil-list
-
get
public OntList<E> get(int index) throws org.apache.jena.shared.PropertyNotFoundException, OntJenaException.IllegalArgument Description copied from interface:OntList
Answers the list that is the tail of this list starting from the given position. Note: the returned list cannot be annotated. This method can be used to insert/remove/clear the parent list at any position, e.g. the operationget(1).addFirst(e)
will insert the elemente
at second position.- Specified by:
get
in interfaceOntList<E extends org.apache.jena.rdf.model.RDFNode>
- Parameters:
index
- int, not negative- Returns:
- new
OntList
instance - Throws:
OntJenaException.IllegalArgument
- if the specified index is out of list boundsorg.apache.jena.shared.PropertyNotFoundException
-
getAs
Safely converts this RDF resource to the giventype
interface, if it is possible. Otherwise, returnsnull
. A calling of this method is effectively equivalent to the expressionthis.canAs(type) ? this.as(type) : null
.- Type Parameters:
X
- any subtype ofRDFNode
- Parameters:
type
- aClass
-type of the desired RDF view (interface)- Returns:
- an instance of the type
X
ornull
- See Also:
-
RDFNode.as(Class)
RDFNode.canAs(Class)
-