Class LinkedHashModel
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<Statement>
-
- org.eclipse.rdf4j.model.impl.AbstractModel
-
- org.eclipse.rdf4j.model.impl.LinkedHashModel
-
- All Implemented Interfaces:
Serializable,Iterable<Statement>,Collection<Statement>,Set<Statement>,Model,NamespaceAware
public class LinkedHashModel extends AbstractModel
Hash table based implementation of theModelinterface.This implementation provides constant-time performance for filters using a single term, assuming the hash function disperses the elements properly among the buckets. Each term is indexed using a
HashMap. When multiple terms are provided in a filter the index, of the term that reduces the possibleStatements the most, is used and a sequential scan is used to filter additional terms.Note that this implementation is not synchronized. If multiple threads access a model concurrently, and at least one of the threads modifies the model, it must be synchronized externally. This is typically accomplished by synchronizing on some object that naturally encapsulates the model. If no such object exists, the set should be "wrapped" using the * Models.synchronizedModel method.
- Author:
- James Leigh
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLinkedHashModel.ModelStatement
-
Constructor Summary
Constructors Constructor Description LinkedHashModel()LinkedHashModel(int size)LinkedHashModel(Collection<? extends Statement> c)LinkedHashModel(Set<Namespace> namespaces)LinkedHashModel(Set<Namespace> namespaces, int size)LinkedHashModel(Set<Namespace> namespaces, Collection<? extends Statement> c)LinkedHashModel(Model model)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(Resource subj, IRI pred, Value obj, Resource... contexts)Adds one or more statements to the model.booleanadd(Statement statement)voidclear()booleancontains(Object o)booleancontains(Resource subj, IRI pred, Value obj, Resource... contexts)Determines if statements with the specified subject, predicate, object and (optionally) context exist in this model.Modelfilter(Resource subj, IRI pred, Value obj, Resource... contexts)Returns a filtered view of the statements with the specified subject, predicate, object and (optionally) context.Optional<Namespace>getNamespace(String prefix)Gets the namespace that is associated with the specified prefix, if any.Set<Namespace>getNamespaces()Gets the set that contains the assigned namespaces.booleanisEmpty()Iteratoriterator()booleanremove(Resource subj, IRI pred, Value obj, Resource... contexts)Removes statements with the specified subject, predicate, object and (optionally) context exist in this model.Optional<Namespace>removeNamespace(String prefix)Removes a namespace declaration by removing the association between a prefix and a namespace name.voidremoveTermIteration(Iterator iterator, Resource subj, IRI pred, Value obj, Resource... contexts)Called by aggregate sets when a term has been removed from a term iterator.NamespacesetNamespace(String prefix, String name)Sets the prefix for a namespace.voidsetNamespace(Namespace namespace)Sets the prefix for a namespace.intsize()-
Methods inherited from class org.eclipse.rdf4j.model.impl.AbstractModel
addAll, clear, closeIterator, containsAll, contexts, objects, predicates, remove, removeAll, retainAll, subjects, toArray, toArray, unmodifiable
-
Methods inherited from class java.util.AbstractSet
equals, hashCode
-
Methods inherited from class java.util.AbstractCollection
toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface org.eclipse.rdf4j.model.Model
getStatements
-
Methods inherited from interface java.util.Set
equals, hashCode, spliterator
-
-
-
-
Constructor Detail
-
LinkedHashModel
public LinkedHashModel()
-
LinkedHashModel
public LinkedHashModel(Model model)
-
LinkedHashModel
public LinkedHashModel(Collection<? extends Statement> c)
-
LinkedHashModel
public LinkedHashModel(int size)
-
LinkedHashModel
public LinkedHashModel(Set<Namespace> namespaces, Collection<? extends Statement> c)
-
-
Method Detail
-
getNamespace
public Optional<Namespace> getNamespace(String prefix)
Description copied from interface:NamespaceAwareGets the namespace that is associated with the specified prefix, if any. If multiple namespaces match the given prefix, the result may not be consistent over successive calls to this method.- Parameters:
prefix- A namespace prefix.- Returns:
- The namespace name that is associated with the specified prefix, or
Optional.empty()if there is no such namespace.
-
getNamespaces
public Set<Namespace> getNamespaces()
Description copied from interface:NamespaceAwareGets the set that contains the assigned namespaces.
-
setNamespace
public Namespace setNamespace(String prefix, String name)
Description copied from interface:ModelSets the prefix for a namespace. This will replace any existing namespace associated to the prefix.- Parameters:
prefix- The new prefix.name- The namespace name that the prefix maps to.- Returns:
- The
Namespaceobject for the given namespace.
-
setNamespace
public void setNamespace(Namespace namespace)
Description copied from interface:ModelSets the prefix for a namespace. This will replace any existing namespace associated to the prefix.- Parameters:
namespace- ANamespaceobject to use in this Model.
-
removeNamespace
public Optional<Namespace> removeNamespace(String prefix)
Description copied from interface:ModelRemoves a namespace declaration by removing the association between a prefix and a namespace name.- Parameters:
prefix- The namespace prefix of which the assocation with a namespace name is to be removed.- Returns:
- the previous namespace bound to the prefix or
Optional.empty()
-
size
public int size()
- Specified by:
sizein interfaceCollection<Statement>- Specified by:
sizein interfaceSet<Statement>- Specified by:
sizein classAbstractCollection<Statement>
-
add
public boolean add(Statement statement)
- Specified by:
addin interfaceCollection<Statement>- Specified by:
addin interfaceSet<Statement>- Overrides:
addin classAbstractModel
-
add
public boolean add(Resource subj, IRI pred, Value obj, Resource... contexts)
Description copied from interface:ModelAdds one or more statements to the model. This method creates a statement for each specified context and adds those to the model. If no contexts are specified, a single statement with no associated context is added. If this Model is a filtered Model then null (if context empty) values are permitted and will use the corresponding filtered values.- Parameters:
subj- The statement's subject.pred- The statement's predicate.obj- The statement's object.contexts- The contexts to add statements to.
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<Statement>- Specified by:
clearin interfaceSet<Statement>- Overrides:
clearin classAbstractModel
-
contains
public boolean contains(Object o)
- Specified by:
containsin interfaceCollection<Statement>- Specified by:
containsin interfaceSet<Statement>- Overrides:
containsin classAbstractModel
-
iterator
public Iterator iterator()
-
contains
public boolean contains(Resource subj, IRI pred, Value obj, Resource... contexts)
Description copied from interface:ModelDetermines if statements with the specified subject, predicate, object and (optionally) context exist in this model. Thesubject,predicateandobjectparameters can benullto indicate wildcards. Thecontextsparameter is a wildcard and accepts zero or more values. If no contexts are specified, statements will match disregarding their context. If one or more contexts are specified, statements with a context matching one of these will match. Note: to match statements without an associated context, specify the valuenulland explicitly cast it to typeResource.Examples:
model.contains(s1, null, null)is true if any statements in this model have subjects1,
model.contains(null, null, null, c1)is true if any statements in this model have contextc1,
model.contains(null, null, null, (Resource)null)is true if any statements in this model have no associated context,
model.contains(null, null, null, c1, c2, c3)is true if any statements in this model have contextc1,c2orc3.- Parameters:
subj- The subject of the statements to match,nullto match statements with any subject.pred- The predicate of the statements to match,nullto match statements with any predicate.obj- The object of the statements to match,nullto match statements with any object.contexts- The contexts of the statements to match. If no contexts are specified, statements will match disregarding their context. If one or more contexts are specified, statements with a context matching one of these will match.- Returns:
trueif statements match the specified pattern.
-
remove
public boolean remove(Resource subj, IRI pred, Value obj, Resource... contexts)
Description copied from interface:ModelRemoves statements with the specified subject, predicate, object and (optionally) context exist in this model. Thesubject,predicateandobjectparameters can benullto indicate wildcards. Thecontextsparameter is a wildcard and accepts zero or more values. If no contexts are specified, statements will be removed disregarding their context. If one or more contexts are specified, statements with a context matching one of these will be removed. Note: to remove statements without an associated context, specify the valuenulland explicitly cast it to typeResource.Examples:
model.remove(s1, null, null)removes any statements in this model have subjects1,
model.remove(null, null, null, c1)removes any statements in this model have contextc1,
model.remove(null, null, null, (Resource)null)removes any statements in this model have no associated context,
model.remove(null, null, null, c1, c2, c3)removes any statements in this model have contextc1,c2orc3.- Parameters:
subj- The subject of the statements to remove,nullto remove statements with any subject.pred- The predicate of the statements to remove,nullto remove statements with any predicate.obj- The object of the statements to remove,nullto remove statements with any object.contexts- The contexts of the statements to remove. If no contexts are specified, statements will be removed disregarding their context. If one or more contexts are specified, statements with a context matching one of these will be removed.- Returns:
trueif one or more statements have been removed.
-
filter
public Model filter(Resource subj, IRI pred, Value obj, Resource... contexts)
Description copied from interface:ModelReturns a filtered view of the statements with the specified subject, predicate, object and (optionally) context. Thesubject,predicateandobjectparameters can benullto indicate wildcards. Thecontextsparameter is a wildcard and accepts zero or more values. If no contexts are specified, statements will match disregarding their context. If one or more contexts are specified, statements with a context matching one of these will match. Note: to match statements without an associated context, specify the valuenulland explicitly cast it to typeResource.The returned model is backed by this Model, so changes to this Model are reflected in the returned model, and vice-versa. If this Model is modified while an iteration over the returned model is in progress (except through the iterator's own
removeoperation), the results of the iteration are undefined. The model supports element removal, which removes the corresponding statement from this Model, via theIterator.remove,Set.remove,removeAll,retainAll, andclearoperations. The statements passed to theaddandaddAlloperations must match the parameter pattern.Examples:
model.filter(s1, null, null)matches all statements that have subjects1,
model.filter(null, null, null, c1)matches all statements that have contextc1,
model.filter(null, null, null, (Resource)null)matches all statements that have no associated context,
model.filter(null, null, null, c1, c2, c3)matches all statements that have contextc1,c2orc3.- Parameters:
subj- The subject of the statements to match,nullto match statements with any subject.pred- The predicate of the statements to match,nullto match statements with any predicate.obj- The object of the statements to match,nullto match statements with any object.contexts- The contexts of the statements to match. If no contexts are specified, statements will match disregarding their context. If one or more contexts are specified, statements with a context matching one of these will match.- Returns:
- The statements that match the specified pattern.
- See Also:
Model.getStatements(Resource, IRI, Value, Resource...)
-
removeTermIteration
public void removeTermIteration(Iterator iterator, Resource subj, IRI pred, Value obj, Resource... contexts)
Description copied from class:AbstractModelCalled by aggregate sets when a term has been removed from a term iterator. Exactly one of the last four terms will be non-empty.- Specified by:
removeTermIterationin classAbstractModel- Parameters:
iterator- The iterator used to navigate the live set (never null)subj- the subject term to be removed or nullpred- the predicate term to be removed or nullobj- the object term to be removed or nullcontexts- an array of one context term to be removed or an empty array
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<Statement>- Specified by:
isEmptyin interfaceSet<Statement>- Overrides:
isEmptyin classAbstractModel
-
-