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


Java Queues.newArrayDeque方法代碼示例

本文整理匯總了Java中com.google.common.collect.Queues.newArrayDeque方法的典型用法代碼示例。如果您正苦於以下問題:Java Queues.newArrayDeque方法的具體用法?Java Queues.newArrayDeque怎麽用?Java Queues.newArrayDeque使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.collect.Queues的用法示例。


在下文中一共展示了Queues.newArrayDeque方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: ParticleManager

import com.google.common.collect.Queues; //導入方法依賴的package包/類
public ParticleManager(World worldIn, TextureManager rendererIn)
{
    this.worldObj = worldIn;
    this.renderer = rendererIn;

    for (int i = 0; i < 4; ++i)
    {
        this.fxLayers[i] = new ArrayDeque[2];

        for (int j = 0; j < 2; ++j)
        {
            this.fxLayers[i][j] = Queues.newArrayDeque();
        }
    }

    this.registerVanillaParticles();
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:18,代碼來源:ParticleManager.java

示例2: floodFill

import com.google.common.collect.Queues; //導入方法依賴的package包/類
private Set<EnumFacing> floodFill(int p_178604_1_)
{
    Set<EnumFacing> set = EnumSet.<EnumFacing>noneOf(EnumFacing.class);
    Queue<Integer> queue = Queues.<Integer>newArrayDeque();
    queue.add(IntegerCache.getInteger(p_178604_1_));
    this.bitSet.set(p_178604_1_, true);

    while (!((Queue)queue).isEmpty())
    {
        int i = ((Integer)queue.poll()).intValue();
        this.addEdges(i, set);

        for (EnumFacing enumfacing : EnumFacing.values())
        {
            int j = this.getNeighborIndexAtFace(i, enumfacing);

            if (j >= 0 && !this.bitSet.get(j))
            {
                this.bitSet.set(j, true);
                queue.add(IntegerCache.getInteger(j));
            }
        }
    }

    return set;
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:27,代碼來源:VisGraph.java

示例3: bfsLists

import com.google.common.collect.Queues; //導入方法依賴的package包/類
/**
 * Do a breadth-first search over the given collection of lists, applying the supplied function
 * to each item in the list.  If the function returns an explicit true (not null or false)
 * the search will abort.
 *
 * @param toTraverse the lists to traverse (breadth-first)
 * @param toApply the function to apply (if it returns true the search will abort)
 * @return the number of lists visited (inclusive)
 */
public static int bfsLists(Collection<WFList> toTraverse, Function<WFList, Boolean> toApply) {
    if (toTraverse == null) return 0;

    int numVisited = 0;
    Queue<WFList> visitQueue = Queues.newArrayDeque(toTraverse);
    while (!visitQueue.isEmpty()) {
        numVisited++;
        WFList cur = visitQueue.remove();
        Boolean abort = toApply.apply(cur);
        if (abort != null && abort.equals(true)) {
            break;
        }
        if (cur.getChildren() != null) {
            visitQueue.addAll(cur.getChildren());
        }
    }
    return numVisited;
}
 
開發者ID:rmnoon,項目名稱:WorkflowyList,代碼行數:28,代碼來源:Utils.java

示例4: pathExistsDirectional

import com.google.common.collect.Queues; //導入方法依賴的package包/類
/**
 * Route Between Nodes: Find whether there is a path between two nodes (A->B) in a directed graph.
 *
 * Assumptions:
 *
 * Time complexity: O(n)
 * Space complexity: O(n)
 *
 * Notes: Simple breadth first search.
 */
public static boolean pathExistsDirectional(IntNode a, IntNode b, IntGraph graph) {
  if (a == b) {
    return true;
  }

  Queue<IntNode> queue = Queues.newArrayDeque();
  Set<IntNode> visited = Sets.newHashSet();
  queue.add(a);
  visited.add(a);

  while (!queue.isEmpty()) {
    IntNode next = queue.remove();
    for (Node<Integer> adjacent : next.getAdjacent()) {
      if (adjacent == b) {
        return true;
      } else if (visited.add((IntNode) adjacent)) {
        queue.add((IntNode) adjacent);
      }
    }  
  }

  return false;
}
 
開發者ID:myyk,項目名稱:cracking-the-coding-interview-6th,代碼行數:34,代碼來源:Chapter4Solutions.java

示例5: pathExistsBidirectional

import com.google.common.collect.Queues; //導入方法依賴的package包/類
/**
 * Route Between Nodes: Modified - Find whether there is a path between two nodes (A->B) in a bidirectional graph.
 *
 * Assumptions:
 *
 * Time complexity: O(n) where n is numer of nodes
 * Space complexity: O(n)
 */
public static boolean pathExistsBidirectional(IntNode a, IntNode b) {
  // BFS on both nodes at the same time
  Queue<IntNode> queueA = Queues.newArrayDeque();
  Queue<IntNode> queueB = Queues.newArrayDeque();
  Set<IntNode> visitedA = Sets.newHashSet();
  Set<IntNode> visitedB = Sets.newHashSet();

  visitedA.add(a);
  visitedB.add(b);
  queueA.add(a);
  queueB.add(b);

  while (!queueA.isEmpty() && !queueB.isEmpty()) {
    if (pathExistsBidirectionalHelper(queueA, visitedA, visitedB)) {
      return true;
    }
    if (pathExistsBidirectionalHelper(queueB, visitedB, visitedA)) {
      return true;
    }
  }

  return false;
}
 
開發者ID:myyk,項目名稱:cracking-the-coding-interview-6th,代碼行數:32,代碼來源:Chapter4Solutions.java

示例6: targetsForSourceFileImpl

import com.google.common.collect.Queues; //導入方法依賴的package包/類
private Collection<TargetIdeInfo> targetsForSourceFileImpl(
    ImmutableMultimap<TargetKey, TargetKey> rdepsMap, File sourceFile) {
  List<TargetIdeInfo> result = Lists.newArrayList();
  Collection<TargetKey> roots = rootsMap.get(sourceFile);

  Queue<TargetKey> todo = Queues.newArrayDeque();
  todo.addAll(roots);
  Set<TargetKey> seen = Sets.newHashSet();
  while (!todo.isEmpty()) {
    TargetKey targetKey = todo.remove();
    if (!seen.add(targetKey)) {
      continue;
    }

    TargetIdeInfo target = targetMap.get(targetKey);
    if (filter.test(target)) {
      result.add(target);
    }
    todo.addAll(rdepsMap.get(targetKey));
  }
  return result;
}
 
開發者ID:bazelbuild,項目名稱:intellij,代碼行數:23,代碼來源:FilteredTargetMap.java

示例7: schemaPathToFieldPath

import com.google.common.collect.Queues; //導入方法依賴的package包/類
/**
 * Returns {@link FieldPath} equivalent of the specified {@link SchemaPath}.
 *
 * @param schemaPath {@link SchemaPath} instance that should be converted
 * @return {@link FieldPath} equivalent of the specified {@link SchemaPath}.
 */
public static FieldPath schemaPathToFieldPath(SchemaPath schemaPath) {
  Deque<PathSegment> pathSegments = Queues.newArrayDeque();
  PathSegment pathSegment = schemaPath.getRootSegment();
  while (pathSegment != null) {
    pathSegments.push(pathSegment);
    pathSegment = pathSegment.getChild();
  }

  FieldSegment child = null;
  while (!pathSegments.isEmpty()) {
    pathSegment = pathSegments.pop();
    if (pathSegment.isNamed()) {
      child = new FieldSegment.NameSegment(((PathSegment.NameSegment) pathSegment).getPath(), child, false);
    } else {
      child = new FieldSegment.IndexSegment(String.valueOf(((PathSegment.ArraySegment) pathSegment).getIndex()), child);
    }
  }
  return new FieldPath((FieldSegment.NameSegment) child);
}
 
開發者ID:axbaretto,項目名稱:drill,代碼行數:26,代碼來源:FieldPathHelper.java

示例8: executeSoot

import com.google.common.collect.Queues; //導入方法依賴的package包/類
private static Scene executeSoot(Collection<String> methodSignatures) {
    IoSinkExpressions sinkExpressions = new IoSinkExpressions(Scene.v());

    Set<MethodAnalysis> processed = Sets.newHashSet();
    Queue<MethodAnalysis> queue = Queues.newArrayDeque(methodSignatures.stream()
                                                                       .map(s -> Scene.v().getMethod(s))
                                                                       .map(MethodAnalysis::new)
                                                                       .collect(Collectors.toSet()));

    PackManager.v().getPack("wjtp").add(
            new Transform("wjtp.dataFlowTransform", new SceneTransformer() {
                @Override protected void internalTransform(String phaseName, Map options) {
                    processQueue(queue, processed, sinkExpressions);
                }
            }));

    PackManager.v().runPacks();
    PackManager.v().writeOutput();
    return Scene.v();
}
 
開發者ID:uwdb,項目名稱:pipegen,代碼行數:21,代碼來源:Optimizer.java

示例9: insertItemIntoListRemoveRedundantCommas

import com.google.common.collect.Queues; //導入方法依賴的package包/類
@Override
@NotNull
public PsiElement insertItemIntoListRemoveRedundantCommas(
  @NotNull final PyElement list,
  @Nullable final PyExpression afterThis,
  @NotNull final PyExpression toInsert) {
  // TODO: #insertItemIntoList is probably buggy. In such case, fix it and get rid of this method
  final PsiElement result = insertItemIntoList(list, afterThis, toInsert);
  final LeafPsiElement[] leafs = PsiTreeUtil.getChildrenOfType(list, LeafPsiElement.class);
  if (leafs != null) {
    final Deque<LeafPsiElement> commas = Queues.newArrayDeque(Collections2.filter(Arrays.asList(leafs), COMMAS_ONLY));
    if (!commas.isEmpty()) {
      final LeafPsiElement lastComma = commas.getLast();
      if (PsiTreeUtil.getNextSiblingOfType(lastComma, PyExpression.class) == null) { //Comma has no expression after it
        lastComma.delete();
      }
    }
  }

  return result;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:22,代碼來源:PyElementGeneratorImpl.java

示例10: getTransitiveDependencies

import com.google.common.collect.Queues; //導入方法依賴的package包/類
public static ImmutableCollection<TargetKey> getTransitiveDependencies(
    Collection<TargetKey> targetKeys, TargetMap targetMap) {
  Queue<TargetKey> targetsToVisit = Queues.newArrayDeque();
  Set<TargetKey> transitiveDependencies = Sets.newHashSet();
  targetsToVisit.addAll(targetKeys);
  while (!targetsToVisit.isEmpty()) {
    TargetIdeInfo currentTarget = targetMap.get(targetsToVisit.remove());
    if (currentTarget == null) {
      continue;
    }
    List<TargetKey> newDependencies =
        currentTarget
            .dependencies
            .stream()
            .map(d -> TargetKey.forPlainTarget(d.targetKey.label))
            // Get rid of the ones we've already seen.
            .filter(r -> !transitiveDependencies.contains(r))
            .collect(Collectors.toList());
    targetsToVisit.addAll(newDependencies);
    transitiveDependencies.addAll(newDependencies);
  }
  return ImmutableSet.copyOf(transitiveDependencies);
}
 
開發者ID:bazelbuild,項目名稱:intellij,代碼行數:24,代碼來源:TransitiveDependencyMap.java

示例11: willRewrite

import com.google.common.collect.Queues; //導入方法依賴的package包/類
private boolean willRewrite(Production production) {
	// fill worker queue
	Deque<Production> openProduction = Queues.newArrayDeque();
	openProduction.offer(production);
	// till no production to consider ...
	while (openProduction.isEmpty() == false) {
		Production currentProduction = openProduction.poll();
		if (currentProduction instanceof RewriteProduction) {
			// we're not done, for sure, as we found a rewrite production
			return true;
		} else if (currentProduction instanceof BranchProduction<?>) {
			BranchProduction<?> branchProduction = (BranchProduction<?>) currentProduction;
			List<Production> branchInnerProductions = branchProduction.getRuleProductions(-1);
			for (Production branchInnerProduction : branchInnerProductions) {
				openProduction.offer(branchInnerProduction);
			}
		}
	}
	return false;
}
 
開發者ID:thotro,項目名稱:linn,代碼行數:21,代碼來源:LinnExecutor.java

示例12: clear

import com.google.common.collect.Queues; //導入方法依賴的package包/類
protected void clear(Commit<Void> commit) {
    Queue<DocumentPath> toClearQueue = Queues.newArrayDeque();
    Map<String, Versioned<byte[]>> topLevelChildren = docTree.getChildren(DocumentPath.from("root"));
    toClearQueue.addAll(topLevelChildren.keySet()
            .stream()
            .map(name -> new DocumentPath(name, DocumentPath.from("root")))
            .collect(Collectors.toList()));
    while (!toClearQueue.isEmpty()) {
        DocumentPath path = toClearQueue.remove();
        Map<String, Versioned<byte[]>> children = docTree.getChildren(path);
        if (children.size() == 0) {
            docTree.removeNode(path);
        } else {
            children.keySet().forEach(name -> toClearQueue.add(new DocumentPath(name, path)));
            toClearQueue.add(path);
        }
    }
}
 
開發者ID:opennetworkinglab,項目名稱:onos,代碼行數:19,代碼來源:AtomixDocumentTreeService.java

示例13: getAllPreviousDocs

import com.google.common.collect.Queues; //導入方法依賴的package包/類
@Nonnull
Iterator<NodeDocument> getAllPreviousDocs() {
    if (getPreviousRanges().isEmpty()) {
        return Iterators.emptyIterator();
    }
    //Currently this method would fire one query per previous doc
    //If that poses a problem we can try to find all prev doc by relying
    //on property that all prevDoc id would starts <depth+2>:p/path/to/node
    return new AbstractIterator<NodeDocument>(){
        private Queue<Map.Entry<Revision, Range>> previousRanges =
                Queues.newArrayDeque(getPreviousRanges().entrySet());
        @Override
        protected NodeDocument computeNext() {
            if(!previousRanges.isEmpty()){
                Map.Entry<Revision, Range> e = previousRanges.remove();
                NodeDocument prev = getPreviousDoc(e.getKey(), e.getValue());
                if(prev != null){
                    previousRanges.addAll(prev.getPreviousRanges().entrySet());
                    return prev;
                }
            }
            return endOfData();
        }
    };
}
 
開發者ID:denismo,項目名稱:jackrabbit-dynamodb-store,代碼行數:26,代碼來源:NodeDocument.java

示例14: testForwardingOfRequests

import com.google.common.collect.Queues; //導入方法依賴的package包/類
@Test
public void testForwardingOfRequests() throws Exception {

  Queue<RequestAndCallback> queue = Queues.newArrayDeque();

  BatchedPermitsRequester container = BatchedPermitsRequester.builder().resourceId("resource")
      .requestorIdentifier("requestor").requestSender(new TestRequestSender(queue, false)).build();
  try (ParallelRequester requester = new ParallelRequester(container)) {

    Future<Boolean> future = requester.request(10);

    await(new QueueSize(queue, 1), 1000);
    Assert.assertEquals(queue.size(), 1);
    satisfyRequestBuilder().requestAndCallback(queue.poll()).satisfy();

    future.get(1, TimeUnit.SECONDS);
    Assert.assertTrue(future.isDone());
    Assert.assertTrue(future.get());
  }
}
 
開發者ID:apache,項目名稱:incubator-gobblin,代碼行數:21,代碼來源:BatchedPermitsRequesterTest.java

示例15: testRetriableFail

import com.google.common.collect.Queues; //導入方法依賴的package包/類
@Test
public void testRetriableFail() throws Exception {
  Queue<RequestAndCallback> queue = Queues.newArrayDeque();

  BatchedPermitsRequester container = BatchedPermitsRequester.builder().resourceId("resource")
      .requestorIdentifier("requestor").requestSender(new TestRequestSender(queue, false)).build();
  try (ParallelRequester requester = new ParallelRequester(container)) {

    Future<Boolean> future = requester.request(10);

    for (int i = 0; i < BatchedPermitsRequester.MAX_RETRIES; i++) {
      // container will fail 5 times
      await(new QueueSize(queue, 1), 1000);
      Assert.assertFalse(future.isDone());
      failRequestBuilder().requestAndCallback(queue.poll()).fail();
    }

    // should return a failure
    Assert.assertFalse(future.get());
    // should not make any more request
    Assert.assertEquals(queue.size(), 0);
  }
}
 
開發者ID:apache,項目名稱:incubator-gobblin,代碼行數:24,代碼來源:BatchedPermitsRequesterTest.java


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