Java Code Examples for java.util.Deque#addAll()
The following examples show how to use
java.util.Deque#addAll() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SPARQL12QueryComplianceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected static Object[][] getTestData() { List<Object[]> tests = new ArrayList<>(); Deque<String> manifests = new ArrayDeque<>(); manifests.add(getManifestURL().toExternalForm()); while (!manifests.isEmpty()) { String pop = manifests.pop(); SPARQLQueryTestManifest manifest = new SPARQLQueryTestManifest(pop, excludedSubdirs, false); tests.addAll(manifest.getTests()); manifests.addAll(manifest.getSubManifests()); } Object[][] result = new Object[tests.size()][6]; tests.toArray(result); return result; }
Example 2
Source File: Twister2TranslationContext.java From twister2 with Apache License 2.0 | 6 votes |
/** * Adds all the side inputs into the sink test so it is available from the DoFn's */ private void addInputs(SinkTSet sinkTSet, Map<String, CachedTSet> sideInputTSets) { TBaseGraph graph = sinkTSet.getTBaseGraph(); Set<String> keys = sideInputTSets.keySet(); TBase currNode = null; Deque<TBase> deque = new ArrayDeque<>(); deque.add(sinkTSet); while (!deque.isEmpty()) { currNode = deque.remove(); deque.addAll(graph.getPredecessors(currNode)); if (currNode instanceof ComputeTSet) { if (((ComputeTSet) currNode).getComputeFunc() instanceof DoFnFunction) { Set<String> sideInputKeys = ((DoFnFunction) ((ComputeTSet) currNode).getComputeFunc()).getSideInputKeys(); for (String sideInputKey : sideInputKeys) { if (!sideInputTSets.containsKey(sideInputKey)) { throw new IllegalStateException("Side input not found for key " + sideInputKey); } ((ComputeTSet) currNode).addInput(sideInputKey, sideInputTSets.get(sideInputKey)); } } } } }
Example 3
Source File: SPARQL11UpdateComplianceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static Object[][] getTestData() { List<Object[]> tests = new ArrayList<>(); Deque<String> manifests = new ArrayDeque<>(); manifests.add( SPARQL11UpdateComplianceTest.class.getClassLoader() .getResource("testcases-sparql-1.1-w3c/manifest-all.ttl") .toExternalForm()); while (!manifests.isEmpty()) { String pop = manifests.pop(); SPARQLUpdateTestManifest manifest = new SPARQLUpdateTestManifest(pop); tests.addAll(manifest.tests); manifests.addAll(manifest.subManifests); } Object[][] result = new Object[tests.size()][6]; tests.toArray(result); return result; }
Example 4
Source File: ElementSelectorPanel.java From netbeans with Apache License 2.0 | 6 votes |
private boolean hasMultipleSelectables(ElementNode.Description elementDescription) { Deque<ElementNode.Description> toProcess = new ArrayDeque<>(); if (elementDescription != null) { toProcess.add(elementDescription); } boolean selectableFound = false; while (!toProcess.isEmpty()) { ElementNode.Description d = toProcess.poll(); List<ElementNode.Description> subs = d.getSubs(); if (subs == null) { if (d.isSelectable()) { if (selectableFound) { return true; } selectableFound = true; } } else { toProcess.addAll(subs); } } return false; }
Example 5
Source File: TileRoutedPipe.java From Logistics-Pipes-2 with MIT License | 6 votes |
protected void checkIfRoutesAreReady() { if (!waitingToRoute.isEmpty()) { try { Tuple<LogisticsRoute, ItemStack> route = waitingToRoute.stream() .filter(entry -> entry.getKey().isComplete()) .findFirst().get(); ItemStack item = route.getVal(); Deque<EnumFacing> routeCopy = new ArrayDeque<EnumFacing>(); routeCopy.addAll(route.getKey().getdirectionStack()); EnumFacing side = network.getDirectionForDestination(nodeID); if (hasItemInInventoryOnSide(side, item)) { ItemStack stack = takeFromInventoryOnSide(side, item); catchItem(new LPRoutedItem((double) posX(), (double) posY(), (double) posZ(), stack, side.getOpposite(), this, routeCopy, (TileGenericPipe) route.getKey().getTarget().getMember())); } waitingToRoute.remove(route); } catch (Exception e) { //Discard Exception. If we get any here that means there simply was no route ready yet. } } }
Example 6
Source File: UnreachableCodeEliminator.java From JAADAS with GNU General Public License v3.0 | 6 votes |
private <T> Set<T> reachable(T first, DirectedGraph<T> g) { if ( first == null || g == null ) { return Collections.<T>emptySet(); } Set<T> visited = new HashSet<T>(g.size()); Deque<T> q = new ArrayDeque<T>(); q.addFirst(first); do { T t = q.removeFirst(); if ( visited.add(t) ) { q.addAll(g.getSuccsOf(t)); } } while (!q.isEmpty()); return visited; }
Example 7
Source File: Radon.java From radon with GNU General Public License v3.0 | 5 votes |
/** * Equivalent to the following: * Class clazz1 = something; * Class class2 = somethingElse; * return class1.isAssignableFrom(class2); */ public boolean isAssignableFrom(String type1, String type2) { if ("java/lang/Object".equals(type1)) return true; if (type1.equals(type2)) return true; getClassWrapper(type1); getClassWrapper(type2); ClassTree firstTree = getTree(type1); if (firstTree == null) throw new MissingClassException("Could not find " + type1 + " in the built class hierarchy"); Set<String> allChildren = new HashSet<>(); Deque<String> toProcess = new ArrayDeque<>(firstTree.getSubClasses()); while (!toProcess.isEmpty()) { String s = toProcess.poll(); if (allChildren.add(s)) { getClassWrapper(s); ClassTree tempTree = getTree(s); toProcess.addAll(tempTree.getSubClasses()); } } return allChildren.contains(type2); }
Example 8
Source File: Reflections.java From quarkus with Apache License 2.0 | 5 votes |
private static Method findMethodInternal(Class<?> clazz, String methodName, Class<?>... parameterTypes) { Class<?> theClass = clazz; Deque<Class<?>> interfaces = new ArrayDeque<>(); while (theClass != null) { try { return theClass.getDeclaredMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { interfaces.addAll(Arrays.asList(theClass.getInterfaces())); theClass = theClass.getSuperclass(); } } //look for default methods on interfaces Set<Class<?>> seen = new HashSet<>(interfaces); while (!interfaces.isEmpty()) { Class<?> iface = interfaces.pop(); try { return iface.getDeclaredMethod(methodName, parameterTypes); } catch (NoSuchMethodException ex) { //ignore } for (Class<?> extra : iface.getInterfaces()) { if (seen.add(extra)) { interfaces.add(extra); } } } throw new IllegalArgumentException("Cannot find method " + methodName + Arrays.asList(parameterTypes) + " on " + clazz); }
Example 9
Source File: MCMPHandler.java From lams with GNU General Public License v2.0 | 5 votes |
void addValues(final HttpString name, Deque<String> value) { Deque<String> values = this.values.get(name); for(String i : value) { checkStringForSuspiciousCharacters(i); } if (values == null) { this.values.put(name, value); } else { values.addAll(value); } }
Example 10
Source File: RedissonDequeTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testDescendingIteratorOrigin() { final Deque<Integer> queue = new ArrayDeque<Integer>(); queue.addAll(Arrays.asList(1, 2, 3)); assertThat(queue.descendingIterator()).toIterable().containsExactly(3, 2, 1); }
Example 11
Source File: QueryablePipeline.java From beam with Apache License 2.0 | 5 votes |
/** Produces a {@link RunnerApi.Components} which contains only primitive transforms. */ @VisibleForTesting static Collection<String> getPrimitiveTransformIds(RunnerApi.Components components) { Collection<String> ids = new LinkedHashSet<>(); for (Map.Entry<String, PTransform> transformEntry : components.getTransformsMap().entrySet()) { PTransform transform = transformEntry.getValue(); boolean isPrimitive = isPrimitiveTransform(transform); if (isPrimitive) { // Sometimes "primitive" transforms have sub-transforms (and even deeper-nested // descendents), due to runners // either rewriting them in terms of runner-specific transforms, or SDKs constructing them // in terms of other // underlying transforms (see https://issues.apache.org/jira/browse/BEAM-5441). // We consider any "leaf" descendents of these "primitive" transforms to be the true // "primitives" that we // preserve here; in the common case, this is just the "primitive" itself, which has no // descendents). Deque<String> transforms = new ArrayDeque<>(); transforms.push(transformEntry.getKey()); while (!transforms.isEmpty()) { String id = transforms.pop(); PTransform next = components.getTransformsMap().get(id); List<String> subtransforms = next.getSubtransformsList(); if (subtransforms.isEmpty()) { ids.add(id); } else { transforms.addAll(subtransforms); } } } } return ids; }
Example 12
Source File: AbstractHistoryTree.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public @Nullable E getMatchingInterval(TimeRangeCondition timeCondition, Predicate<E> extraPredicate) { /* Queue a stack of nodes containing nodes intersecting t */ Deque<Integer> queue = new LinkedList<>(); /* We start by reading the information in the root node */ queue.add(getRootNode().getSequenceNumber()); /* Then we follow the down in the relevant children until we find the interval */ try { while (!queue.isEmpty()) { int sequenceNumber = queue.pop(); HTNode<E> currentNode = readNode(sequenceNumber); @Nullable E interval = currentNode.getMatchingInterval(timeCondition, extraPredicate); if (interval != null) { return interval; } if (currentNode.getNodeType() == HTNode.NodeType.CORE) { /* Here we add the relevant children nodes for BFS */ queue.addAll(currentNode.selectNextChildren(timeCondition)); } } } catch (ClosedChannelException e) { } return null; }
Example 13
Source File: AbstractHistoryTree.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public Iterable<E> getMatchingIntervals(TimeRangeCondition timeCondition, Predicate<E> extraPredicate) { // TODO Change this to evaluate the nodes lazily List<E> intervalsOfNodes = new ArrayList<>(); /* Queue is a stack of nodes containing nodes intersecting t */ Deque<Integer> queue = new LinkedList<>(); /* We start by reading the information in the root node */ queue.add(getRootNode().getSequenceNumber()); /* Then we follow the down in the relevant children */ try { while (!queue.isEmpty()) { int sequenceNumber = queue.pop(); HTNode<E> currentNode = readNode(sequenceNumber); TimeRangeCondition nodeCondition = timeCondition.subCondition( currentNode.getNodeStart(), currentNode.getNodeEnd()); if (nodeCondition == null) { continue; } if (currentNode.getNodeType() == HTNode.NodeType.CORE) { /* Here we add the relevant children nodes for BFS */ queue.addAll(currentNode.selectNextChildren(nodeCondition, currentNode.getCoreDataPredicate(extraPredicate))); } Collection<E> nodeIntervals = currentNode.getMatchingIntervals(nodeCondition, extraPredicate); intervalsOfNodes.addAll(nodeIntervals); } } catch (ClosedChannelException e) { } return intervalsOfNodes; }
Example 14
Source File: Closure_130_CollapseProperties_s.java From coming with MIT License | 5 votes |
/** * For each qualified name N in the global scope, we check if: * (a) No ancestor of N is ever aliased or assigned an unknown value type. * (If N = "a.b.c", "a" and "a.b" are never aliased). * (b) N has exactly one write, and it lives in the global scope. * (c) N is aliased in a local scope. * * If (a) is true, then GlobalNamespace must know all the writes to N. * If (a) and (b) are true, then N cannot change during the execution of * a local scope. * If (a) and (b) and (c) are true, then the alias can be inlined if the * alias obeys the usual rules for how we decide whether a variable is * inlineable. * @see InlineVariables */ private void inlineAliases(GlobalNamespace namespace) { // Invariant: All the names in the worklist meet condition (a). Deque<Name> workList = new ArrayDeque<Name>(namespace.getNameForest()); while (!workList.isEmpty()) { Name name = workList.pop(); // Don't attempt to inline a getter or setter property as a variable. if (name.type == Name.Type.GET || name.type == Name.Type.SET) { continue; } if (name.globalSets == 1 && name.localSets == 0 && name.aliasingGets > 0) { // {@code name} meets condition (b). Find all of its local aliases // and try to inline them. List<Ref> refs = Lists.newArrayList(name.getRefs()); for (Ref ref : refs) { if (ref.type == Type.ALIASING_GET && ref.scope.isLocal()) { // {@code name} meets condition (c). Try to inline it. if (inlineAliasIfPossible(ref, namespace)) { name.removeRef(ref); } } } } // Check if {@code name} has any aliases left after the // local-alias-inlining above. if ((name.type == Name.Type.OBJECTLIT || name.type == Name.Type.FUNCTION) && name.aliasingGets == 0 && name.props != null) { // All of {@code name}'s children meet condition (a), so they can be // added to the worklist. workList.addAll(name.props); } } }
Example 15
Source File: Util.java From AILibs with GNU Affero General Public License v3.0 | 5 votes |
public static void refineRecursively(final Interval interval, final int maxNumberOfSubIntervalsPerRefinement, final double basis, final double pointOfConcentration, final double factorForMaximumLengthOfFinestIntervals) { /* first, do a logarithmic refinement */ List<Interval> initRefinement = refineOnLogScale(interval, maxNumberOfSubIntervalsPerRefinement, basis, pointOfConcentration); Collections.reverse(initRefinement); Deque<Interval> openRefinements = new LinkedList<>(); openRefinements.addAll(initRefinement); int depth = 0; do { Interval intervalToRefine = openRefinements.pop(); if (logger.isInfoEnabled()) { StringBuilder offsetSB = new StringBuilder(); for (int i = 0; i < depth; i++) { offsetSB.append("\t"); } logger.info("{}[{}, {}]", offsetSB, intervalToRefine.getInf(), intervalToRefine.getSup()); } /* compute desired granularity for this specific interval */ double distanceToPointOfContentration = Math.min(Math.abs(intervalToRefine.getInf() - pointOfConcentration), Math.abs(intervalToRefine.getSup() - pointOfConcentration)); double maximumLengthOfFinestIntervals = Math.pow(distanceToPointOfContentration + 1, 2) * factorForMaximumLengthOfFinestIntervals; logger.info("{} * {} = {}", Math.pow(distanceToPointOfContentration + 1, 2), factorForMaximumLengthOfFinestIntervals, maximumLengthOfFinestIntervals); List<Interval> refinements = refineOnLinearScale(intervalToRefine, maxNumberOfSubIntervalsPerRefinement, maximumLengthOfFinestIntervals); depth++; if (refinements.size() == 1 && refinements.get(0).equals(intervalToRefine)) { depth--; } else { Collections.reverse(refinements); openRefinements.addAll(refinements); } } while (!openRefinements.isEmpty()); }
Example 16
Source File: SentenceSimilarity.java From uncc2014watsonsim with GNU General Public License v2.0 | 5 votes |
/** Enumerate all of the child parses of a parse tree */ public List<Parse> getAllChildren(List<Parse> parses){ List<Parse> doneChildren = new ArrayList<>(parses.size()); Deque<Parse> nextChildren = new ArrayDeque<>(100); nextChildren.addAll(parses); while (!nextChildren.isEmpty()) { Parse child = nextChildren.remove(); doneChildren.add(child); nextChildren.addAll(Arrays.asList(child.getChildren())); } return doneChildren; }
Example 17
Source File: Closure_130_CollapseProperties_t.java From coming with MIT License | 5 votes |
/** * For each qualified name N in the global scope, we check if: * (a) No ancestor of N is ever aliased or assigned an unknown value type. * (If N = "a.b.c", "a" and "a.b" are never aliased). * (b) N has exactly one write, and it lives in the global scope. * (c) N is aliased in a local scope. * * If (a) is true, then GlobalNamespace must know all the writes to N. * If (a) and (b) are true, then N cannot change during the execution of * a local scope. * If (a) and (b) and (c) are true, then the alias can be inlined if the * alias obeys the usual rules for how we decide whether a variable is * inlineable. * @see InlineVariables */ private void inlineAliases(GlobalNamespace namespace) { // Invariant: All the names in the worklist meet condition (a). Deque<Name> workList = new ArrayDeque<Name>(namespace.getNameForest()); while (!workList.isEmpty()) { Name name = workList.pop(); // Don't attempt to inline a getter or setter property as a variable. if (name.type == Name.Type.GET || name.type == Name.Type.SET) { continue; } if (!name.inExterns && name.globalSets == 1 && name.localSets == 0 && name.aliasingGets > 0) { // {@code name} meets condition (b). Find all of its local aliases // and try to inline them. List<Ref> refs = Lists.newArrayList(name.getRefs()); for (Ref ref : refs) { if (ref.type == Type.ALIASING_GET && ref.scope.isLocal()) { // {@code name} meets condition (c). Try to inline it. if (inlineAliasIfPossible(ref, namespace)) { name.removeRef(ref); } } } } // Check if {@code name} has any aliases left after the // local-alias-inlining above. if ((name.type == Name.Type.OBJECTLIT || name.type == Name.Type.FUNCTION) && name.aliasingGets == 0 && name.props != null) { // All of {@code name}'s children meet condition (a), so they can be // added to the worklist. workList.addAll(name.props); } } }
Example 18
Source File: RolePermissionResolverImpl.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
@Override public Collection<Permission> resolvePermissionsInRole(final String roleString) { checkNotNull(roleString); // check memory-sensitive cache; use cached value as long as config is not dirty Collection<Permission> cachedPermissions = rolePermissionsCache.getIfPresent(roleString); if (cachedPermissions != null) { return cachedPermissions; } final Set<Permission> permissions = new LinkedHashSet<>(); final Deque<String> rolesToProcess = new ArrayDeque<>(); final Set<String> processedRoleIds = new HashSet<>(); // initial role rolesToProcess.add(roleString); while (!rolesToProcess.isEmpty()) { final String roleId = rolesToProcess.removeFirst(); if (processedRoleIds.add(roleId)) { if (roleNotFoundCache.getIfPresent(roleId) != null) { log.trace("Role {} found in NFC, role check skipped", roleId); continue; // use cached results } try { // try to re-use results when resolving the role tree cachedPermissions = rolePermissionsCache.getIfPresent(roleId); if (cachedPermissions != null) { permissions.addAll(cachedPermissions); continue; // use cached results } final CRole role = configuration.readRole(roleId); // process the roles this role has recursively rolesToProcess.addAll(role.getRoles()); // add the permissions this role has for (String privilegeId : role.getPrivileges()) { Permission permission = permission(privilegeId); if (permission != null) { permissions.add(permission); } } } catch (NoSuchRoleException e) { log.trace("Ignoring missing role: {}", roleId, e); roleNotFoundCache.put(roleId, ""); } } } // cache result of (non-trivial) computation rolePermissionsCache.put(roleString, permissions); return permissions; }
Example 19
Source File: ReportAnalyzer.java From quarkus with Apache License 2.0 | 4 votes |
/** * Analyze the contents of the call tree report produced by Substrate when using -H:+PrintAnalysisCallTree, * and does a more meaningful analysis of what is causing a type to be retained. * * In particular for virtual or interface methods that have multiple implementations what is calling this method * is not really important, its what caused this particular instance of the class to be created that is important * (e.g. if you have an instance of Runnable, you don't care about all the different parts that call runnable, you * care about what created this particular instance). * * If a virtual or interface call is detected with multiple implementations then printing the current call flow * is abandoned, and instead the call flow for the constructor of the current object is printed instead. * */ public String analyse(String className, String methodName) throws Exception { List<Node> dm = byClassMap.getOrDefault(className, new ArrayList<>()).stream() .filter((s) -> s.method.startsWith(methodName + "(")).collect(Collectors.toList()); Deque<Node> runQueue = new ArrayDeque<>(dm); Set<String> attemptedClasses = new HashSet<>(); if (methodName.equals("<init>")) { attemptedClasses.add(className); } StringBuilder ret = new StringBuilder(); StringBuilder sb = new StringBuilder(); while (!runQueue.isEmpty()) { Node current = runQueue.pop(); sb.append("Possible path to " + current.className + "." + current.method + "\n"); while (current != null) { sb.append("\t" + current.className + "." + current.method + '\n'); String reason = null; if (current.parent == null || current.parent.children.size() > 1) { if (current.type.equals("is overridden by")) { reason = "This is an implementation of " + current.parent.className + " printing path to constructors of " + current.className + "\n"; } else if (current.type.equals("is implemented by")) { reason = "This is an implementation of " + current.parent.className + " printing path to constructors of " + current.className + "\n"; } } if (reason != null) { if (!attemptedClasses.contains(current.className)) { attemptedClasses.add(current.className); List<Node> toAdd = constructors.getOrDefault(current.className, new ArrayList<>()); runQueue.addAll(toAdd); sb.append(reason + '\n'); sb.append("\n"); ret.append(sb); } //note that we discard the string builder if it is part of attemptedClasses, as this basically //represents an alternate path that we have already displayed sb.setLength(0); break; } current = current.parent; } } ret.append(sb); return ret.toString(); }
Example 20
Source File: InverseDepsAnalyzer.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Returns all paths reachable from the given targets. */ private Set<Deque<Archive>> findPaths(Graph<Archive> graph, Archive target) { // path is in reversed order Deque<Archive> path = new LinkedList<>(); path.push(target); Set<Edge<Archive>> visited = new HashSet<>(); Deque<Edge<Archive>> deque = new LinkedList<>(); deque.addAll(graph.edgesFrom(target)); if (deque.isEmpty()) { return makePaths(path).collect(Collectors.toSet()); } Set<Deque<Archive>> allPaths = new HashSet<>(); while (!deque.isEmpty()) { Edge<Archive> edge = deque.pop(); if (visited.contains(edge)) continue; Archive node = edge.v; path.addLast(node); visited.add(edge); Set<Edge<Archive>> unvisitedDeps = graph.edgesFrom(node) .stream() .filter(e -> !visited.contains(e)) .collect(Collectors.toSet()); trace("visiting %s %s (%s)%n", edge, path, unvisitedDeps); if (unvisitedDeps.isEmpty()) { makePaths(path).forEach(allPaths::add); path.removeLast(); } // push unvisited adjacent edges unvisitedDeps.stream().forEach(deque::push); // when the adjacent edges of a node are visited, pop it from the path while (!path.isEmpty()) { if (visited.containsAll(graph.edgesFrom(path.peekLast()))) path.removeLast(); else break; } } return allPaths; }