当前位置: 首页>>代码示例>>Java>>正文


Java Queue.remove方法代码示例

本文整理汇总了Java中java.util.Queue.remove方法的典型用法代码示例。如果您正苦于以下问题:Java Queue.remove方法的具体用法?Java Queue.remove怎么用?Java Queue.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Queue的用法示例。


在下文中一共展示了Queue.remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: floodFill

import java.util.Queue; //导入方法依赖的package包/类
private void floodFill(int u, int v, int label) {
	Queue<Point> Q = new LinkedList<Point>();	//queue contains pixel coordinates
	Q.add(new Point(u, v));
	while (!Q.isEmpty()) {
		Point p = Q.remove();	// get the next point to process
		int x = p.x;
		int y = p.y;
		if ((x >= 0) && (x < width) && (y >= 0) && (y < height)
				&& getLabel(x, y) == FOREGROUND) {
			setLabel(x, y, label);
			Q.add(new Point(x+1, y));
			Q.add(new Point(x, y+1));
			Q.add(new Point(x, y-1));
			Q.add(new Point(x-1, y));
		}
	}
}
 
开发者ID:imagingbook,项目名称:imagingbook-common,代码行数:18,代码来源:BreadthFirstLabeling.java

示例2: visitIndirectNeighbours

import java.util.Queue; //导入方法依赖的package包/类
/**
 * Applies the given {@link Consumer} to the identifiers of the indirect neighbours in the given direction.
 *
 * @param id        the node's identifier
 * @param direction the direction of neighbours to visit
 * @param visited   a function that returns true if the node with the supplied id has been visited during this
 *                  iteration
 * @param action    the function to apply to each neighbour's identifier
 */
public void visitIndirectNeighbours(final int id, final SequenceDirection direction,
                                    final Predicate<Integer> visited, final Consumer<Integer> action) {
    final Queue<Integer> queue = new LinkedList<>();
    queue.add(id);

    while (!queue.isEmpty()) {
        final int head = queue.remove();
        if (visited.test(head)) {
            continue;
        }

        action.accept(head);
        visitDirectNeighbours(head, direction, index -> {
            if (!visited.test(index)) {
                queue.add(index);
            }
        });
    }
}
 
开发者ID:ProgrammingLife2017,项目名称:hygene,代码行数:29,代码来源:GraphIterator.java

示例3: 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

示例4: breadthFirstFrom

import java.util.Queue; //导入方法依赖的package包/类
public void breadthFirstFrom(final String start, final Walken christopher) {
    final Queue<BuildRule> buildRules = new LinkedList<>();
    final BuildRule startRule = map.get(start);
    int depth = 0;

    buildRules.add(startRule);
    christopher.step(startRule, depth);

    while (!buildRules.isEmpty()) {
        final BuildRule parent = buildRules.remove();
        depth++;
        final Set<BuildRule> children = graph.predecessors(parent);
        for (final BuildRule child : children) {
            christopher.step(child, depth);
            buildRules.add(child);
        }
    }
}
 
开发者ID:nfisher,项目名称:cljbuck,代码行数:19,代码来源:BuildGraph.java

示例5: browseForFileObjects

import java.util.Queue; //导入方法依赖的package包/类
private Set<FileObject> browseForFileObjects(javax.swing.tree.TreeModel model) {
    Queue<CheckNode> q = new LinkedList<CheckNode>();
    q.add((CheckNode) model.getRoot());
    Set<FileObject> result = new HashSet<FileObject>();
    while (!q.isEmpty()) {
        CheckNode node = q.remove();
        Object uo = node.getUserObject();
        if (uo instanceof FileTreeElement) {
            FileTreeElement fileTreeElement = (FileTreeElement) uo;
            Object userObject = fileTreeElement.getUserObject();
            if (userObject instanceof FileObject) {
                result.add((FileObject) userObject);
            } else {
                throw new IllegalArgumentException("Object of type FileObject was expected, but got " + userObject.getClass().getName());
            }

        }
        for (int i = 0; i < model.getChildCount(node); i++) {
            q.add((CheckNode) model.getChild(node, i));
        }
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:RefactoringResultOperator.java

示例6: 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

示例7: leftistDraw

import java.util.Queue; //导入方法依赖的package包/类
/**
 * Draw each node so that it's x-coordinate is as small
 * as possible without intersecting any other node at the same level
 * the same as its parent's
 */
public void leftistDraw() {
	assignLevels();

	Queue<GeometricTreeNode> queue = new LinkedList<GeometricTreeNode>();

	//get root node
	GeometricTreeNode p = r;
	//set root position to 0
	p.position.x = 0;
	//add root node to queue
	queue.add(p);

	//loop through tree in breadth first traverse
	while (!queue.isEmpty()) {
		//get current node from queue
		GeometricTreeNode c = queue.remove();

		//if current node is same y, then x must be ++
		c.position.x = (p.position.y == c.position.y) ? p.position.x + 1 : 0;

		//ensure root is at .x = 0
		if (c == r) {
			c.position.x = 0;
		}

		//set parent node to current node
		p = c;

		//add child nodes if not null
		//left then right to follow bfs
		if (c.left != nil) {
			queue.add(c.left);
		}
		if (c.right != nil) {
			queue.add(c.right);
		}
	}

}
 
开发者ID:hughxie,项目名称:class-code,代码行数:45,代码来源:GeometricTree.java

示例8: getMaxChildrenWidth

import java.util.Queue; //导入方法依赖的package包/类
/**
 * Returns the maximum number of children with the same distance to the given node.
 *
 * @param node a {@link LayoutableNode}
 * @return the maximum number of children with the same distance to the given node
 */
private int getMaxChildrenWidth(final LayoutableNode node) {
    int[] maxChildrenWidth = {-1};

    final Set<LayoutableNode> visited = new HashSet<>();
    final Queue<LayoutableNode> queue = new LinkedList<>();
    queue.add(node);

    final int[] depthIncreaseTimes = {1, 0};
    while (!queue.isEmpty()) {
        final LayoutableNode head = queue.remove();

        if (!visited.contains(head)) {
            visited.add(head);

            head.getOutgoingEdges().forEach(edge -> {
                if (!visited.contains(edge.getTo())) {
                    depthIncreaseTimes[1]++;
                    queue.add(edge.getTo());
                }
            });
        }

        depthIncreaseTimes[0]--;
        if (depthIncreaseTimes[0] <= 0) {
            depthIncreaseTimes[0] = depthIncreaseTimes[1];
            depthIncreaseTimes[1] = 0;

            maxChildrenWidth[0] = Math.max(maxChildrenWidth[0], depthIncreaseTimes[0]);
            if (depthIncreaseTimes[0] == 1) {
                return maxChildrenWidth[0];
            }
        }
    }

    return maxChildrenWidth[0];
}
 
开发者ID:ProgrammingLife2017,项目名称:hygene,代码行数:43,代码来源:BarycentricCrossingsReducer.java

示例9: testFailureDetection

import java.util.Queue; //导入方法依赖的package包/类
@Test
public void testFailureDetection() throws Exception {
  Time mockTime = getMockTime();
  Queue<Anomaly> anomalies = new ConcurrentLinkedQueue<>();
  BrokerFailureDetector detector = createBrokerFailureDetector(anomalies, mockTime);
  try {
    // Start detection.
    detector.startDetection();
    assertTrue(anomalies.isEmpty());
    int brokerId = 0;
    killBroker(brokerId);
    long start = System.currentTimeMillis();
    while (anomalies.isEmpty() && System.currentTimeMillis() < start + 30000) {
      // wait for the anomalies to be drained.
    }
    assertEquals("One broker failure should have been detected before timeout.", 1, anomalies.size());
    Anomaly anomaly = anomalies.remove();
    assertTrue("The anomaly should be BrokerFailure", anomaly instanceof BrokerFailures);
    BrokerFailures brokerFailures = (BrokerFailures) anomaly;
    assertEquals("The failed broker should be 0 and time should be 100L", Collections.singletonMap(brokerId, 100L),
                 brokerFailures.failedBrokers());

    // Bring the broker back
    System.out.println("Starting brokers.");
    restartDeadBroker(brokerId);
    detector.detectBrokerFailures();
    assertTrue(detector.failedBrokers().isEmpty());
  } finally {
    detector.shutdown();
  }
}
 
开发者ID:linkedin,项目名称:cruise-control,代码行数:32,代码来源:BrokerFailureDetectorTest.java

示例10: calculateUptime

import java.util.Queue; //导入方法依赖的package包/类
/**
 * Calculates the up time.
 *
 * @param difference the difference
 * @param calculations the calculations
 * @param labels the labels
 * @return the uptime as a string.
 */
protected String calculateUptime(final double difference, final Queue<Integer> calculations, final Queue<String> labels) {
    if (calculations.isEmpty()) {
        return "";
    }

    final int value = calculations.remove();
    final double time = Math.floor(difference / value);
    final double newDifference = difference - time * value;
    final String currentLabel = labels.remove();
    final String label = time == 0 || time > 1 ? currentLabel + 's' : currentLabel;

    return Integer.toString((int) time) + ' ' + label + ' ' + calculateUptime(newDifference, calculations, labels);
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:22,代码来源:StatisticsController.java

示例11: levelOrderQueue

import java.util.Queue; //导入方法依赖的package包/类
public void levelOrderQueue(Node root) {
Queue<Node> q = new LinkedList<Node>();
if (root == null)
return;
q.add(root);
while (!q.isEmpty()) {
Node n = (Node) q.remove();
			
			
int goal=11;
int c=0;
			
			if (n.left != null)
				q.add(n.left);
			c+=1;
			if (n.right != null)
				q.add(n.right);
			c+=1;
			  System.out.print(" " + n.data);
				if(n.data==goal)
				break;
		
		    
		      
		    
		}
		
	}
 
开发者ID:BaReinhard,项目名称:Hacktoberfest-Data-Structure-and-Algorithms,代码行数:29,代码来源:binary_tree_bfs.java

示例12: readValue

import java.util.Queue; //导入方法依赖的package包/类
private double readValue(Queue<Token> tokens) throws Exception {
  double sign = 1.0;

  if (NEGATIVE.equals(tokens.peek())) {
    sign = -1.0;
    tokens.remove();
  }

  final Token token = tokens.remove();
  double value = 0.0;
  if (token instanceof NumberToken) {
    final NumberToken number = (NumberToken) token;
    value = number.value;
  } else if (token instanceof NameToken) {
    final NameToken name = (NameToken) token;
    final Variable variable = variables.get(name.value);
    if (variable == null) {
      throw new Exception(String.format(
          "Attempting to read value of \"%s\" before assigning value.",
          name.value));
    }
    value = variable.read();
  } else {
    throw new Exception(String.format("Cannot evaluate %s", token));
  }

  return sign * value;
}
 
开发者ID:google,项目名称:codeu_coding_assessment_b_2017,代码行数:29,代码来源:LetFunction.java

示例13: addImpliedFeatures

import java.util.Queue; //导入方法依赖的package包/类
/**
 * Given a set of features, add to it all the features directly or indirectly
 * implied by any of them, and return it.
 * @param features the set of features to expand
 * @return the same set of features, expanded with all implied features
 */
public static Set<Feature<?>> addImpliedFeatures(Set<Feature<?>> features) {
  Queue<Feature<?>> queue = new ArrayDeque<Feature<?>>(features);
  while (!queue.isEmpty()) {
    Feature<?> feature = queue.remove();
    for (Feature<?> implied : feature.getImpliedFeatures()) {
      if (features.add(implied)) {
        queue.add(implied);
      }
    }
  }
  return features;
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:19,代码来源:FeatureUtil.java

示例14: bfTraverse

import java.util.Queue; //导入方法依赖的package包/类
public void bfTraverse() {
	Queue<Node> q = new LinkedList<Node>();
	q.add(r);
	while (!q.isEmpty()) {
		Node u = q.remove();
		if (u.left != nil) q.add(u.left);
		if (u.right != nil) q.add(u.right);
	}
}
 
开发者ID:hughxie,项目名称:class-code,代码行数:10,代码来源:BinaryTree.java

示例15: obtainLast

import java.util.Queue; //导入方法依赖的package包/类
private Event obtainLast(EventsQueue eventsQueue) {
  Event lastEvent = null;
  Queue<Event> queue = eventsQueue.queue.obtainQueue();
  int count = queue.size();
  for (int i = 0; i < count; i++) {
    lastEvent = queue.remove();
  }
  return lastEvent;
}
 
开发者ID:mapbox,项目名称:mapbox-events-android,代码行数:10,代码来源:EventsQueueTest.java


注:本文中的java.util.Queue.remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。