本文整理匯總了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();
}