Class MemStatementIterator
- java.lang.Object
-
- org.eclipse.rdf4j.sail.memory.model.MemStatementIterator
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,CloseableIteration<MemStatement,SailException>
,Iteration<MemStatement,SailException>
public class MemStatementIterator extends java.lang.Object implements CloseableIteration<MemStatement,SailException>
A StatementIterator that can iterate over a list of Statement objects. This iterator compares Resource and Literal objects using the '==' operator, which is possible thanks to the extensive sharing of these objects in the MemoryStore.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
MemStatementIterator.Stats
-
Field Summary
Fields Modifier and Type Field Description private int
cachedHashCode
private boolean
closed
Flag indicating whether this iteration has been closed.private MemResource[]
contexts
The context of statements to return, or null if any context is OK.private boolean
explicit
Flag indicating whether this iterator should only return explicitly added statements or only return inferred statements.private boolean
explicitNotSpecified
private MemStatementIteratorCache
iteratorCache
private int
matchingStatements
The number of returned statementsstatic int
MIN_SIZE_TO_CONSIDER_FOR_CACHE
private MemStatement
nextElement
private boolean
noIsolation
private MemValue
object
The object of statements to return, or null if any object is OK.private MemIRI
predicate
The predicate of statements to return, or null if any predicate is OK.private int
snapshot
Indicates which snapshot should be iterated over.private int
statementIndex
The index of the last statement that has been returned.private MemStatement[]
statementList
private int
statementListSize
The lists of statements over which to iterate, and its size (different from length).private MemResource
subject
The subject of statements to return, or null if any subject is OK.
-
Constructor Summary
Constructors Constructor Description MemStatementIterator(MemStatementList statementList, MemResource subject, MemIRI predicate, MemValue object, java.lang.Boolean explicit, int snapshot, MemStatementIteratorCache iteratorCache, MemResource... contexts)
Creates a new MemStatementIterator that will iterate over the statements contained in the supplied MemStatementList searching for statements that match the specified pattern of subject, predicate, object and context(s).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static CloseableIteration<MemStatement,SailException>
cacheAwareInstance(MemStatementList smallestList, MemResource subj, MemIRI pred, MemValue obj, java.lang.Boolean explicit, int snapshot, MemResource[] memContexts, MemStatementIteratorCache iteratorCache)
void
close()
Closes this iteration, freeing any resources that it is holding.boolean
equals(java.lang.Object o)
private MemStatement
getNextElement()
Searches through statementList, starting from index _nextStatementIdx + 1, for statements that match the constraints that have been set for this iterator.MemStatementIterator.Stats
getStats()
int
hashCode()
boolean
hasNext()
Returns true if the iteration has more elements.private boolean
isCandidateForCache()
Returns true if this iterator was particularly costly and should be considered for cachingprivate MemStatement
lookAhead()
Fetches the next element if it hasn't been fetched yet and stores it innextElement
.(package private) boolean
matchesExplicitAndSnapshot(MemStatement st)
MemStatement
next()
Returns the next element in the iteration.void
remove()
Throws anUnsupportedOperationException
.java.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.rdf4j.common.iteration.CloseableIteration
stream
-
-
-
-
Field Detail
-
MIN_SIZE_TO_CONSIDER_FOR_CACHE
public static final int MIN_SIZE_TO_CONSIDER_FOR_CACHE
- See Also:
- Constant Field Values
-
statementListSize
private final int statementListSize
The lists of statements over which to iterate, and its size (different from length). Always set the size before the array. If we get the array first and the size after, then the MemStatementList object could have resized the array in between so that the size > length.
-
statementList
private MemStatement[] statementList
-
subject
private final MemResource subject
The subject of statements to return, or null if any subject is OK.
-
predicate
private final MemIRI predicate
The predicate of statements to return, or null if any predicate is OK.
-
object
private final MemValue object
The object of statements to return, or null if any object is OK.
-
contexts
private final MemResource[] contexts
The context of statements to return, or null if any context is OK.
-
explicit
private final boolean explicit
Flag indicating whether this iterator should only return explicitly added statements or only return inferred statements.If this has not been specified (null) and we should return both explicit and inferred statements, then the flag below will be set to true.
-
explicitNotSpecified
private final boolean explicitNotSpecified
-
snapshot
private final int snapshot
Indicates which snapshot should be iterated over.
-
noIsolation
private final boolean noIsolation
-
statementIndex
private int statementIndex
The index of the last statement that has been returned.
-
matchingStatements
private int matchingStatements
The number of returned statements
-
nextElement
private MemStatement nextElement
-
closed
private boolean closed
Flag indicating whether this iteration has been closed.
-
iteratorCache
private final MemStatementIteratorCache iteratorCache
-
cachedHashCode
private int cachedHashCode
-
-
Constructor Detail
-
MemStatementIterator
public MemStatementIterator(MemStatementList statementList, MemResource subject, MemIRI predicate, MemValue object, java.lang.Boolean explicit, int snapshot, MemStatementIteratorCache iteratorCache, MemResource... contexts) throws java.lang.InterruptedException
Creates a new MemStatementIterator that will iterate over the statements contained in the supplied MemStatementList searching for statements that match the specified pattern of subject, predicate, object and context(s).- Parameters:
statementList
- the statements over which to iterate.subject
- subject of pattern.predicate
- predicate of pattern.object
- object of pattern.contexts
- context(s) of pattern.- Throws:
java.lang.InterruptedException
-
-
Method Detail
-
cacheAwareInstance
public static CloseableIteration<MemStatement,SailException> cacheAwareInstance(MemStatementList smallestList, MemResource subj, MemIRI pred, MemValue obj, java.lang.Boolean explicit, int snapshot, MemResource[] memContexts, MemStatementIteratorCache iteratorCache) throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
getNextElement
private MemStatement getNextElement()
Searches through statementList, starting from index _nextStatementIdx + 1, for statements that match the constraints that have been set for this iterator. If a matching statement has been found it will be stored in _nextStatement and _nextStatementIdx points to the index of this statement in _statementList. Otherwise, _nextStatement will set to null.
-
matchesExplicitAndSnapshot
boolean matchesExplicitAndSnapshot(MemStatement st)
-
isCandidateForCache
private boolean isCandidateForCache()
Returns true if this iterator was particularly costly and should be considered for caching- Returns:
- true if it should be cached
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getStats
public MemStatementIterator.Stats getStats()
-
hasNext
public final boolean hasNext()
Description copied from interface:Iteration
Returns true if the iteration has more elements. (In other words, returns true ifIteration.next()
would return an element rather than throwing a NoSuchElementException.)- Specified by:
hasNext
in interfaceIteration<MemStatement,SailException>
- Returns:
- true if the iteration has more elements.
-
next
public final MemStatement next()
Description copied from interface:Iteration
Returns the next element in the iteration.- Specified by:
next
in interfaceIteration<MemStatement,SailException>
- Returns:
- the next element in the iteration.
-
lookAhead
private MemStatement lookAhead()
Fetches the next element if it hasn't been fetched yet and stores it innextElement
.- Returns:
- The next element, or null if there are no more results. @ If there is an issue getting the next element or closing the iteration.
-
remove
public void remove()
Throws anUnsupportedOperationException
.- Specified by:
remove
in interfaceIteration<MemStatement,SailException>
-
close
public final void close()
Description copied from interface:CloseableIteration
Closes this iteration, freeing any resources that it is holding. If the iteration has already been closed then invoking this method has no effect.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceCloseableIteration<MemStatement,SailException>
-
-