本文整理汇总了Java中java.util.ArrayDeque.pollFirst方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayDeque.pollFirst方法的具体用法?Java ArrayDeque.pollFirst怎么用?Java ArrayDeque.pollFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.ArrayDeque
的用法示例。
在下文中一共展示了ArrayDeque.pollFirst方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startFromImpl
import java.util.ArrayDeque; //导入方法依赖的package包/类
/**
* Generic implementation of BFS; forward/reverse edges are chosen using <code>selector</code>.
*
* @param g {@link DirectedGraph} to use for iteration.
* @param v Vertex to start from.
* @param visitor {@link VertexVisitor} to use for visiting vertices.
* @param selector {@link NeighborSelector} for selecting forward/reverse vertices.
*/
@Override
protected void startFromImpl(DirectedGraph<V, E> g, V v, VertexVisitor<V, E> visitor,
NeighborSelector<V, E> selector) {
final Set<V> seen = new HashSet<V>();
final ArrayDeque<V> dequeue = new ArrayDeque<V>();
dequeue.addLast(v);
while (!dequeue.isEmpty()) {
final V vertex = dequeue.pollFirst();
if (!seen.contains(vertex)) { // skip seen ones
seen.add(vertex);
if (!visitor.visit(g, vertex)) {
break;
}
final Iterator<V> it = selector.nextFrom(g, vertex);
while (it.hasNext()) {
dequeue.add(it.next());
}
}
}
}
示例2: onNext
import java.util.ArrayDeque; //导入方法依赖的package包/类
@Override
public final void onNext(T item) {
T dropped = null;
synchronized (this) {
ArrayDeque<T> q = this.queue;
if (q.size() == capacity) {
if (dropNewest) {
dropped = q.pollLast();
} else {
dropped = q.pollFirst();
}
}
q.offer(item);
}
if (dropped != null) {
try {
onDrop.accept(dropped);
} catch (Throwable ex) {
upstream.cancel();
onError(ex);
return;
}
}
drain();
}