當前位置: 首頁>>代碼示例>>Java>>正文


Java Queue.isEmpty方法代碼示例

本文整理匯總了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);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:29,代碼來源:Graphs.java

示例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);
		}
	}
}
 
開發者ID:hughxie,項目名稱:class-code,代碼行數:21,代碼來源:BinaryTree.java

示例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;
}
 
開發者ID:praenubilus,項目名稱:UF-CPP,代碼行數:23,代碼來源:Himanshu_BFSShortestPath.java

示例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();
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:19,代碼來源:OperatorGroupBy.java

示例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;
            }
        }
    }
}
 
開發者ID:takun2s,項目名稱:smile_1.5.0_java7,代碼行數:23,代碼來源:AdjacencyMatrix.java

示例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);
        }
    }
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:10,代碼來源:SimplePaigeTarjanMcKay.java

示例7: runAll

import java.util.Queue; //導入方法依賴的package包/類
private void runAll(Queue<Runnable> queue) {
    synchronized (queue) {
        while (!queue.isEmpty()) {
            queue.poll().run();
        }
    }
}
 
開發者ID:vipycm,項目名稱:mao-android,代碼行數:8,代碼來源:BaseCameraView.java

示例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();
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:11,代碼來源:CollectionContainsOnlyInOrder.java

示例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);
		}
	});
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:10,代碼來源:ValidationManagerImpl.java

示例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());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:LinkedBlockingQueueTest.java

示例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);
		}
	});
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:11,代碼來源:ValidationManagerImpl.java

示例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);
		}
	});
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:10,代碼來源:ValidationManagerImpl.java

示例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();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:8,代碼來源:PubSubConnectionEntry.java

示例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()));
}
 
開發者ID:DavidQuan,項目名稱:vertx-ssdb,代碼行數:9,代碼來源:CompositeClient.java

示例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());
    }
 
開發者ID:ranjeet-floyd,項目名稱:practice-coding,代碼行數:43,代碼來源:LevelAnagramTree.java


注:本文中的java.util.Queue.isEmpty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。