本文整理汇总了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);
}