Interface OntList<E extends org.apache.jena.rdf.model.RDFNode>

Type Parameters:
E - the type of rdf-nodes 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

public interface OntList<E extends org.apache.jena.rdf.model.RDFNode> extends RDFNodeList<E>
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 Type
    Method
    Description
    default OntList<E>
    add(E e)
    Adds the given value to the end of the list.
    default OntList<E>
    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.
    Removes all elements from this list.
    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>
    X
    getAs(Class<X> type)
    Safely converts this RDF resource to the given type interface, if it is possible.
    Returns the main triple (wrapped as OntStatement) which determines the nature of this ontological resource.
    Returns the ontology model associated with this resource.
    default boolean
    Determines if this Ontology List is locally defined.
    default OntList<E>
    Removes the last element 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.
    Optional<org.apache.jena.rdf.model.Resource>
    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

      OntList<E> addLast(E e)
      Adds the given value to the end of the list.
      Parameters:
      e - E rdf-node
      Returns:
      this list instance
      See Also:
    • removeLast

      OntList<E> 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 type E.
      Returns:
      this list instance
      See Also:
    • addFirst

      OntList<E> addFirst(E e)
      Inserts the specified element at the beginning of this list. As a rule, this operation is faster than addLast(RDFNode), since it does not require iteration to the end of the list.
      Parameters:
      e - E rdf-node
      Returns:
      this list instance
    • removeFirst

      OntList<E> 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 type E. As a rule, this operation is faster than removeLast() , since the last one requires iteration to the end of the list.
      Returns:
      the first element from this list
    • clear

      OntList<E> clear()
      Removes all elements from this list. The list will be empty (nil) after this call returns.
      Returns:
      this (empty) instance
    • get

      OntList<E> get(int index) throws OntJenaException
      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.
      Parameters:
      index - int, not negative
      Returns:
      new OntList instance
      Throws:
      OntJenaException.IllegalArgument - if the specified index is out of list bounds
      OntJenaException
    • 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 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).
      Returns:
      Optional around the URI-Resource, can be empty.
    • 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 Statements that does not support annotations
    • content

      default Stream<OntStatement> content()
      Returns the root statement plus spec. Please note: only the first item (root) is allowed to be annotated.
      Returns:
      Stream of Ontology Statements
    • add

      default OntList<E> add(E e)
      Adds the given value to the end of the list. This is a synonym for the this.addLast(e).
      Parameters:
      e - E rdf-node
      Returns:
      this list instance
      See Also:
    • remove

      default OntList<E> remove()
      Removes the last element from this list. This is a synonym for the this.removeLast(e).
      Returns:
      this list instance
      See Also:
    • addAll

      default OntList<E> 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.
      Parameters:
      c - Collection of E-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 the root statement) belongs to the base ontology graph. If the ontology contains subgraphs (which should match owl:imports in OWL) and the resource is defined in one of them, than this method called from top-level interface will return false.
    • 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 interface org.apache.jena.rdf.model.RDFNode
      Returns:
      OntModel
    • getMainStatement

      OntStatement getMainStatement()
      Returns the main triple (wrapped as OntStatement) which determines the nature of this ontological resource. Usually it is a type-declaration (i.e., a triple with predicate rdf:type and with this resource as a subject). The result may be null 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 of Annotation, but a main-statement can have annotation assertions.

      Returns:
      OntStatement or null
    • 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)