Class ObjectSet<T>
- Type Parameters:
T
- the type of elements handled by this set
- All Implemented Interfaces:
Iterable<T>
,Collection<T>
,Set<T>
Set
interface as a dynamic, mutable view over an RDF predicate-object list
(statements that share a subject and a predicate). It is intended for use in classes that wrap
RDF nodes
for strongly typed convenience mapping.
This set does not permit null
elements.
The order of elements returned by this implementation is not guaranteed as it depends on the ordering of query
results in the underlying Graph
. This reflects the unordered nature of RDF graphs.
The synchronization characteristics and time complexity of this implementation are those of the underlying
Graph
implementation. It could well be that read and write operations on instances of this class result in
expensive IO operations. Even simple iteration is most likely to be much less performant than what callers expect
from other Java collections.
The iterators returned by this implementation do not support the Iterator.remove()
operation.
This implementation uses the AbstractSet.equals(Object)
and AbstractSet.hashCode()
operations.
Equality and hashing are dynamic: They depend on the state of the underlying Graph
at the time of calling and
are not fixed when creating the instance.
Example: Given a node wrapper N
, instances of this class can be used to make read/write strongly typed
set properties.
public class N {
public Set<String> getType {
return new PredicateObjectSet<>(
this,
RDF.type,
g,
NodeMappings::asIriResource,
ValueMappings::iriAsString
);
}
}
- Author:
- Samu Lang
-
Field Summary
Modifier and TypeFieldDescriptionprotected final Graph
protected final IRI
protected final BlankNodeOrIRI
protected final TermMapping<T>
protected final ValueMapping<T>
-
Constructor Summary
ConstructorDescriptionObjectSet
(BlankNodeOrIRI subject, IRI predicate, Graph graph, TermMapping<T> termMapping, ValueMapping<T> valueMapping) Constructs a new dynamic set view over the objects of statements that share a predicate and a subject. -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends T> c) void
clear()
boolean
boolean
containsAll
(Collection<?> c) boolean
int
hashCode()
boolean
isEmpty()
iterator()
boolean
boolean
removeAll
(Collection<?> c) boolean
retainAll
(Collection<?> c) int
size()
Object[]
toArray()
<U> U[]
toArray
(U[] a) 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
-
Field Details
-
subject
-
predicate
-
graph
-
termMapping
-
valueMapping
-
-
Constructor Details
-
ObjectSet
public ObjectSet(BlankNodeOrIRI subject, IRI predicate, Graph graph, TermMapping<T> termMapping, ValueMapping<T> valueMapping) Constructs a new dynamic set view over the objects of statements that share a predicate and a subject.- Parameters:
subject
- the subject node shared by all statementspredicate
- the predicate node shared by all statementsgraph
- the graph containing the statementstermMapping
- a mapping from terms to values used for read operations (useTermMappings
for common mappings)valueMapping
- a mapping from values to nodes used for write operations (useValueMappings
for common mappings)- Throws:
NullPointerException
- if any of the arguments are null
-
-
Method Details
-
size
public int size()- Specified by:
size
in interfaceCollection<T>
- Specified by:
size
in interfaceSet<T>
- Specified by:
size
in classAbstractCollection<T>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<T>
- Specified by:
isEmpty
in interfaceSet<T>
- Overrides:
isEmpty
in classAbstractCollection<T>
-
contains
- Specified by:
contains
in interfaceCollection<T>
- Specified by:
contains
in interfaceSet<T>
- Overrides:
contains
in classAbstractCollection<T>
-
iterator
- Specified by:
iterator
in interfaceCollection<T>
- Specified by:
iterator
in interfaceIterable<T>
- Specified by:
iterator
in interfaceSet<T>
- Specified by:
iterator
in classAbstractCollection<T>
- Implementation Note:
- Prior to returning the iterator, this implementation consumes (buffers) an underlying
stream of statements
with the currentsubject
andpredicate
as well as thevalue mapping function
applied to each object.
-
toArray
- Specified by:
toArray
in interfaceCollection<T>
- Specified by:
toArray
in interfaceSet<T>
- Overrides:
toArray
in classAbstractCollection<T>
-
toArray
public <U> U[] toArray(U[] a) - Specified by:
toArray
in interfaceCollection<T>
- Specified by:
toArray
in interfaceSet<T>
- Overrides:
toArray
in classAbstractCollection<T>
-
add
- Specified by:
add
in interfaceCollection<T>
- Specified by:
add
in interfaceSet<T>
- Overrides:
add
in classAbstractCollection<T>
-
remove
- Specified by:
remove
in interfaceCollection<T>
- Specified by:
remove
in interfaceSet<T>
- Overrides:
remove
in classAbstractCollection<T>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<T>
- Specified by:
containsAll
in interfaceSet<T>
- Overrides:
containsAll
in classAbstractCollection<T>
-
addAll
- Specified by:
addAll
in interfaceCollection<T>
- Specified by:
addAll
in interfaceSet<T>
- Overrides:
addAll
in classAbstractCollection<T>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<T>
- Specified by:
retainAll
in interfaceSet<T>
- Overrides:
retainAll
in classAbstractCollection<T>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<T>
- Specified by:
removeAll
in interfaceSet<T>
- Overrides:
removeAll
in classAbstractSet<T>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<T>
- Specified by:
clear
in interfaceSet<T>
- Overrides:
clear
in classAbstractCollection<T>
-
equals
- Specified by:
equals
in interfaceCollection<T>
- Specified by:
equals
in interfaceSet<T>
- Overrides:
equals
in classAbstractSet<T>
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<T>
- Specified by:
hashCode
in interfaceSet<T>
- Overrides:
hashCode
in classAbstractSet<T>
-