Class MemValueFactory

  • All Implemented Interfaces:
    ValueFactory

    public class MemValueFactory
    extends AbstractValueFactory
    A factory for MemValue objects that keeps track of created objects to prevent the creation of duplicate objects, minimizing memory usage as a result.
    • Field Detail

      • iriRegistry

        private final WeakObjectRegistry<IRI,​MemIRI> iriRegistry
        Registry containing the set of MemURI objects as used by a MemoryStore. This registry enables the reuse of objects, minimizing the number of objects in main memory.
      • tripleRegistry

        private final WeakObjectRegistry<Triple,​MemTriple> tripleRegistry
        Registry containing the set of MemTriple objects as used by a MemoryStore. This registry enables the reuse of objects, minimizing the number of objects in main memory.
      • bnodeRegistry

        private final WeakObjectRegistry<BNode,​MemBNode> bnodeRegistry
        Registry containing the set of MemBNode objects as used by a MemoryStore. This registry enables the reuse of objects, minimizing the number of objects in main memory.
      • literalRegistry

        private final WeakObjectRegistry<Literal,​MemLiteral> literalRegistry
        Registry containing the set of MemLiteral objects as used by a MemoryStore. This registry enables the reuse of objects, minimizing the number of objects in main memory.
      • namespaceRegistry

        private final WeakObjectRegistry<java.lang.String,​java.lang.String> namespaceRegistry
        Registry containing the set of namespce strings as used by MemURI objects in a MemoryStore. This registry enables the reuse of objects, minimizing the number of objects in main memory.
    • Constructor Detail

      • MemValueFactory

        public MemValueFactory()
        A cache of the most common IRIs to improve lookup performance when users use our vocabularies (eg. RDF.TYPE).
    • Method Detail

      • clear

        public void clear()
      • getMemValue

        public MemValue getMemValue​(Value value)
        Returns a previously created MemValue that is equal to the supplied value, or null if the supplied value is a new value or is equal to null.
        Parameters:
        value - The MemValue equivalent of the supplied value, or null.
        Returns:
        A previously created MemValue that is equal to value, or null if no such value exists or if value is equal to null.
      • getMemResource

        public MemResource getMemResource​(Resource resource)
        See getMemValue() for description.
      • getMemURI

        public MemIRI getMemURI​(IRI uri)
        See getMemValue() for description.
      • getMemBNode

        public MemBNode getMemBNode​(BNode bnode)
        See getMemValue() for description.
      • getMemLiteral

        public MemLiteral getMemLiteral​(Literal literal)
        See getMemValue() for description.
      • isOwnMemBnode

        private boolean isOwnMemBnode​(BNode value)
        Checks whether the supplied value is an instance of MemValue and whether it has been created by this MemValueFactory.
      • isOwnMemLiteral

        private boolean isOwnMemLiteral​(Literal value)
      • isOwnMemTriple

        private boolean isOwnMemTriple​(Triple value)
      • isOwnMemIRI

        private boolean isOwnMemIRI​(IRI value)
      • getMemURIs

        @Deprecated(forRemoval=true,
                    since="4.0.0")
        public java.util.Set<MemIRI> getMemURIs()
        Deprecated, for removal: This API element is subject to removal in a future version.
        Use getMemIRIsIterator() instead.
        Gets all URIs that are managed by this value factory.

        Warning: This method is not synchronized.

        Returns:
        An unmodifiable Set of MemURI objects.
      • getMemBNodes

        @Deprecated(forRemoval=true,
                    since="4.0.0")
        public java.util.Set<MemBNode> getMemBNodes()
        Deprecated, for removal: This API element is subject to removal in a future version.
        Use getMemBNodesIterator() instead.
        Gets all bnodes that are managed by this value factory.

        Warning: This method is not synchronized.

        Returns:
        An unmodifiable Set of MemBNode objects.
      • getMemLiterals

        @Deprecated(forRemoval=true,
                    since="4.0.0")
        public java.util.Set<MemLiteral> getMemLiterals()
        Deprecated, for removal: This API element is subject to removal in a future version.
        Use getMemLiteralsIterator() instead.
        Gets all literals that are managed by this value factory.

        Warning: This method is not synchronized.

        Returns:
        An unmodifiable Set of MemURI objects.
      • getOrCreateMemValue

        public MemValue getOrCreateMemValue​(Value value)
        Gets or creates a MemValue for the supplied Value. If the factory already contains a MemValue object that is equivalent to the supplied value then this equivalent value will be returned. Otherwise a new MemValue will be created, stored for future calls and then returned.
        Parameters:
        value - A Resource or Literal.
        Returns:
        The existing or created MemValue.
      • createIRI

        public IRI createIRI​(java.lang.String uri)
        Description copied from interface: ValueFactory
        Creates a new IRI from the supplied string-representation.
        Specified by:
        createIRI in interface ValueFactory
        Overrides:
        createIRI in class AbstractValueFactory
        Parameters:
        uri - A string-representation of a IRI.
        Returns:
        An object representing the IRI.
      • createIRI

        public IRI createIRI​(java.lang.String namespace,
                             java.lang.String localName)
        Description copied from interface: ValueFactory
        Creates a new IRI from the supplied namespace and local name. Calling this method is funtionally equivalent to calling createIRI(namespace+localName), but allows the ValueFactory to reuse supplied namespace and local name strings whenever possible. Note that the values returned by IRI.getNamespace() and IRI.getLocalName() are not necessarily the same as the values that are supplied to this method.
        Specified by:
        createIRI in interface ValueFactory
        Overrides:
        createIRI in class AbstractValueFactory
        Parameters:
        namespace - The IRI's namespace.
        localName - The IRI's local name.
      • createBNode

        public BNode createBNode​(java.lang.String nodeID)
        Description copied from interface: ValueFactory
        Creates a new blank node with the given node identifier.
        Specified by:
        createBNode in interface ValueFactory
        Overrides:
        createBNode in class AbstractValueFactory
        Parameters:
        nodeID - The blank node identifier.
        Returns:
        An object representing the blank node.
      • createLiteral

        public Literal createLiteral​(java.lang.String value,
                                     java.lang.String language)
        Description copied from interface: ValueFactory
        Creates a new literal with the supplied label and language attribute. The return value of Literal.getDatatype() for the returned object must be rdf:langString.
        Specified by:
        createLiteral in interface ValueFactory
        Overrides:
        createLiteral in class AbstractValueFactory
        Parameters:
        value - The literal's label, must not be null.
        language - The literal's language attribute, must not be null.
        Returns:
        A literal for the specified value and language attribute.
      • createLiteral

        public Literal createLiteral​(java.lang.String value,
                                     IRI datatype)
        Description copied from interface: ValueFactory
        Creates a new literal with the supplied label and datatype.
        Specified by:
        createLiteral in interface ValueFactory
        Overrides:
        createLiteral in class AbstractValueFactory
        Parameters:
        value - The literal's label, must not be null.
        datatype - The literal's datatype. If it is null, the datatype xsd:string will be assigned to this literal.
        Returns:
        A literal for the specified value and type.
      • createLiteral

        public Literal createLiteral​(boolean value)
        Description copied from interface: ValueFactory
        Creates a new xsd:boolean-typed literal representing the specified value.
        Specified by:
        createLiteral in interface ValueFactory
        Overrides:
        createLiteral in class AbstractValueFactory
        Parameters:
        value - The value for the literal.
        Returns:
        An xsd:boolean-typed literal for the specified value.
      • createLiteral

        public Literal createLiteral​(javax.xml.datatype.XMLGregorianCalendar calendar)
        Description copied from interface: ValueFactory
        Creates a new literal representing the specified calendar that is typed using the appropriate XML Schema date/time datatype.
        Specified by:
        createLiteral in interface ValueFactory
        Overrides:
        createLiteral in class AbstractValueFactory
        Parameters:
        calendar - The value for the literal.
        Returns:
        A typed literal for the specified calendar.
      • createTriple

        public Triple createTriple​(Resource subject,
                                   IRI predicate,
                                   Value object)
        Description copied from interface: ValueFactory
        Creates a new RDF-star triple with the supplied subject, predicate and object.
        Specified by:
        createTriple in interface ValueFactory
        Overrides:
        createTriple in class AbstractValueFactory
        Parameters:
        subject - The statement's subject.
        predicate - The statement's predicate.
        object - The statement's object.
        Returns:
        The created triple.