本文整理汇总了Java中java.util.Queue.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java Queue.isEmpty方法的具体用法?Java Queue.isEmpty怎么用?Java Queue.isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Queue
的用法示例。
在下文中一共展示了Queue.isEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reachableNodes
import java.util.Queue; //导入方法依赖的package包/类
/**
* Returns the set of nodes that are reachable from {@code node}. Node B is defined as reachable
* from node A if there exists a path (a sequence of adjacent outgoing edges) starting at node A
* and ending at node B. Note that a node is always reachable from itself via a zero-length path.
*
* <p>This is a "snapshot" based on the current topology of {@code graph}, rather than a live view
* of the set of nodes reachable from {@code node}. In other words, the returned {@link Set} will
* not be updated after modifications to {@code graph}.
*
* @throws IllegalArgumentException if {@code node} is not present in {@code graph}
*/
public static <N> Set<N> reachableNodes(Graph<N> graph, N node) {
checkArgument(graph.nodes().contains(node), NODE_NOT_IN_GRAPH, node);
Set<N> visitedNodes = new LinkedHashSet<N>();
Queue<N> queuedNodes = new ArrayDeque<N>();
visitedNodes.add(node);
queuedNodes.add(node);
// Perform a breadth-first traversal rooted at the input node.
while (!queuedNodes.isEmpty()) {
N currentNode = queuedNodes.remove();
for (N successor : graph.successors(currentNode)) {
if (visitedNodes.add(successor)) {
queuedNodes.add(successor);
}
}
}
return Collections.unmodifiableSet(visitedNodes);
}
示例2: galtonWatsonTree
import java.util.Queue; //导入方法依赖的package包/类
static <Node extends BinaryTreeNode<Node>> void galtonWatsonTree(BinaryTree<Node> t, int n) {
Random r = new Random();
Queue<Node> q = new LinkedList<Node>();
t.clear();
t.r = t.newNode();
q.add(t.r);
double p = ((double)0.5 - ((double)1)/(n+n));
while (!q.isEmpty()) {
Node u = q.remove();
if (r.nextDouble() < p) {
u.left = t.newNode();
u.left.parent = u;
q.add(u.left);
} if (r.nextDouble() < p) {
u.right = t.newNode();
u.right.parent = u;
q.add(u.right);
}
}
}
示例3: bfs
import java.util.Queue; //导入方法依赖的package包/类
public int[] bfs(int[][] matrix,int s){
int[] dist=new int[matrix.length];
for(int i=0;i<dist.length;i++)
dist[i]=-1;
dist[s]=0;
Queue<Integer> queue=new LinkedList<>();
HashSet<Integer> visited=new HashSet<>();
queue.add(s);
visited.add(s);
while(!queue.isEmpty()){
int v=queue.poll();
for(int i=0;i<matrix.length;i++){
if(matrix[v][i]==1 && !visited.contains(i)){
visited.add(i);
queue.add(i);
dist[i]=dist[v]+6;
}
}
}
return dist;
}
示例4: emitItem
import java.util.Queue; //导入方法依赖的package包/类
private void emitItem(GroupState<K, T> groupState, Object item) {
Queue<Object> q = groupState.buffer;
AtomicLong keyRequested = groupState.requested;
REQUESTED.decrementAndGet(this);
if (keyRequested == null || keyRequested.get() <= 0 || !(q == null || q.isEmpty())) {
q.add(item);
BUFFERED_COUNT.incrementAndGet(this);
if (groupState.count.getAndIncrement() == 0) {
pollQueue(groupState);
}
} else {
nl.accept(groupState.getObserver(), item);
if (keyRequested.get() != Long.MAX_VALUE) {
keyRequested.decrementAndGet();
}
}
requestMoreIfNecessary();
}
示例5: bfs
import java.util.Queue; //导入方法依赖的package包/类
/**
* Breadth-first search of graph.
* @param v the start vertex.
* @param cc the array to store the connected component id of vertices.
* @param id the current component id.
*/
private void bfs(Visitor visitor, int v, int[] cc, int id) {
visitor.visit(v);
cc[v] = id;
Queue<Integer> queue = new LinkedList<>();
queue.offer(v);
while (!queue.isEmpty()) {
int t = queue.poll();
for (int i = 0; i < n; i++) {
if (graph[t][i] != 0.0 && cc[i] == -1) {
visitor.visit(i);
queue.offer(i);
cc[i] = id;
}
}
}
}
示例6: split
import java.util.Queue; //导入方法依赖的package包/类
private void split(Queue<Block> splitterList) {
while (!splitterList.isEmpty()) {
// find the first non-empty splitter in the queue
Block splitter = splitterList.poll();
if (splitter.size() > 0) {
splitNext(splitter, splitterList);
}
}
}
示例7: runAll
import java.util.Queue; //导入方法依赖的package包/类
private void runAll(Queue<Runnable> queue) {
synchronized (queue) {
while (!queue.isEmpty()) {
queue.poll().run();
}
}
}
示例8: matchesSafely
import java.util.Queue; //导入方法依赖的package包/类
@Override
protected boolean matchesSafely(Collection<T> actualItems) {
final Queue<Matcher<? extends T>> copyOfMatchers = new LinkedList<>(matchers);
for (T item : actualItems) {
if (copyOfMatchers.isEmpty() || !copyOfMatchers.remove().matches(item)) {
return false;
}
}
return copyOfMatchers.isEmpty();
}
示例9: invalidateNextMessageAsync
import java.util.Queue; //导入方法依赖的package包/类
private void invalidateNextMessageAsync(final Queue<MessageId> invalidate) {
if (invalidate.isEmpty()) return;
dbExecutor.execute(new Runnable() {
@Override
public void run() {
invalidateNextMessage(invalidate);
}
});
}
示例10: testSerialization
import java.util.Queue; //导入方法依赖的package包/类
/**
* A deserialized/reserialized queue has same elements in same order
*/
public void testSerialization() throws Exception {
Queue x = populatedQueue(SIZE);
Queue y = serialClone(x);
assertNotSame(x, y);
assertEquals(x.size(), y.size());
assertEquals(x.toString(), y.toString());
assertTrue(Arrays.equals(x.toArray(), y.toArray()));
while (!x.isEmpty()) {
assertFalse(y.isEmpty());
assertEquals(x.remove(), y.remove());
}
assertTrue(y.isEmpty());
}
示例11: deliverNextPendingMessageAsync
import java.util.Queue; //导入方法依赖的package包/类
private void deliverNextPendingMessageAsync(
final Queue<MessageId> pending) {
if (pending.isEmpty()) return;
dbExecutor.execute(new Runnable() {
@Override
public void run() {
deliverNextPendingMessage(pending);
}
});
}
示例12: validateNextMessageAsync
import java.util.Queue; //导入方法依赖的package包/类
private void validateNextMessageAsync(final Queue<MessageId> unvalidated) {
if (unvalidated.isEmpty()) return;
dbExecutor.execute(new Runnable() {
@Override
public void run() {
validateNextMessage(unvalidated);
}
});
}
示例13: removeAllListeners
import java.util.Queue; //导入方法依赖的package包/类
public boolean removeAllListeners(String channelName) {
Queue<RedisPubSubListener<?>> listeners = channelListeners.get(channelName);
for (RedisPubSubListener<?> listener : listeners) {
removeListener(channelName, listener);
}
return !listeners.isEmpty();
}
示例14: intValue_1
import java.util.Queue; //导入方法依赖的package包/类
Integer intValue_1(Queue<byte[]> queue)
{
if (queue.isEmpty()) {
return INT_1;
}
return new Integer(new String(queue.poll()));
}
示例15: isAllLevelAnagrams
import java.util.Queue; //导入方法依赖的package包/类
private boolean isAllLevelAnagrams(Node root1, Node root2) {
if (root2 == null || root1 == null) {
return false;
}
//traverse level by level and check if level is angram
Queue<Node> nodes1 = new LinkedList<>();
nodes1.add(root1);
Stack<Node> nodes2 = new Stack<>();
nodes2.add(root2);
while (!nodes1.isEmpty() && !nodes2.isEmpty()) {
Node childNode1 = nodes1.poll();
Node childNode2 = nodes2.pop();
if (childNode1.data != childNode2.data) {
return false;
}
if (childNode1.left != null) {
nodes1.add(childNode1.left);
}
if (childNode1.right != null) {
nodes1.add(childNode1.right);
}
if (childNode2.left != null) {
nodes2.add(childNode2.left);
}
if (childNode2.right != null) {
nodes2.add(childNode2.right);
}
}
return !(!nodes1.isEmpty() || !nodes2.isEmpty());
}