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 Classes
    Modifier and Type
    Class
    Description
    static class 
    The simplest iterator over a rdf:List, whose Iterator.next() method returns a batch of triples in the form of standard Java List.
    static class 
    An extended OntListImpl.RDFListIterator whose Iterator.next() method does not throw NoSuchElementException in case no element found, but returns null instead.
  • Field Summary

    Fields inherited from class org.apache.jena.rdf.model.impl.ResourceImpl

    factory, rdfNodeFactory
  • Method Summary

    Modifier and Type
    Method
    Description
    Inserts 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>
    T
    as(Class<T> t)
     
    org.apache.jena.graph.Node
     
    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 existing RDFList as OntList.
    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 existing RDFList as OntList.
    <X extends org.apache.jena.rdf.model.RDFNode>
    boolean
    canAs(Class<X> t)
     
    abstract E
    cast(org.apache.jena.rdf.model.RDFNode n)
    Makes an E-resource from the given RDF-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)
     
    Removes all elements from this list.
    boolean
    contains(E item)
    Answers true if the []-list contains the specified element.
    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 fresh OntList with the given elementType as a type constraint containing all content from the specified ExtendedIterator preserving the original order.
    Iterator<List<org.apache.jena.graph.Triple>>
    Answers the Iterator 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>
    X
    getAs(Class<X> type)
    Safely converts this RDF resource to the given type interface, if it is possible.
    org.apache.jena.rdf.model.Statement
    Finds the first statement with predicate rdf:rest from this ONT-List.
    List<org.apache.jena.rdf.model.Statement>
    Finds the first two statements with predicate rdf:rest from this ONT-List.
    org.apache.jena.rdf.model.Statement
    Finds the last statement with predicate rdf:rest from this ONT-List.
    List<org.apache.jena.rdf.model.Statement>
    Finds the last two statements with predicate rdf:rest from this ONT-List.
     
     
    boolean
    Answers true if this list contains no elements of the type E.
    boolean
    Answers true if it is a nil []-list.
    static boolean
    isNil(org.apache.jena.rdf.model.RDFNode list)
    Answers true if the given RDF-Node is nil []-list.
    abstract boolean
    isValid(org.apache.jena.rdf.model.RDFNode n)
    Answers true if the given RDF-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 type E from this list.
    org.apache.jena.util.iterator.ExtendedIterator<OntStatement>
     
    Lists all elements of the type E from this list.
    Removes and the first element from this list.
    Removes the last element from this list.
    Lists all statements related to this list.
    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 of OntList.
    Optional<org.apache.jena.rdf.model.Resource>
    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 class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.apache.jena.ontapi.model.OntList

    add, addAll, isLocal, remove

    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 fresh OntList with the given elementType as a type constraint containing all content from the specified ExtendedIterator preserving the original order. The returned []-list will be attached to the model by the given subject and predicate.
      Type Parameters:
      N - any subtype of RDFNode
      Parameters:
      model - Ontology RDF Model Impl, not null
      subject - OntObject a subject for new root statement, not null
      predicate - Property a predicate for new root statement, not null
      listType - Resource list type, must be a URI-Resource or null for default []-list
      elementType - class-type of OntList elements
      elements - 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 existing RDFList as OntList.
      Type Parameters:
      N - any subtype of RDFNode
      Parameters:
      list - RDFList an existing rdf-list, not null
      model - Ontology RDF Model Impl, not null
      subject - OntObject a subject for existing root statement, not null
      predicate - Property a predicate for existing root statement, not null
      listType - Resource list type, must be a URI-Resource or null for default []-list
      elementType - class-type of OntList 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 existing RDFList as OntList. This method creates an instance of OntList 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 of RDFNode
      Parameters:
      list - RDFList an existing rdf-list, not null
      model - Ontology RDF Model Impl, not null
      subject - OntObject a subject for existing root statement, not null
      predicate - Property a predicate for existing root statement, not null
      listType - Resource list type, must be a URI-Resource or null for default []-list
      elementType - class-type of OntList 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 of OntList.
      Type Parameters:
      N - RDFNode subtype
      Parameters:
      model - OntGraphModelImpl
      subject - OntObject a subject for existing root statement, not null
      predicate - Property a predicate for existing root statement, not null
      elementType - 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):
      
       [ rdf:type   <type> ;
         rdf:first  <A> ;
         rdf:rest   [ rdf:type   <type> ;
                      rdf:first  <B> ;
                      rdf:rest   rdf:nil
                    ]
       ] .
       
      or :
      
       _: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, not null
      type - Resource URI-Resource, not null
      members - Iterator of RDFNode, not null
      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)
      Answers true if the given RDF-Node is nil []-list.
      Parameters:
      list - RDFNode, not null
      Returns:
      boolean
    • getMainStatement

      public OntStatement getMainStatement()
    • type

      public Optional<org.apache.jena.rdf.model.Resource> 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 any rdf:type in its RDF-deeps, since predicates rdf:first, rdf:rest and rdf:nil are sufficient for its description. In this case the method returns empty result. But in some rare semantics (e.g. see SWRL), the []-list must to be typed. In that case this method returns a URI-Resource (that is wrapped as Optional) describing the []-list's type (for SWRL it is swrl:AtomList).
      Specified by:
      type in interface OntList<E extends org.apache.jena.rdf.model.RDFNode>
      Returns:
      Optional around the URI-Resource, can be empty.
    • getModel

      public OntGraphModelImpl getModel()
      Specified by:
      getModel in interface org.apache.jena.rdf.model.RDFNode
      Overrides:
      getModel in class org.apache.jena.rdf.model.impl.ResourceImpl
    • asNode

      public org.apache.jena.graph.Node asNode()
      Specified by:
      asNode in interface org.apache.jena.graph.FrontsNode
      Overrides:
      asNode in class org.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 interface org.apache.jena.rdf.model.RDFNode
      Overrides:
      as in class org.apache.jena.enhanced.EnhNode
      Throws:
      org.apache.jena.enhanced.UnsupportedPolymorphismException
    • canAs

      public <X extends org.apache.jena.rdf.model.RDFNode> boolean canAs(Class<X> t)
      Specified by:
      canAs in interface org.apache.jena.rdf.model.RDFNode
      Overrides:
      canAs in class org.apache.jena.enhanced.EnhNode
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: RDFNodeList
      Answers true if this list contains no elements of the type E. A nil-list is always empty, but the reverse is not true.
      Specified by:
      isEmpty in interface RDFNodeList<E extends org.apache.jena.rdf.model.RDFNode>
      Returns:
      boolean
      See Also:
    • isNil

      public boolean isNil()
      Description copied from interface: RDFNodeList
      Answers true if it is a nil []-list. Please note: a non-nil list may also not contain elements of the type E and, therefore, be RDFNodeList.isEmpty() empty.
      Specified by:
      isNil in interface RDFNodeList<E extends org.apache.jena.rdf.model.RDFNode>
      Returns:
      boolean
      See Also:
    • members

      public Stream<E> members()
      Description copied from interface: RDFNodeList
      Lists all elements of the type E 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 result Stream. To get all RDF Nodes use the standard list representation: the expression Iter.asStream(this.as(RDFList.class).iterator()) will return a Stream of nodes.
      Specified by:
      members in interface RDFNodeList<E extends org.apache.jena.rdf.model.RDFNode>
      Returns:
      Stream of E-elements
      See Also:
    • listMembers

      public org.apache.jena.util.iterator.ExtendedIterator<E> listMembers()
      Lists all elements of type E from this list. Note: the list may contain nodes with incompatible type, in this case they will be skipped.
      Returns:
      ExtendedIterator of E-elements
    • spec

      public Stream<OntStatement> 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 interface OntList<E extends org.apache.jena.rdf.model.RDFNode>
      Returns:
      Stream of Ontology Statements that does not support annotations
    • listSpec

      public org.apache.jena.util.iterator.ExtendedIterator<OntStatement> listSpec()
    • contains

      public boolean contains(E item)
      Description copied from interface: RDFNodeList
      Answers true if the []-list contains the specified element. More formally, returns true if and only if this RDF-list contains at least one element e of the type E such that element.equals(e).
      Specified by:
      contains in interface RDFNodeList<E extends org.apache.jena.rdf.model.RDFNode>
      Parameters:
      item - E, not null
      Returns:
      boolean
    • listContent

      public org.apache.jena.util.iterator.ExtendedIterator<OntStatement> listContent()
    • content

      public Stream<OntStatement> 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 interface OntList<E extends org.apache.jena.rdf.model.RDFNode>
      Returns:
      Stream of Ontology Statements
    • createRDFListIterator

      public Iterator<List<org.apache.jena.graph.Triple>> createRDFListIterator()
      Answers the Iterator of batches of triples that belong to this ONT-List.
      Returns:
      Iterator of Triple Lists or null in case of empty for nil-list
    • isValid

      public abstract boolean isValid(org.apache.jena.rdf.model.RDFNode n)
      Answers true if the given RDF-Node is valid to be a typed element of this list.
      Parameters:
      n - RDFNode
      Returns:
      boolean
    • cast

      public abstract E cast(org.apache.jena.rdf.model.RDFNode n)
      Makes an E-resource from the given RDF-Node.
      Parameters:
      n - RDFNode
      Returns:
      RDFNode of type E
    • addLast

      public OntList<E> addLast(E e)
      Description copied from interface: OntList
      Adds the given value to the end of the list.
      Specified by:
      addLast in interface OntList<E extends org.apache.jena.rdf.model.RDFNode>
      Parameters:
      e - E rdf-node
      Returns:
      this list instance
      See Also:
    • addFirst

      public OntList<E> addFirst(E e) throws org.apache.jena.shared.PropertyNotFoundException
      Description copied from interface: OntList
      Inserts the specified element at the beginning of this list. As a rule, this operation is faster than OntList.addLast(RDFNode), since it does not require iteration to the end of the list.
      Specified by:
      addFirst in interface OntList<E extends org.apache.jena.rdf.model.RDFNode>
      Parameters:
      e - E rdf-node
      Returns:
      this list instance
      Throws:
      org.apache.jena.shared.PropertyNotFoundException
    • removeLast

      public OntList<E> 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 type E.
      Specified by:
      removeLast in interface OntList<E extends org.apache.jena.rdf.model.RDFNode>
      Returns:
      this list instance
      See Also:
    • removeFirst

      public OntList<E> removeFirst() throws org.apache.jena.shared.PropertyNotFoundException
      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 type E. As a rule, this operation is faster than OntList.removeLast() , since the last one requires iteration to the end of the list.
      Specified by:
      removeFirst in interface OntList<E extends org.apache.jena.rdf.model.RDFNode>
      Returns:
      the first element from this list
      Throws:
      org.apache.jena.shared.PropertyNotFoundException
    • clear

      public OntList<E> clear()
      Description copied from interface: OntList
      Removes all elements from this list. The list will be empty (nil) after this call returns.
      Specified by:
      clear in interface OntList<E extends org.apache.jena.rdf.model.RDFNode>
      Returns:
      this (empty) instance
    • getFirstRestStatement

      public org.apache.jena.rdf.model.Statement getFirstRestStatement()
      Finds the first statement with predicate rdf:rest from this ONT-List.
      Returns:
      Statement or null in case of nil-list
    • getLastRestStatement

      public org.apache.jena.rdf.model.Statement getLastRestStatement()
      Finds the last statement with predicate rdf:rest from this ONT-List.
      Returns:
      Statement or null in case of nil-list
    • getFirstTwoRestStatements

      public List<org.apache.jena.rdf.model.Statement> getFirstTwoRestStatements()
      Finds the first two statements with predicate rdf:rest from this ONT-List.
      Returns:
      List that contains two or one Statements or null in case of nil-list
    • getLastTwoRestStatements

      public List<org.apache.jena.rdf.model.Statement> getLastTwoRestStatements()
      Finds the last two statements with predicate rdf:rest from this ONT-List.
      Returns:
      List that contains two or one Statements or null 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 operation get(1).addFirst(e) will insert the element e at second position.
      Specified by:
      get in interface OntList<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 bounds
      org.apache.jena.shared.PropertyNotFoundException
    • getAs

      default <X extends org.apache.jena.rdf.model.RDFNode> X getAs(Class<X> type)
      Safely converts this RDF resource to the given type interface, if it is possible. Otherwise, returns null. A calling of this method is effectively equivalent to the expression this.canAs(type) ? this.as(type) : null.
      Type Parameters:
      X - any subtype of RDFNode
      Parameters:
      type - a Class-type of the desired RDF view (interface)
      Returns:
      an instance of the type X or null
      See Also:
      • RDFNode.as(Class)
      • RDFNode.canAs(Class)