本文整理匯總了Java中org.apache.tinkerpop.gremlin.structure.util.CloseableIterator類的典型用法代碼示例。如果您正苦於以下問題:Java CloseableIterator類的具體用法?Java CloseableIterator怎麽用?Java CloseableIterator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CloseableIterator類屬於org.apache.tinkerpop.gremlin.structure.util包,在下文中一共展示了CloseableIterator類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: map
import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator; //導入依賴的package包/類
public static <S, E> Iterator<E> map(final Iterator<S> iterator, final Function<S, E> function) {
return new CloseableIterator<E>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public void remove() {
iterator.remove();
}
@Override
public E next() {
return function.apply(iterator.next());
}
@Override
public void close() {
CloseableIterator.closeIterator(iterator);
}
};
}
示例2: flatMap
import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator; //導入依賴的package包/類
public static <S, E> Iterator<E> flatMap(final Iterator<S> iterator, final Function<S, Iterator<E>> function) {
return new CloseableIterator<E>() {
private Iterator<E> currentIterator = Collections.emptyIterator();
@Override
public boolean hasNext() {
if (this.currentIterator.hasNext())
return true;
else {
while (iterator.hasNext()) {
this.currentIterator = function.apply(iterator.next());
if (this.currentIterator.hasNext())
return true;
}
}
return false;
}
@Override
public void remove() {
iterator.remove();
}
@Override
public E next() {
if (this.hasNext())
return this.currentIterator.next();
else
throw FastNoSuchElementException.instance();
}
@Override
public void close() {
CloseableIterator.closeIterator(iterator);
}
};
}
示例3: filter
import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator; //導入依賴的package包/類
public static <S> Iterator<S> filter(final Iterator<S> iterator, final Predicate<S> predicate) {
return new CloseableIterator<S>() {
S nextResult = null;
@Override
public boolean hasNext() {
if (null != this.nextResult) {
return true;
} else {
advance();
return null != this.nextResult;
}
}
@Override
public void remove() {
iterator.remove();
}
@Override
public S next() {
try {
if (null != this.nextResult) {
return this.nextResult;
} else {
advance();
if (null != this.nextResult)
return this.nextResult;
else
throw FastNoSuchElementException.instance();
}
} finally {
this.nextResult = null;
}
}
private void advance() {
this.nextResult = null;
while (iterator.hasNext()) {
final S s = iterator.next();
if (predicate.test(s)) {
this.nextResult = s;
return;
}
}
}
@Override
public void close() {
CloseableIterator.closeIterator(iterator);
}
};
}
示例4: close
import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator; //導入依賴的package包/類
@Override
public void close() {
this.iterators.forEach(CloseableIterator::closeIterator);
}
示例5: closeIterator
import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator; //導入依賴的package包/類
protected void closeIterator() {
CloseableIterator.closeIterator(iterator);
}
示例6: close
import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator; //導入依賴的package包/類
/**
* Attempts to close an underlying iterator if it is of type {@link CloseableIterator}. Graph providers may choose
* to return this interface containing their vertices and edges if there are expensive resources that might need to
* be released at some point.
*/
@Override
public void close() {
CloseableIterator.closeIterator(iterator);
}