Class DynamicModel
- All Implemented Interfaces:
Serializable
,Iterable<Statement>
,Collection<Statement>
,Set<Statement>
,Model
,NamespaceAware
- Author:
- HÃ¥vard Mikkelsen Ottestad
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds one or more statements to the model.boolean
boolean
addAll
(Collection<? extends Statement> c) void
clear()
boolean
Removes statements with the specified context exist in this model.boolean
boolean
Determines if statements with the specified subject, predicate, object and (optionally) context exist in this model.boolean
containsAll
(Collection<?> c) contexts()
Returns aSet
view of the contexts contained in this model.boolean
Returns a filtered view of the statements with the specified subject, predicate, object and (optionally) context.getNamespace
(String prefix) Gets the namespace that is associated with the specified prefix, if any.Gets the set that contains the assigned namespaces.getStatements
(Resource subject, IRI predicate, Value object, Resource... contexts) int
hashCode()
boolean
isEmpty()
iterator()
objects()
Returns aSet
view of the objects contained in this model.Returns aSet
view of the predicates contained in this model.boolean
boolean
Removes statements with the specified subject, predicate, object and (optionally) context exist in this model.boolean
removeAll
(Collection<?> c) removeNamespace
(String prefix) Removes a namespace declaration by removing the association between a prefix and a namespace name.boolean
retainAll
(Collection<?> c) setNamespace
(String prefix, String name) Sets the prefix for a namespace.void
setNamespace
(Namespace namespace) Sets the prefix for a namespace.int
size()
subjects()
Returns aSet
view of the subjects contained in this model.Object[]
toArray()
<T> T[]
toArray
(T[] a) Returns an unmodifiable view of this model.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 java.util.Set
spliterator
-
Constructor Details
-
DynamicModel
-
-
Method Details
-
unmodifiable
Description copied from interface:Model
Returns an unmodifiable view of this model. This method provides "read-only" access to this model. Query operations on the returned model "read through" to this model, and attempts to modify the returned model, whether direct or via its iterator, result in anUnsupportedOperationException
.- Specified by:
unmodifiable
in interfaceModel
- Returns:
- an unmodifiable view of the specified set.
-
getNamespace
Description copied from interface:NamespaceAware
Gets 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.- Specified by:
getNamespace
in interfaceNamespaceAware
- 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
Description copied from interface:NamespaceAware
Gets the set that contains the assigned namespaces.- Specified by:
getNamespaces
in interfaceNamespaceAware
- Returns:
- A
Set
containing theNamespace
objects that are available.
-
setNamespace
Description copied from interface:Model
Sets the prefix for a namespace. This will replace any existing namespace associated to the prefix.- Specified by:
setNamespace
in interfaceModel
- Parameters:
prefix
- The new prefix.name
- The namespace name that the prefix maps to.- Returns:
- The
Namespace
object for the given namespace.
-
setNamespace
Description copied from interface:Model
Sets the prefix for a namespace. This will replace any existing namespace associated to the prefix.- Specified by:
setNamespace
in interfaceModel
- Parameters:
namespace
- ANamespace
object to use in this Model.
-
removeNamespace
Description copied from interface:Model
Removes a namespace declaration by removing the association between a prefix and a namespace name.- Specified by:
removeNamespace
in interfaceModel
- 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()
-
contains
Description copied from interface:Model
Determines if statements with the specified subject, predicate, object and (optionally) context exist in this model. Thesubject
,predicate
andobject
parameters can benull
to indicate wildcards. Thecontexts
parameter 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 valuenull
and 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
,c2
orc3
.- Specified by:
contains
in interfaceModel
- Parameters:
subj
- The subject of the statements to match,null
to match statements with any subject.pred
- The predicate of the statements to match,null
to match statements with any predicate.obj
- The object of the statements to match,null
to 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:
true
if statements match the specified pattern.
-
add
Description copied from interface:Model
Adds 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. -
clear
Description copied from interface:Model
Removes statements with the specified context exist in this model. -
remove
Description copied from interface:Model
Removes statements with the specified subject, predicate, object and (optionally) context exist in this model. Thesubject
,predicate
andobject
parameters can benull
to indicate wildcards. Thecontexts
parameter 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 valuenull
and 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
,c2
orc3
.- Specified by:
remove
in interfaceModel
- Parameters:
subj
- The subject of the statements to remove,null
to remove statements with any subject.pred
- The predicate of the statements to remove,null
to remove statements with any predicate.obj
- The object of the statements to remove,null
to 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:
true
if one or more statements have been removed.
-
filter
Description copied from interface:Model
Returns a filtered view of the statements with the specified subject, predicate, object and (optionally) context. Thesubject
,predicate
andobject
parameters can benull
to indicate wildcards. Thecontexts
parameter 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 valuenull
and 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
remove
operation), 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
, andclear
operations. The statements passed to theadd
andaddAll
operations 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
,c2
orc3
.- Specified by:
filter
in interfaceModel
- Parameters:
subj
- The subject of the statements to match,null
to match statements with any subject.pred
- The predicate of the statements to match,null
to match statements with any predicate.obj
- The object of the statements to match,null
to 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:
-
subjects
Description copied from interface:Model
Returns aSet
view of the subjects contained in this model. The set is backed by the model, so changes to the model are reflected in the set, and vice-versa. If the model is modified while an iteration over the set is in progress (except through the iterator's ownremove
operation), the results of the iteration are undefined. The set supports element removal, which removes all statements from the model for which that element is a subject value, via theIterator.remove
,Set.remove
,removeAll
,retainAll
, andclear
operations. It does not support theadd
oraddAll
operations if the parameterspred
orobj
are null. -
predicates
Description copied from interface:Model
Returns aSet
view of the predicates contained in this model. The set is backed by the model, so changes to the model are reflected in the set, and vice-versa. If the model is modified while an iteration over the set is in progress (except through the iterator's ownremove
operation), the results of the iteration are undefined. The set supports element removal, which removes all statements from the model for which that element is a predicate value, via theIterator.remove
,Set.remove
,removeAll
,retainAll
, andclear
operations. It does not support theadd
oraddAll
operations if the parameterssubj
orobj
are null.- Specified by:
predicates
in interfaceModel
- Returns:
- a set view of the predicates contained in this model
-
objects
Description copied from interface:Model
Returns aSet
view of the objects contained in this model. The set is backed by the model, so changes to the model are reflected in the set, and vice-versa. If the model is modified while an iteration over the set is in progress (except through the iterator's ownremove
operation), the results of the iteration are undefined. The set supports element removal, which removes all statements from the model for which that element is an object value, via theIterator.remove
,Set.remove
,removeAll
,retainAll
, andclear
operations. It does not support theadd
oraddAll
operations if the parameterssubj
orpred
are null. -
contexts
Description copied from interface:Model
Returns aSet
view of the contexts contained in this model. The set is backed by the model, so changes to the model are reflected in the set, and vice-versa. If the model is modified while an iteration over the set is in progress (except through the iterator's ownremove
operation), the results of the iteration are undefined. The set supports element removal, which removes all statements from the model for which that element is a context value, via theIterator.remove
,Set.remove
,removeAll
,retainAll
, andclear
operations. It does not support theadd
oraddAll
operations if the parameterssubj
,pred
orobj
are null. -
size
public int size()- Specified by:
size
in interfaceCollection<Statement>
- Specified by:
size
in interfaceSet<Statement>
- Specified by:
size
in classAbstractCollection<Statement>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<Statement>
- Specified by:
isEmpty
in interfaceSet<Statement>
- Overrides:
isEmpty
in classAbstractCollection<Statement>
-
contains
- Specified by:
contains
in interfaceCollection<Statement>
- Specified by:
contains
in interfaceSet<Statement>
- Overrides:
contains
in classAbstractCollection<Statement>
-
iterator
-
toArray
- Specified by:
toArray
in interfaceCollection<Statement>
- Specified by:
toArray
in interfaceSet<Statement>
- Overrides:
toArray
in classAbstractCollection<Statement>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArray
in interfaceCollection<Statement>
- Specified by:
toArray
in interfaceSet<Statement>
- Overrides:
toArray
in classAbstractCollection<Statement>
-
add
- Specified by:
add
in interfaceCollection<Statement>
- Specified by:
add
in interfaceSet<Statement>
- Overrides:
add
in classAbstractCollection<Statement>
-
remove
- Specified by:
remove
in interfaceCollection<Statement>
- Specified by:
remove
in interfaceSet<Statement>
- Overrides:
remove
in classAbstractCollection<Statement>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<Statement>
- Specified by:
containsAll
in interfaceSet<Statement>
- Overrides:
containsAll
in classAbstractCollection<Statement>
-
addAll
- Specified by:
addAll
in interfaceCollection<Statement>
- Specified by:
addAll
in interfaceSet<Statement>
- Overrides:
addAll
in classAbstractCollection<Statement>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<Statement>
- Specified by:
retainAll
in interfaceSet<Statement>
- Overrides:
retainAll
in classAbstractCollection<Statement>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<Statement>
- Specified by:
removeAll
in interfaceSet<Statement>
- Overrides:
removeAll
in classAbstractSet<Statement>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<Statement>
- Specified by:
clear
in interfaceSet<Statement>
- Overrides:
clear
in classAbstractCollection<Statement>
-
getStatements
public Iterable<Statement> getStatements(Resource subject, IRI predicate, Value object, Resource... contexts) Description copied from interface:Model
Returns anIterable
over allStatement
s in this Model that match the supplied criteria.Examples:
model.getStatements(s1, null, null)
matches all statements that have subjects1
model.getStatements(s1, p1, null)
matches all statements that have subjects1
and predicatep1
model.getStatements(null, null, null, c1)
matches all statements that have contextc1
model.getStatements(null, null, null, (Resource)null)
matches all statements that have no associated contextmodel.getStatements(null, null, null, c1, c2, c3)
matches all statements that have contextc1
,c2
orc3
- Specified by:
getStatements
in interfaceModel
- Parameters:
subject
- The subject of the statements to match,null
to match statements with any subject.predicate
- The predicate of the statements to match,null
to match statements with any predicate.object
- The object of the statements to match,null
to 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 any one of these will match. To match statements without an associated context, specify the valuenull
and explicitly cast it to typeResource
.- Returns:
- an
Iterable
over the statements in this Model that match the specified pattern. - See Also:
-
equals
- Specified by:
equals
in interfaceCollection<Statement>
- Specified by:
equals
in interfaceSet<Statement>
- Overrides:
equals
in classAbstractSet<Statement>
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<Statement>
- Specified by:
hashCode
in interfaceSet<Statement>
- Overrides:
hashCode
in classAbstractSet<Statement>
-