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 classThe simplestiteratorover ardf:List, whoseIterator.next()method returns a batch oftriples in the form of standardJava List.static classAn extendedOntListImpl.RDFListIteratorwhoseIterator.next()method does not throwNoSuchElementExceptionin case no element found, but returnsnullinstead. -
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.NodeasNode()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 existingRDFListasOntList.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 existingRDFListasOntList.<X extends org.apache.jena.rdf.model.RDFNode>
booleanabstract Ecast(org.apache.jena.rdf.model.RDFNode n) Makes anE-resource from the givenRDF-Node.static voidcheckRequiredInputs(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 voidcheckRequiredInputs(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.booleanAnswerstrueif 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 freshOntListwith the givenelementTypeas a type constraint containing all content from the specifiedExtendedIteratorpreserving the original order.Answers theIteratorof batches of triples that belong to this ONT-List.static org.apache.jena.rdf.model.RDFListcreateTypedList(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 giventypeinterface, if it is possible.org.apache.jena.rdf.model.StatementFinds the first statement with predicaterdf:restfrom this ONT-List.List<org.apache.jena.rdf.model.Statement>Finds the first two statements with predicaterdf:restfrom this ONT-List.org.apache.jena.rdf.model.StatementFinds the last statement with predicaterdf:restfrom this ONT-List.List<org.apache.jena.rdf.model.Statement>Finds the last two statements with predicaterdf:restfrom this ONT-List.getModel()booleanisEmpty()Answerstrueif this list contains no elements of the typeE.booleanisNil()Answerstrueif it is a nil []-list.static booleanisNil(org.apache.jena.rdf.model.RDFNode list) Answerstrueif the givenRDF-Nodeis nil []-list.abstract booleanisValid(org.apache.jena.rdf.model.RDFNode n) Answerstrueif the givenRDF-Nodeis 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 typeEfrom this list.org.apache.jena.util.iterator.ExtendedIterator<OntStatement>listSpec()members()Lists all elements of the typeEfrom 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, visitWithMethods inherited from class org.apache.jena.enhanced.EnhNode
equals, getGraph, hashCode, isAnon, isLiteral, isResource, isStmtResource, isURIResource, isValid, viewAsMethods inherited from class org.apache.jena.enhanced.Polymorphic
addView, supportsMethods inherited from interface org.apache.jena.rdf.model.RDFNode
asLiteral, asResource, isAnon, isLiteral, isResource, isStmtResource, isURIResource, visitWithMethods inherited from interface org.apache.jena.ontapi.model.RDFNodeList
first, last, sizeMethods 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 freshOntListwith the givenelementTypeas a type constraint containing all content from the specifiedExtendedIteratorpreserving the original order. The returned []-list will be attached to the model by the givensubjectandpredicate.- Type Parameters:
N- any subtype ofRDFNode- Parameters:
model-Ontology RDF Model Impl, notnullsubject-OntObjecta subject for new root statement, notnullpredicate-Propertya predicate for new root statement, notnulllistType-Resourcelist type, must be a URI-Resource ornullfor default []-listelementType- class-type ofOntListelementselements-Iteratorof elements to be added to the new rdf-list- Returns:
- a fresh
OntListinstance
-
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 existingRDFListasOntList.- Type Parameters:
N- any subtype ofRDFNode- Parameters:
list-RDFListan existing rdf-list, notnullmodel-Ontology RDF Model Impl, notnullsubject-OntObjecta subject for existing root statement, notnullpredicate-Propertya predicate for existing root statement, notnulllistType-Resourcelist type, must be a URI-Resource ornullfor default []-listelementType- class-type ofOntListelements- Returns:
- a fresh
OntListinstance 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 existingRDFListasOntList. This method creates an instance ofOntListwhich 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-RDFListan existing rdf-list, notnullmodel-Ontology RDF Model Impl, notnullsubject-OntObjecta subject for existing root statement, notnullpredicate-Propertya predicate for existing root statement, notnulllistType-Resourcelist type, must be a URI-Resource ornullfor default []-listelementType- class-type ofOntListelements- Returns:
- a fresh
OntListinstance 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-RDFNodesubtype- Parameters:
model-OntGraphModelImplsubject-OntObjecta subject for existing root statement, notnullpredicate-Propertya predicate for existing root statement, notnullelementType- class-type of OntList elements- Returns:
- Stream of
OntLists
-
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-EnhGraphmodel, notnulltype-ResourceURI-Resource, notnullmembers-IteratorofRDFNode, 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) Answerstrueif the givenRDF-Nodeis nil []-list.- Parameters:
list-RDFNode, notnull- Returns:
- boolean
-
getMainStatement
-
type
Description copied from interface:OntListAnswers the resource-type of this ONT-list, if it is typed. A standard RDF-list does not require anyrdf:typein its RDF-deeps, since predicatesrdf:first,rdf:restandrdf:nilare sufficient for its description. In this case the method returnsemptyresult. 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:
getModelin interfaceorg.apache.jena.rdf.model.RDFNode- Overrides:
getModelin classorg.apache.jena.rdf.model.impl.ResourceImpl
-
asNode
public org.apache.jena.graph.Node asNode()- Specified by:
asNodein interfaceorg.apache.jena.graph.FrontsNode- Overrides:
asNodein 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:
asin interfaceorg.apache.jena.rdf.model.RDFNode- Overrides:
asin classorg.apache.jena.enhanced.EnhNode- Throws:
org.apache.jena.enhanced.UnsupportedPolymorphismException
-
canAs
- Specified by:
canAsin interfaceorg.apache.jena.rdf.model.RDFNode- Overrides:
canAsin classorg.apache.jena.enhanced.EnhNode
-
isEmpty
public boolean isEmpty()Description copied from interface:RDFNodeListAnswerstrueif this list contains no elements of the typeE. Anil-list is always empty, but the reverse is not true.- Specified by:
isEmptyin interfaceRDFNodeList<E extends org.apache.jena.rdf.model.RDFNode>- Returns:
- boolean
- See Also:
-
isNil
public boolean isNil()Description copied from interface:RDFNodeListAnswerstrueif it is a nil []-list. Please note: a non-nil list may also not contain elements of the typeEand, therefore, beRDFNodeList.isEmpty()empty.- Specified by:
isNilin interfaceRDFNodeList<E extends org.apache.jena.rdf.model.RDFNode>- Returns:
- boolean
- See Also:
-
members
Description copied from interface:RDFNodeListLists all elements of the typeEfrom 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 Nodes use the standard list representation: the expressionIter.asStream(this.as(RDFList.class).iterator())will return aStreamof nodes.- Specified by:
membersin interfaceRDFNodeList<E extends org.apache.jena.rdf.model.RDFNode>- Returns:
StreamofE-elements- See Also:
-
RDFNode.as(Class)Iterators.asStream(java.util.Iterator)
-
listMembers
Lists all elements of typeEfrom this list. Note: the list may contain nodes with incompatible type, in this case they will be skipped.- Returns:
ExtendedIteratorofE-elements
-
spec
Description copied from interface:OntListLists 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:
specin interfaceOntList<E extends org.apache.jena.rdf.model.RDFNode>- Returns:
- Stream of
Ontology Statements that does not support annotations
-
listSpec
-
contains
Description copied from interface:RDFNodeListAnswerstrueif the []-list contains the specifiedelement. More formally, returnstrueif and only if this RDF-list contains at least one elementeof the typeEsuch thatelement.equals(e).- Specified by:
containsin interfaceRDFNodeList<E extends org.apache.jena.rdf.model.RDFNode>- Parameters:
item-E, notnull- Returns:
- boolean
-
listContent
-
content
Description copied from interface:OntListReturns the root statement plus spec. Please note: only the first item (root) is allowed to be annotated.- Specified by:
contentin interfaceOntList<E extends org.apache.jena.rdf.model.RDFNode>- Returns:
StreamofOntology Statements
-
createRDFListIterator
Answers theIteratorof batches of triples that belong to this ONT-List. -
isValid
public abstract boolean isValid(org.apache.jena.rdf.model.RDFNode n) Answerstrueif the givenRDF-Nodeis 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:
RDFNodeof typeE
-
addLast
Description copied from interface:OntListAdds the given value to the end of the list. -
addFirst
Description copied from interface:OntListInserts 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:OntListRemoves 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:
removeLastin interfaceOntList<E extends org.apache.jena.rdf.model.RDFNode>- Returns:
- this list instance
- See Also:
-
removeFirst
Description copied from interface:OntListRemoves 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:
removeFirstin 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:OntListRemoves 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:restfrom this ONT-List.- Returns:
Statementornullin case of nil-list
-
getLastRestStatement
public org.apache.jena.rdf.model.Statement getLastRestStatement()Finds the last statement with predicaterdf:restfrom this ONT-List.- Returns:
Statementornullin case of nil-list
-
getFirstTwoRestStatements
Finds the first two statements with predicaterdf:restfrom this ONT-List.- Returns:
Listthat contains two or oneStatements ornullin case of nil-list
-
getLastTwoRestStatements
Finds the last two statements with predicaterdf:restfrom this ONT-List.- Returns:
Listthat contains two or oneStatements ornullin case of nil-list
-
get
public OntList<E> get(int index) throws org.apache.jena.shared.PropertyNotFoundException, OntJenaException.IllegalArgument Description copied from interface:OntListAnswers 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 elementeat second position.- Specified by:
getin interfaceOntList<E extends org.apache.jena.rdf.model.RDFNode>- Parameters:
index- int, not negative- Returns:
- new
OntListinstance - Throws:
OntJenaException.IllegalArgument- if the specified index is out of list boundsorg.apache.jena.shared.PropertyNotFoundException
-
getAs
Safely converts this RDF resource to the giventypeinterface, 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
Xornull - See Also:
-
RDFNode.as(Class)RDFNode.canAs(Class)
-