Refine search
private Set<AbstractProject> getTransitive(Map<AbstractProject, List<DependencyGroup>> direction, AbstractProject src, boolean up) { Set<AbstractProject> visited = new HashSet<AbstractProject>(); Stack<AbstractProject> queue = new Stack<AbstractProject>(); queue.add(src); while(!queue.isEmpty()) { AbstractProject p = queue.pop(); for (AbstractProject child : get(direction,p,up)) { if(visited.add(child)) queue.add(child); } } return visited; }
private Set<Class> findAllInterfacesInHierarchy(Class candidateGoExtensionClass) { Stack<Class> classesInHierarchy = new Stack<>(); classesInHierarchy.add(candidateGoExtensionClass); Set<Class> interfaces = new HashSet<>(); while (!classesInHierarchy.empty()) { Class classToCheckFor = classesInHierarchy.pop(); if (classToCheckFor.isInterface()) { interfaces.add(classToCheckFor); } classesInHierarchy.addAll(Arrays.asList(classToCheckFor.getInterfaces())); if (classToCheckFor.getSuperclass() != null) { classesInHierarchy.add(classToCheckFor.getSuperclass()); } } return interfaces; }
private static boolean hasAnnotation(Annotation annotation, Collection<Class<? extends Annotation>> desired) { Set<Class<? extends Annotation>> seen = new HashSet<Class<? extends Annotation>>(); Stack<Class<? extends Annotation>> toCheck = new Stack<Class<? extends Annotation>>(); toCheck.add(annotation.annotationType()); while (!toCheck.isEmpty()) { Class<? extends Annotation> annotationType = toCheck.pop(); if (desired.contains(annotationType)) { return true; } seen.add(annotationType); for (Annotation annotationTypesAnnotations : annotationType.getAnnotations()) { if (!seen.contains(annotationTypesAnnotations.annotationType())) { toCheck.add(annotationTypesAnnotations.annotationType()); } } } return false; }
/** * Returns the first descendant of a component that is an * <code>RTextArea</code>. This is primarily here to support * <code>javax.swing.JLayer</code>s that wrap <code>RTextArea</code>s. * * @param comp The component to recursively look through. * @return The first descendant text area, or <code>null</code> if none * is found. */ private static RTextArea getFirstRTextAreaDescendant(Component comp) { Stack<Component> stack = new Stack<Component>(); stack.add(comp); while (!stack.isEmpty()) { Component current = stack.pop(); if (current instanceof RTextArea) { return (RTextArea)current; } if (current instanceof Container) { Container container = (Container)current; stack.addAll(Arrays.asList(container.getComponents())); } } return null; }
public TreeNode<E,T> balance(TreeNode<E,T> node) { if (debug) check(node); Stack<TreeNode<E,T>> todo = new Stack<>(); todo.add(node); TreeNode<E,T> newRoot = null; while (!todo.isEmpty()) { TreeNode<E,T> n = todo.pop(); // Balance tree between this node // Select median nodes and try to balance the tree int medianAt = n.size/2; TreeNode<E,T> median = getNode(n, medianAt); // Okay, this is going to be our root if (median != null && median != n) { // Yes, there is indeed something to be done rotateUp(median, n); } if (newRoot == null) { newRoot = median; } if (median.left != null) todo.push(median.left); if (median.right != null) todo.push(median.right); } if (newRoot == null) return node; else return newRoot; }
@Override public List<InspectableComponent> extract(LithoView lithoView) { final List<InspectableComponent> res = new LinkedList<>(); final Stack<InspectableComponent> stack = new Stack<>(); final InspectableComponent rootInstance = InspectableComponent.getRootInstance(lithoView); Preconditions.checkNotNull( rootInstance, "Could not obtain DebugComponent. " + "Please ensure that ComponentsConfiguration.IS_INTERNAL_BUILD is enabled."); stack.add(rootInstance); while (!stack.isEmpty()) { final InspectableComponent inspectableComponent = stack.pop(); res.add(inspectableComponent); for (InspectableComponent child : inspectableComponent.getChildComponents()) { stack.push(child); } } return res; }
public static <E extends Comparable<E>, T extends HasInterval<E>> boolean overlaps(TreeNode<E,T> node, Interval<E> target) { Stack<TreeNode<E,T>> todo = new Stack<>(); todo.push(node); while (!todo.isEmpty()) { TreeNode<E,T> n = todo.pop(); // Don't search nodes that don't exist if (n == null || n.isEmpty()) continue; // If target is to the right of the rightmost point of any interval // in this node and all children, there won't be any matches. if (target.first.compareTo(n.maxEnd) > 0) continue; // Check this node if (n.value.getInterval().overlaps(target)) { return true; } // Search left children if (n.left != null) { todo.add(n.left); } // If target is to the left of the start of this interval, // then it can't be in any child to the right. if (target.second.compareTo(n.value.getInterval().first()) < 0) { continue; } if (n.right != null) { todo.add(n.right); } } return false; }
static Part findPartById(Part searchRoot, long partId) { if (searchRoot instanceof LocalMessage) { LocalMessage localMessage = (LocalMessage) searchRoot; if (localMessage.getMessagePartId() == partId) { return localMessage; } } Stack<Part> partStack = new Stack<>(); partStack.add(searchRoot); while (!partStack.empty()) { Part part = partStack.pop(); if (part instanceof LocalPart) { LocalPart localBodyPart = (LocalPart) part; if (localBodyPart.getPartId() == partId) { return part; } } Body body = part.getBody(); if (body instanceof Multipart) { Multipart innerMultipart = (Multipart) body; for (BodyPart innerPart : innerMultipart.getBodyParts()) { partStack.add(innerPart); } } if (body instanceof Part) { partStack.add((Part) body); } } return null; }
/** * Iterative implementation of this binary tree traversal. The complexity order in time terms of * this algorithm is O(N) where N is the number of nodes in the tree. In space terms the * complexity order of this algorithm is also O(N) where N is the number of nodes we have to * store in the auxiliary data structure, the stack. */ public List<BinaryNode> getIterative(BinaryNode root) { validateBinaryNode(root); List<BinaryNode> result = new LinkedList<BinaryNode>(); Stack<BinaryNode> stack = new Stack<BinaryNode>(); stack.push(root); while (!stack.isEmpty()) { BinaryNode node = stack.pop(); result.add(node); if (node.hasRight()) { stack.add(node.getRight()); } if (node.hasLeft()) { stack.add(node.getLeft()); } } return result; }
/** * @param source an Alluxio URI * @param fileSystem the Alluxio file system * @return whether the URI is a file or a directory which contains files (including recursively) * @throws Exception if an unexpected exception occurs */ private static boolean hasFiles(AlluxioURI source, FileSystem fileSystem) throws Exception { Stack<AlluxioURI> dirsToCheck = new Stack<>(); dirsToCheck.add(source); while (!dirsToCheck.isEmpty()) { try { for (URIStatus status : fileSystem.listStatus(dirsToCheck.pop())) { if (!status.isFolder()) { return true; } dirsToCheck.push(new AlluxioURI(status.getPath())); } } catch (FileDoesNotExistException e) { // This probably means another worker has deleted the directory already, so we can probably // return false here. To be safe though, we will fall through and complete the search. } } return false; }
/** * Extracts all columns from the given filter query tree. */ public static Set<String> extractFilterColumns(FilterQueryTree root) { Set<String> filterColumns = new HashSet<>(); if (root.getChildren() == null) { filterColumns.add(root.getColumn()); } else { Stack<FilterQueryTree> stack = new Stack<>(); stack.add(root); while (!stack.empty()) { FilterQueryTree node = stack.pop(); for (FilterQueryTree child : node.getChildren()) { if (child.getChildren() == null) { filterColumns.add(child.getColumn()); } else { stack.push(child); } } } } return filterColumns; }
public void check(TreeNode<E,T> treeNode) { Stack<TreeNode<E,T>> todo = new Stack<>(); todo.add(treeNode); while (!todo.isEmpty()) { TreeNode<E,T> node = todo.pop(); if (node == node.parent) { throw new IllegalStateException("node is same as parent!!!"); if (node.left != null) todo.add(node.left); if (node.right != null) todo.add(node.right);