Module org.apache.jena.ontapi
Package org.apache.jena.ontapi.model
Interface OntList<E extends org.apache.jena.rdf.model.RDFNode>
- Type Parameters:
E
- the type ofrdf-node
s in this list
- All Superinterfaces:
org.apache.jena.graph.FrontsNode
,org.apache.jena.rdf.model.RDFNode
,RDFNodeList<E>
,org.apache.jena.rdf.model.Resource
- All Known Implementing Classes:
OntListImpl
A parameterized analogue of the
Jena []-List
that behaves like a java collection.
Please note: currently it is not a Personality resource and, therefore, Jena Polymorphism is not supported for it.
The latter means that attempt to cast any RDF Node
to this view
will cause UnsupportedPolymorphismException
,
but it is possible do the opposite: cast an instance of this interface to the Jena []-List
view
using the expression OntList.as(RDFList.class)
.
Also note: switching to nil-list (by any of the add/remove/clean operations) from a not-empty list and vice verse
violates a Jena invariant, this means that this OntResource
behaves not always like pure Jena Resource
and all the methods may throw OntJenaException.IllegalState
in case of usage different instances encapsulating the same resource-list.
Unlike the standard []-List
implementation, ONT-List can be typed.
This means that each resource-member of []-List may have an rdf:type
declaration,
while the standard RDF []-List impl does not support typing.
See below for an example of a typed []-list in Turtle format:
[ rdf:type <type> ;
rdf:first <A> ;
rdf:rest [ rdf:type <type> ;
rdf:first <B> ;
rdf:rest rdf:nil
]
] .
Note, that an empty []-list (i.e. nil
-list) cannot be typed.
Using the method getMainStatement()
it is possible to add annotations with any nesting depth.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionAdds the given value to the end of the list.addAll
(Collection<? extends E> c) Appends all the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator.Inserts the specified element at the beginning of this list.Adds the given value to the end of the list.clear()
Removes all elements from this list.default Stream<OntStatement>
content()
Returns the root statement plus spec.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.Returns the main triple (wrapped asOntStatement
) which determines the nature of this ontological resource.getModel()
Returns the ontology model associated with this resource.default boolean
isLocal()
Determines if this Ontology List is locally defined.remove()
Removes the last element 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.Optional<org.apache.jena.rdf.model.Resource>
type()
Answers the resource-type of this ONT-list, if it is typed.Methods inherited from interface org.apache.jena.graph.FrontsNode
asNode
Methods inherited from interface org.apache.jena.rdf.model.RDFNode
as, asLiteral, asResource, canAs, isAnon, isLiteral, isResource, isStmtResource, isURIResource, visitWith
Methods inherited from interface org.apache.jena.ontapi.model.RDFNodeList
contains, first, isEmpty, isNil, last, members, 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
-
addLast
Adds the given value to the end of the list.- Parameters:
e
-E
rdf-node- Returns:
- this list instance
- See Also:
-
removeLast
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
.- Returns:
- this list instance
- See Also:
-
addFirst
Inserts the specified element at the beginning of this list. As a rule, this operation is faster thanaddLast(RDFNode)
, since it does not require iteration to the end of the list.- Parameters:
e
-E
rdf-node- Returns:
- this list instance
-
removeFirst
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 thanremoveLast()
, since the last one requires iteration to the end of the list.- Returns:
- the first element from this list
-
clear
Removes all elements from this list. The list will be empty (nil) after this call returns.- Returns:
- this (empty) instance
-
get
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.- Parameters:
index
- int, not negative- Returns:
- new
OntList
instance - Throws:
OntJenaException.IllegalArgument
- if the specified index is out of list boundsOntJenaException
-
type
Optional<org.apache.jena.rdf.model.Resource> type()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
).- Returns:
Optional
around the URI-Resource
, can be empty.
-
spec
Stream<OntStatement> spec()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.- Returns:
- Stream of
Ontology Statement
s that does not support annotations
-
content
Returns the root statement plus spec. Please note: only the first item (root) is allowed to be annotated.- Returns:
Stream
ofOntology Statement
s
-
add
Adds the given value to the end of the list. This is a synonym for thethis.addLast(e)
.- Parameters:
e
-E
rdf-node- Returns:
- this list instance
- See Also:
-
remove
Removes the last element from this list. This is a synonym for thethis.removeLast(e)
.- Returns:
- this list instance
- See Also:
-
addAll
Appends all the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator.- Parameters:
c
- Collection ofE
-elements- Returns:
- this list instance
-
isLocal
default boolean isLocal()Determines if this Ontology List is locally defined. This means that the resource definition (i.e., a theroot statement
) belongs to the base ontology graph. If the ontology contains subgraphs (which should matchowl:imports
in OWL) and the resource is defined in one of them, than this method called from top-level interface will returnfalse
. -
getModel
OntModel getModel()Returns the ontology model associated with this resource. If the Resource was not created by a Model, the result may be null.- Specified by:
getModel
in interfaceorg.apache.jena.rdf.model.RDFNode
- Returns:
OntModel
-
getMainStatement
OntStatement getMainStatement()Returns the main triple (wrapped asOntStatement
) which determines the nature of this ontological resource. Usually it is a type-declaration (i.e., a triple with predicaterdf:type
and with this resource as a subject). The result may benull
in several boundary cases (e.g., for built-in OWL entities).Note that a main statement differs from the others: for a common
OntStatement
, its annotations go in the form ofAnnotation
, but a main-statement can have annotation assertions.- Returns:
OntStatement
ornull
-
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)
-