Returns all entries found exactly one level below parent. Throws {@link NoSuchNodeException} if resolving the
argument Dn fails at its leaf. Throws {@link MissingParentException} if resolving fails earlier.
550061
public List<Entry> getDirectChildren(Dn parent) throws NoSuchNodeException, MissingParentException {
        return extractEntriesFromCursor(searchOneLevel(parent));
    }
341352
public void depthFirstSearch(Context context, SearchResultVisitor visitor, Resource root) {
        ArrayDeque<SearchResults.Result> stack = Queues.newArrayDeque();

        // Build an instance of a SearchResult for the root resource
        // but don't invoke the visitor with it
        boolean skipFirstVisit = true;
        SearchResults initialResults = new SearchResults();
        initialResults.addResult(root, new ArrayList<String>(0));
        stack.add(initialResults.iterator().next());

        while (!stack.isEmpty()) {
            SearchResults.Result r = stack.pop();
            if (skipFirstVisit) {
                skipFirstVisit = false;
            } else {
                if (!visitor.visit(r)) {
                    return;
                }
            }

            // Reverse the order of the results so we walk the left-most
            // branches first
            ImmutableList<SearchResults.Result> results = ImmutableList.copyOf(m_searcher.search(
                    context, matchKeyAndValue(Constants.PARENT_TERM_FIELD, r.getResource().getId())));
            for (SearchResults.Result result : results.reverse()) {
                stack.push(result);
            }
        }
    }
1259594
private boolean findInclusiveNa(int colIdToFind) {
    if (parent == null) {
      return true;
    }
    else if (parent.getColId() == colIdToFind) {
      return inclusiveNa;
    }
    return parent.findInclusiveNa(colIdToFind);
  }
458746
private static Node getFirstNonEmptyChild(Node n) {
    for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
      if (c.isBlock()) {
        Node result = getFirstNonEmptyChild(c);
        if (result != null) {
          return result;
        }
      } else if (!c.isEmpty()) {
        return c;
      }
    }
    return null;
  }
370437
public TrieNode getParent() {
    if (0 == index) return null;
    if (null == parent && -1 == depth) {
      synchronized (this) {
        if (null == parent) {
          parent = newNode(trie.parentIndex[index]);
          assert (parent.index < index);
        }
      }
    }
    return parent;
  }
103386
public Set<N> getParents(N n)
    {
        Pair<HashSet<N>, HashSet<N>> p = nodes.get(n);
        
        if(p == null)
            return null;
        
        return p.getIncoming();
    }
1260945
public List<Node> findSiblings(Node node) {
      Preconditions.checkNotNull(node);
    
      Node parent = node.parent();
      if (null == parent) return null;

      return parent.childNodes();               
  }
409335
private void treeWalker(Node node, int level, List<PathQueryMatcher> queryMatchers, List<Node> collector) {
        MatchType matchType = queryMatchers.get(level).match(level, node);
        if(matchType == MatchType.NOT_A_MATCH) {
            // no reason to scan deeper
            //noinspection UnnecessaryReturnStatement
            return;
        } else if(matchType == MatchType.NODE_MATCH) {
            // we have a match
            if(level == queryMatchers.size()-1) {
                // full path match
                collector.add(node);
            } else if(node instanceof Element) {
                // scan deeper
                Element element = (Element) node;
                List<Node> childElements = element.getChildElements();
                for (Node childElement : childElements) {
                    treeWalker(childElement, level+1, queryMatchers, collector);
                }
            }
        } else {
            throw new PathQueryException("Unknown MatchType: " + matchType);
        }
    }
217048
private int depth() {
        int i = 0;
        for (TreeString p = this; p != null; p = p.parent) {
            i++;
        }
        return i;
    }
98813
@SuppressWarnings("unchecked")
    private final int checkNodeDirectory() throws ClusterInfoException {
        try {

            // get all of the nodes in the nodeDir and set one for this node if it's not already set.
            final Collection<String> nodeDirs;
            if (nodeDirectory == null) {
                nodeDirectory = utils.session.recursiveMkdir(utils.nodesDir + "/node_", thisNode, DirMode.PERSISTENT,
                        DirMode.EPHEMERAL_SEQUENTIAL);
                nodeDirs = session.getSubdirs(utils.nodesDir, this);
            } else
                nodeDirs = utils.persistentGetSubdir(utils.nodesDir, null);

            // what node am I?
            int nodeRank = -1;
            int index = 0;
            final String nodeSubdir = new File(nodeDirectory).getName();
            for (final String cur : nodeDirs) {
                if (nodeSubdir.equals(cur)) {
                    nodeRank = index;
                    break;
                }
                index++;
            }

            // If I couldn't find me, there's a problem.
            if (nodeRank == -1) {
                // drop the node directory since it clearly doesn't exist anymore
                nodeDirectory = null;
                throw new ClusterInfoException(
                        "Node " + thisNode + " was registered at " + nodeSubdir + " but it wasn't found as a subdirectory.");
            }

            // verify the container address is correct.
            C curDest = (C) session.getData(nodeDirectory, null);
            if (curDest == null) // this really can't be null
                session.setData(nodeDirectory, thisNode);
            else if (!thisNode.equals(curDest)) { // wth?
                final String tmp = nodeDirectory;
                nodeDirectory = null;
                throw new ClusterInfoException("Impossible! The Node directory " + tmp + " contains the destination for " + curDest
                        + " but should have " + thisNode);
            }

            // Check to make sure that THIS node is only in one place. If we find it in a node directory
            // that's not THIS node directory then this is something we should clean up.
            for (final String subdir : nodeDirs) {
                final String fullPathToSubdir = utils.nodesDir + "/" + subdir;
                curDest = (C) session.getData(fullPathToSubdir, null);
                if (thisNode.equals(curDest) && !fullPathToSubdir.equals(nodeDirectory)) // this is bad .. clean up
                    session.rmdir(fullPathToSubdir);
            }

            return nodeRank;
        } catch (final ClusterInfoException cie) {
            cleanupAfterExceptionDuringNodeDirCheck();
            throw cie;
        } catch (final RuntimeException re) {
            cleanupAfterExceptionDuringNodeDirCheck();
            throw re;
        } catch (final Throwable th) {
            cleanupAfterExceptionDuringNodeDirCheck();
            throw new RuntimeException("Unknown exception!", th);
        }
    }
1247767
public Iterable<Entry<String, ProfileNode>> getDescendingOrderedNodes() {
			if( nodes == null ) return null;
			
			List<Entry<String, ProfileNode>> averageStepTimes = new LinkedList<Entry<String, ProfileNode>>(nodes.entrySet());
			
			Collections.sort(averageStepTimes, new Comparator<Entry<String, ProfileNode>>() {
				public int compare(Entry<String, ProfileNode> o1, Entry<String, ProfileNode> o2) {
					return (int) (o1.getValue().totalMillisecs - o2.getValue().totalMillisecs);
				}
			});
			
			
			return averageStepTimes;
	}
1273313
public final CountedCompleter<?> getRoot() {
    CountedCompleter<?> a = this, p;
    while ((p = a.completer) != null)
      a = p;
    return a;
  }
1252825
public T result() throws NoSuchElementException {
    if (result == NULL_RESULT) {
      if (parent != null) {
        return parent.result();
      }
      throw new NoSuchElementException("There is no result");
    }
    return result;
  }
1279563
private void getDescendants(Entity entity, LdapEntry ldapEntry, DescendantControl descCtrl) throws WIMException {
        if (descCtrl == null) {
            return;
        }

        List<String> propNames = descCtrl.getProperties();
        int level = descCtrl.getLevel();
        List<String> descTypes = getEntityTypes(descCtrl);
        String[] bases = getBases(descCtrl, descTypes);
        boolean treeView = descCtrl.isSetTreeView();
        int scope = SearchControls.ONELEVEL_SCOPE;
        if (level == 0 && !treeView) {
            scope = SearchControls.SUBTREE_SCOPE;
        }
        Set<String> descToDo = new HashSet<String>();
        Map<String, Entity> descendants = new HashMap<String, Entity>();
        Set<LdapEntry> descEntries = iLdapConn.searchEntities(ldapEntry.getDN(), "objectClass=*", null, scope, descTypes,
                                                              propNames, false, false);
        for (LdapEntry descEntry : descEntries) {
            String descType = descEntry.getType();
            String descDn = descEntry.getDN();
            Entity descendant = null;
            if (LdapHelper.isUnderBases(descDn, bases) && descTypes.contains(descType)) {
                descendant = createEntityFromLdapEntry(entity, SchemaConstants.DO_CHILDREN, descEntry, propNames);
            } else if (treeView) {
                descendant = createEntityFromLdapEntry(entity, SchemaConstants.DO_CHILDREN, descEntry, null);
            }
            if (treeView) {
                descToDo.add(descDn);
                descendants.put(descDn, descendant);
            }
        }
        if (treeView) {
            while (descToDo.size() > 0) {
                Set<String> nextDescs = new HashSet<String>();
                for (String dn : descToDo) {
                    Entity parent = descendants.get(dn);
                    descEntries = iLdapConn.searchEntities(dn, "objectClass=*", null, scope, descTypes, propNames,
                                                           false, false);
                    for (LdapEntry descEntry : descEntries) {
                        String descType = descEntry.getType();
                        String descDn = descEntry.getDN();
                        Entity descendant = null;
                        if (descTypes.contains(descType)) {
                            descendant = createEntityFromLdapEntry(parent, SchemaConstants.DO_CHILDREN, descEntry, propNames);
                        } else if (treeView) {
                            descendant = createEntityFromLdapEntry(parent, SchemaConstants.DO_CHILDREN, descEntry, null);
                        }
                        if (!descToDo.contains(descDn)) {
                            nextDescs.add(descDn);
                            descendants.put(descDn, descendant);
                        }
                    }
                }
                descToDo = nextDescs;
            }
        }
    }
281250
@Nullable
  public final Node getAncestor(int level) {
    checkArgument(level >= 0);
    Node node = this;
    while (node != null && level-- > 0) {
      node = node.getParent();
    }
    return node;
  }
100498
private Collection<Group> findGroups(Session session, Group parent, boolean recursive) throws Exception
   {
      List<Group> groups = new ArrayList<Group>();
      String parentId = parent == null ? "" : parent.getId();

      NodeIterator childNodes = utils.getGroupNode(session, parentId).getNodes();

      while (childNodes.hasNext())
      {
         Node groupNode = childNodes.nextNode();
         if (!groupNode.getName().startsWith(JCROrganizationServiceImpl.JOS_MEMBERSHIP))
         {
            Group group = readGroup(groupNode);
            groups.add(group);

            if (recursive)
            {
               groups.addAll(findGroups(session, group, recursive));
            }
         }
      }

      return groups;
   }
6462
@Override
  public Description matchEmptyStatement(EmptyStatementTree tree, VisitorState state) {
    boolean matches = false;
    Tree parent = state.getPath().getParentPath().getLeaf();
    if (parent.getKind() == IF) {
      IfTree parentAsIf = (IfTree) parent;
      matches =
          (parentAsIf.getThenStatement() instanceof EmptyStatementTree)
              && (parentAsIf.getElseStatement() == null);
    }
    if (!matches) {
      return Description.NO_MATCH;
    }

    /*
     * We suggest different fixes depending on what follows the parent if statement.
     * If there is no statement following the if, then suggest deleting the whole
     * if statement. If the next statement is a block, then suggest deleting the
     * empty then part of the if.  If the next statement is not a block, then also
     * suggest deleting the empty then part of the if.
     */
    boolean nextStmtIsNull =
        parentNode(nextStatement(Matchers.<StatementTree>isSame(null))).matches(tree, state);

    assert (state.getPath().getParentPath().getLeaf().getKind() == IF);
    IfTree ifParent = (IfTree) state.getPath().getParentPath().getLeaf();
    if (nextStmtIsNull) {
      // No following statements. Delete whole if.
      return describeMatch(parent, SuggestedFix.delete(parent));
    } else {
      // There are more statements. Delete the empty then part of the if.
      return describeMatch(
          ifParent.getThenStatement(), SuggestedFix.delete(ifParent.getThenStatement()));
    }
  }