当前位置: 首页>>代码示例>>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;未经允许,请勿转载。