org.apache.jena.util.iterator.ClosableIterator Java Examples

The following examples show how to use org.apache.jena.util.iterator.ClosableIterator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DistinctExpression.java    From shacl with Apache License 2.0 6 votes vote down vote up
private static <T> ExtendedIterator<T> recording(ClosableIterator<T> i, Set<T> seen) {
	return new NiceIterator<T>() {
		
		@Override
		public void remove() {
			i.remove();
		}

		@Override
		public boolean hasNext() {
			return i.hasNext(); 
		}    

		@Override
		public T next() { 
			T x = i.next(); 
			seen.add(x);
			return x;
		}  

		@Override
		public void close() {
			i.close(); 
		}
	};
}
 
Example #2
Source File: CSVTable.java    From tarql with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public QueryIterator iterator(ExecutionContext ctxt) {
	// QueryIteratorPlainWrapper doesn't close wrapped 
	// ClosableIterators, so we do that ourselves.
	final ClosableIterator<Binding> wrapped = rows();
	return new QueryIterPlainWrapper(wrapped, ctxt) {
		@Override
		protected void closeIterator() {
			super.closeIterator();
			wrapped.close();
		}
	};
}
 
Example #3
Source File: CSVTable.java    From tarql with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public ClosableIterator<Binding> rows() {
	ensureHasParser();
	final ClosableIterator<Binding> wrappedIterator = nextParser;
	nextParser = null;
	// We will add a wrapper to the iterator that removes it
	// from the list of open iterators once it is closed and
	// exhausted, and that fills the size cache once the
	// iterator is exhausted.
	return new ClosableIterator<Binding>() {
		private int count = 0;
		@Override
		public boolean hasNext() {
			if (wrappedIterator.hasNext()) return true;
			if (sizeCache == null) sizeCache = count;
			openIterators.remove(wrappedIterator);
			return false;
		}
		@Override
		public Binding next() {
			count++;
			return wrappedIterator.next();
		}
		@Override
		public void remove() {
			wrappedIterator.remove();
		}
		@Override
		public void close() {
			openIterators.remove(wrappedIterator);
			wrappedIterator.close();
		}
	};
}
 
Example #4
Source File: CSVTable.java    From tarql with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Closes any open iterators over the table.
 */
@Override
public void closeTable() {
	while (!openIterators.isEmpty()) {
		ClosableIterator<Binding> next = openIterators.remove(0);
		next.close();
	}
}