Class ObjectSet<T>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<T>
-
- com.inrupt.rdf.wrapping.jena.ObjectSet<T>
-
- Type Parameters:
T- the type of elements handled by this set
- All Implemented Interfaces:
Iterable<T>,Collection<T>,Set<T>
public class ObjectSet<T> extends AbstractSet<T>
This class implements theSetinterface 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 wrapRDF nodesfor strongly typed convenience mapping.This set does not permit
nullelements.The order of elements returned by this implementation is not guaranteed as it depends on the ordering of query results in the underlying
Model. This reflects the unordered nature of RDF graphs.The synchronization characteristics and time complexity of this implementation are those of the underlying
Modelimplementation. 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)andAbstractSet.hashCode()operations. Equality and hashing are dynamic: They depend on the state of the underlyingModelat 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 extends WrapperResource { public Set<String> getType { return new ObjectSet<>( this, RDF.type, NodeMappings::asIriResource, ValueMappings::iriAsString ); } }- Author:
- Samu Lang
-
-
Field Summary
Fields Modifier and Type Field Description protected NodeMapping<T>nodeMappingprotected org.apache.jena.rdf.model.Propertypredicateprotected org.apache.jena.rdf.model.Resourcesubjectprotected ValueMapping<T>valueMapping
-
Constructor Summary
Constructors Constructor Description ObjectSet(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate, NodeMapping<T> nodeMapping, ValueMapping<T> valueMapping)Constructs a new dynamic set view over the objects of statements that share a predicate and an object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(T e)booleanaddAll(Collection<? extends T> c)voidclear()booleancontains(Object o)booleancontainsAll(Collection<?> c)booleanequals(Object o)inthashCode()booleanisEmpty()Iterator<T>iterator()booleanremove(Object o)booleanremoveAll(Collection<?> c)booleanretainAll(Collection<?> c)intsize()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 Detail
-
subject
protected final org.apache.jena.rdf.model.Resource subject
-
predicate
protected final org.apache.jena.rdf.model.Property predicate
-
nodeMapping
protected final NodeMapping<T> nodeMapping
-
valueMapping
protected final ValueMapping<T> valueMapping
-
-
Constructor Detail
-
ObjectSet
public ObjectSet(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate, NodeMapping<T> nodeMapping, ValueMapping<T> valueMapping)Constructs a new dynamic set view over the objects of statements that share a predicate and an object.- Parameters:
subject- the subject node shared by all statementspredicate- the predicate node shared by all statementsnodeMapping- a mapping from nodes to values used for read operations (useNodeMappingsfor common mappings)valueMapping- a mapping from values to nodes used for write operations (useValueMappingsfor common mappings)- Throws:
NullPointerException- if any of the arguments are nullorg.apache.jena.rdf.model.HasNoModelException- ifsubjectdoes not have an associatedModel
-
-
Method Detail
-
size
public int size()
- Specified by:
sizein interfaceCollection<T>- Specified by:
sizein interfaceSet<T>- Specified by:
sizein classAbstractCollection<T>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<T>- Specified by:
isEmptyin interfaceSet<T>- Overrides:
isEmptyin classAbstractCollection<T>
-
contains
public boolean contains(Object o)
- Specified by:
containsin interfaceCollection<T>- Specified by:
containsin interfaceSet<T>- Overrides:
containsin classAbstractCollection<T>
-
toArray
public Object[] toArray()
- Specified by:
toArrayin interfaceCollection<T>- Specified by:
toArrayin interfaceSet<T>- Overrides:
toArrayin classAbstractCollection<T>
-
toArray
public <U> U[] toArray(U[] a)
- Specified by:
toArrayin interfaceCollection<T>- Specified by:
toArrayin interfaceSet<T>- Overrides:
toArrayin classAbstractCollection<T>
-
add
public boolean add(T e)
- Specified by:
addin interfaceCollection<T>- Specified by:
addin interfaceSet<T>- Overrides:
addin classAbstractCollection<T>
-
remove
public boolean remove(Object o)
- Specified by:
removein interfaceCollection<T>- Specified by:
removein interfaceSet<T>- Overrides:
removein classAbstractCollection<T>
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAllin interfaceCollection<T>- Specified by:
containsAllin interfaceSet<T>- Overrides:
containsAllin classAbstractCollection<T>
-
addAll
public boolean addAll(Collection<? extends T> c)
- Specified by:
addAllin interfaceCollection<T>- Specified by:
addAllin interfaceSet<T>- Overrides:
addAllin classAbstractCollection<T>
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAllin interfaceCollection<T>- Specified by:
retainAllin interfaceSet<T>- Overrides:
retainAllin classAbstractCollection<T>
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAllin interfaceCollection<T>- Specified by:
removeAllin interfaceSet<T>- Overrides:
removeAllin classAbstractSet<T>
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<T>- Specified by:
clearin interfaceSet<T>- Overrides:
clearin classAbstractCollection<T>
-
equals
public boolean equals(Object o)
- Specified by:
equalsin interfaceCollection<T>- Specified by:
equalsin interfaceSet<T>- Overrides:
equalsin classAbstractSet<T>
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceCollection<T>- Specified by:
hashCodein interfaceSet<T>- Overrides:
hashCodein classAbstractSet<T>
-
-