Class DistinctModelReducingUnionIteration
- java.lang.Object
-
- org.eclipse.rdf4j.common.iteration.AbstractCloseableIteration<E,X>
-
- org.eclipse.rdf4j.common.iteration.LookAheadIteration<Statement,SailException>
-
- org.eclipse.rdf4j.sail.base.DistinctModelReducingUnionIteration
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,CloseableIteration<Statement,SailException>
,Iteration<Statement,SailException>
public class DistinctModelReducingUnionIteration extends LookAheadIteration<Statement,SailException>
An Iteration that takes two source. An iterator and a model.
For every statement returned by the iterator, that statement is removed from the model. Once the iterator is exhausted, a new filteredStatementsIterator is created by applying the filterable function to the model.
The point of this iteration is to create a distinct iterator that produces only distinct results in a lazy and mutable manner. This is useful when iterating in a transaction, since the user may have added duplicate statements. On a potential second iteration there will be no need for further deduplication, since the initial deduplication was mutable.
Model will throw a ConcurrentModificationException if two threads call .remove(...) at the same time or one thread calls .next() on an iterator while another calls .remove(...). This is resolved by synchronizing access to the model and by consuming the entire iterator into an ArrayList, effectively caching the filtered part of the model in memory. There is no overflow to disk for this cache.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.function.Consumer<Statement>
approvedRemover
private java.util.function.Supplier<java.lang.Iterable<Statement>>
approvedSupplier
private java.util.Iterator<? extends Statement>
filteredStatementsIterator
private CloseableIteration<? extends Statement,SailException>
iterator
-
Constructor Summary
Constructors Constructor Description DistinctModelReducingUnionIteration(CloseableIteration<? extends Statement,SailException> iterator, java.util.function.Consumer<Statement> approvedRemover, java.util.function.Supplier<java.lang.Iterable<Statement>> approvedSupplier)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Statement
getNextElement()
Gets the next element.protected void
handleClose()
Called byAbstractCloseableIteration.close()
when it is called for the first time.-
Methods inherited from class org.eclipse.rdf4j.common.iteration.LookAheadIteration
hasNext, next, remove
-
Methods inherited from class org.eclipse.rdf4j.common.iteration.AbstractCloseableIteration
close, isClosed
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.rdf4j.common.iteration.CloseableIteration
stream
-
-
-
-
Field Detail
-
iterator
private final CloseableIteration<? extends Statement,SailException> iterator
-
approvedRemover
private final java.util.function.Consumer<Statement> approvedRemover
-
approvedSupplier
private final java.util.function.Supplier<java.lang.Iterable<Statement>> approvedSupplier
-
filteredStatementsIterator
private java.util.Iterator<? extends Statement> filteredStatementsIterator
-
-
Constructor Detail
-
DistinctModelReducingUnionIteration
DistinctModelReducingUnionIteration(CloseableIteration<? extends Statement,SailException> iterator, java.util.function.Consumer<Statement> approvedRemover, java.util.function.Supplier<java.lang.Iterable<Statement>> approvedSupplier)
-
-
Method Detail
-
getNextElement
protected Statement getNextElement() throws SailException
Description copied from class:LookAheadIteration
Gets the next element. Subclasses should implement this method so that it returns the next element.- Specified by:
getNextElement
in classLookAheadIteration<Statement,SailException>
- Returns:
- The next element, or null if no more elements are available.
- Throws:
SailException
-
handleClose
protected void handleClose() throws SailException
Description copied from class:AbstractCloseableIteration
Called byAbstractCloseableIteration.close()
when it is called for the first time. This method is only called once on each iteration. By default, this method does nothing.- Overrides:
handleClose
in classLookAheadIteration<Statement,SailException>
- Throws:
SailException
-
-