Class WrapperBlankNodeOrIRI

  • All Implemented Interfaces:
    org.apache.commons.rdf.api.BlankNodeOrIRI, org.apache.commons.rdf.api.RDFTerm
    Direct Known Subclasses:
    WrapperBlankNode, WrapperIRI

    public abstract class WrapperBlankNodeOrIRI
    extends Object
    implements org.apache.commons.rdf.api.BlankNodeOrIRI
    A wrapper for IRI and blank node terms which contains methods that aid authoring wrapping classes.

    All methods require a predicate and a value mapping function.

    This table details the behavior of singular getter helper methods depending on the number of matching statements in the underlying graph:

     ┌───────────────┬───────┬────────┬────────┐
     │               │   0   │   1    │   >1   │
     ├───────────────┼───────┼────────┼────────┤
     │ anyOrNull     │ null  │ single │ random │
     │ anyOrThrow    │ throw │ single │ random │
     │ singleOrNull  │ null  │ single │ throw  │
     │ singleOrThrow │ throw │ single │ throw  │
     └───────────────┴───────┴────────┴────────┘
     

    This table details the behavior of plural getter helper methods in terms of reflecting changes to the underlying graph after calling them:

     ┌─────────────────┬─────────┐
     │ objects         │ dynamic │
     │ objectStream    │ static  │
     │ objectIterator  │ static  │
     │ objectsReadOnly │ static  │
     └─────────────────┴─────────┘
     

    This table details the behavior of setter helper methods in terms of effect on existing statements in the underlying graph and given values:

     ┌───────────────────┬──────────┬────────────┐
     │                   │ existing │ null value │
     ├───────────────────┼──────────┼────────────┤
     │ overwrite         │ remove   │ throw      │
     │ overwriteNullable │ remove   │ ignore     │
     │ add               │ leave    │ throw      │
     └───────────────────┴──────────┴────────────┘
     
    Author:
    Samu Lang
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.apache.commons.rdf.api.Graph graph
      The internal wrapped graph object.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected WrapperBlankNodeOrIRI​(org.apache.commons.rdf.api.Graph graph)
      Create a new subject node with a backing Graph object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected <T> void add​(org.apache.commons.rdf.api.IRI p, Iterable<T> v, TermMapping<T> m)
      An additive converting singular setter helper for expected cardinality 0..*.
      protected <T> void add​(org.apache.commons.rdf.api.IRI p, T v, TermMapping<T> m)
      An additive converting singular setter helper for expected cardinality 0..*.
      protected <T> T anyOrNull​(org.apache.commons.rdf.api.IRI p, ValueMapping<T> m)
      A converting singular getter helper for expected cardinality 0..1 that ignores overflow.
      protected <T> T anyOrThrow​(org.apache.commons.rdf.api.IRI p, ValueMapping<T> m)
      A converting singular getter helper for expected cardinality 1..1 that ignores overflow.
      protected <T> Iterator<T> objectIterator​(org.apache.commons.rdf.api.IRI p, ValueMapping<T> m)
      A static converting plural getter helper for expected cardinality 0..*.
      protected <T> Set<T> objects​(org.apache.commons.rdf.api.IRI p, TermMapping<T> tm, ValueMapping<T> vm)
      A dynamic converting plural getter helper for expected cardinality 0..*.
      protected <T> Set<T> objectsReadOnly​(org.apache.commons.rdf.api.IRI p, ValueMapping<T> m)
      A static converting plural getter helper for expected cardinality 0..*.
      protected <T> Stream<T> objectStream​(org.apache.commons.rdf.api.IRI p, ValueMapping<T> m)
      A static converting plural getter helper for expected cardinality 0..*.
      protected <T> void overwrite​(org.apache.commons.rdf.api.IRI p, Iterable<T> v, TermMapping<T> m)
      A destructive converting plural setter helper for expected cardinality 1..*.
      protected <T> void overwrite​(org.apache.commons.rdf.api.IRI p, T v, TermMapping<T> m)
      A destructive converting singular setter helper for expected cardinality 1..1.
      protected <T> void overwriteNullable​(org.apache.commons.rdf.api.IRI p, Iterable<T> v, TermMapping<T> m)
      A destructive converting plural setter helper for expected cardinality 0..*.
      protected <T> void overwriteNullable​(org.apache.commons.rdf.api.IRI p, T v, TermMapping<T> m)
      A destructive converting singular setter helper for expected cardinality 0..1.
      protected <T> T singleOrNull​(org.apache.commons.rdf.api.IRI p, ValueMapping<T> m)
      A converting singular getter helper for expected cardinality 0..1 that forbids overflow.
      protected <T> T singleOrThrow​(org.apache.commons.rdf.api.IRI p, ValueMapping<T> m)
      A converting singular getter helper for expected cardinality 1..1 that forbids overflow.
      • Methods inherited from interface org.apache.commons.rdf.api.RDFTerm

        equals, hashCode, ntriplesString
    • Field Detail

      • graph

        protected final org.apache.commons.rdf.api.Graph graph
        The internal wrapped graph object.
    • Constructor Detail

      • WrapperBlankNodeOrIRI

        protected WrapperBlankNodeOrIRI​(org.apache.commons.rdf.api.Graph graph)
        Create a new subject node with a backing Graph object.
        Parameters:
        graph - The wrapped graph, may not be null
    • Method Detail

      • anyOrNull

        protected <T> T anyOrNull​(org.apache.commons.rdf.api.IRI p,
                                  ValueMapping<T> m)
        A converting singular getter helper for expected cardinality 0..1 that ignores overflow.
        Type Parameters:
        T - the type of values returned the type of values returned
        Parameters:
        p - the predicate to query
        m - the mapping applied to result terms
        Returns:
        the converted object of an arbitrary statement with this subject and the given predicate or null if there are no such statements
      • anyOrThrow

        protected <T> T anyOrThrow​(org.apache.commons.rdf.api.IRI p,
                                   ValueMapping<T> m)
        A converting singular getter helper for expected cardinality 1..1 that ignores overflow.
        Type Parameters:
        T - the type of values returned
        Parameters:
        p - the predicate to query
        m - the mapping applied to result terms
        Returns:
        the converted object of an arbitrary statement with this subject and the given predicate
        Throws:
        IllegalStateException - if there are no such statements
      • singleOrNull

        protected <T> T singleOrNull​(org.apache.commons.rdf.api.IRI p,
                                     ValueMapping<T> m)
        A converting singular getter helper for expected cardinality 0..1 that forbids overflow.
        Type Parameters:
        T - the type of values returned
        Parameters:
        p - the predicate to query
        m - the mapping applied to result terms
        Returns:
        the converted object of the only statement with this subject and the given predicate, or null if there is no such statement
        Throws:
        IllegalStateException - if there are multiple such statements
      • singleOrThrow

        protected <T> T singleOrThrow​(org.apache.commons.rdf.api.IRI p,
                                      ValueMapping<T> m)
        A converting singular getter helper for expected cardinality 1..1 that forbids overflow.
        Type Parameters:
        T - the type of values returned
        Parameters:
        p - the predicate to query
        m - the mapping applied to result terms
        Returns:
        the converted object of the only statement with this subject and the given predicate
        Throws:
        IllegalStateException - if there are no such statements
        IllegalStateException - if there are multiple such statements
      • objectIterator

        protected <T> Iterator<T> objectIterator​(org.apache.commons.rdf.api.IRI p,
                                                 ValueMapping<T> m)
        A static converting plural getter helper for expected cardinality 0..*.
        Type Parameters:
        T - the type of values returned
        Parameters:
        p - the predicate to query
        m - the mapping applied to result terms
        Returns:
        the converted objects of statements with this subject and the given predicate
        Implementation Note:
        Prior to returning the iterator, this implementation consumes (buffers) an underlying stream of statements with the predicate p and the mapping function m applied to each object.
      • objectsReadOnly

        protected <T> Set<T> objectsReadOnly​(org.apache.commons.rdf.api.IRI p,
                                             ValueMapping<T> m)
        A static converting plural getter helper for expected cardinality 0..*.
        Type Parameters:
        T - the type of values returned
        Parameters:
        p - the predicate to query
        m - the mapping applied to result terms
        Returns:
        a static set view over converted objects of statements with this subject and the given predicate
      • objects

        protected <T> Set<T> objects​(org.apache.commons.rdf.api.IRI p,
                                     TermMapping<T> tm,
                                     ValueMapping<T> vm)
        A dynamic converting plural getter helper for expected cardinality 0..*.
        Type Parameters:
        T - the type of values returned
        Parameters:
        p - the predicate to query
        tm - the input mapping to apply to values
        vm - the output mapping to apply to terms
        Returns:
        a dynamic set view over converted objects of statements with this subject and the given predicate
      • objectStream

        protected <T> Stream<T> objectStream​(org.apache.commons.rdf.api.IRI p,
                                             ValueMapping<T> m)
        A static converting plural getter helper for expected cardinality 0..*.
        Type Parameters:
        T - the type of values returned
        Parameters:
        p - the predicate to query
        m - the mapping applied to result terms
        Returns:
        a static stream of converted objects of statements with this subject and the given predicate
      • overwrite

        protected <T> void overwrite​(org.apache.commons.rdf.api.IRI p,
                                     T v,
                                     TermMapping<T> m)
        A destructive converting singular setter helper for expected cardinality 1..1.
        Type Parameters:
        T - the type of values returned
        Parameters:
        p - the predicate to query
        v - the value to assert as object in the graph
        m - the mapping applied to the value
        Throws:
        NullPointerException - if the given value is null
      • overwrite

        protected <T> void overwrite​(org.apache.commons.rdf.api.IRI p,
                                     Iterable<T> v,
                                     TermMapping<T> m)
        A destructive converting plural setter helper for expected cardinality 1..*.
        Type Parameters:
        T - the type of values returned
        Parameters:
        p - the predicate to query
        v - the values to assert as objects in the graph
        m - the mapping applied to the value
        Throws:
        NullPointerException - if the given value is null
        NullPointerException - if the given value contains null elements
      • overwriteNullable

        protected <T> void overwriteNullable​(org.apache.commons.rdf.api.IRI p,
                                             Iterable<T> v,
                                             TermMapping<T> m)
        A destructive converting plural setter helper for expected cardinality 0..*.
        Type Parameters:
        T - the type of values returned
        Parameters:
        p - the predicate to query
        v - the values to assert as objects in the graph
        m - the mapping applied to the value
        Throws:
        NullPointerException - if the given value is not null and contains null elements
      • overwriteNullable

        protected <T> void overwriteNullable​(org.apache.commons.rdf.api.IRI p,
                                             T v,
                                             TermMapping<T> m)
        A destructive converting singular setter helper for expected cardinality 0..1.
        Type Parameters:
        T - the type of values returned
        Parameters:
        p - the predicate to query
        v - the value to assert as object in the graph
        m - the mapping applied to the value
      • add

        protected <T> void add​(org.apache.commons.rdf.api.IRI p,
                               T v,
                               TermMapping<T> m)
        An additive converting singular setter helper for expected cardinality 0..*.
        Type Parameters:
        T - the type of values returned
        Parameters:
        p - the predicate to query
        v - the value to assert as object in the graph
        m - the mapping applied to the value
        Throws:
        NullPointerException - if the given value is null
      • add

        protected <T> void add​(org.apache.commons.rdf.api.IRI p,
                               Iterable<T> v,
                               TermMapping<T> m)
        An additive converting singular setter helper for expected cardinality 0..*.
        Type Parameters:
        T - the type of values returned
        Parameters:
        p - the predicate to query
        v - the values to assert as objects in the graph
        m - the mapping applied to the value
        Throws:
        NullPointerException - if the given value is null
        NullPointerException - if the given value contains null elements