Internal routine to locate a parent (recursive, don't loop your trees!).

@param parent  The parent to start searching with.
@param account The account to find the parent of.
@return The parent account, else null if not found.
965306
private Account findParent(Account parent, Account account) {
        if (parent == null || account == null)
            return null;

        // Does this parent contain the child account?
        if (parent.getChildren().contains(account))
            return parent;

        // Recurse through the children
        for (Account child : parent.getChildren()) {
            Account theOne = findParent(child, account);
            if (theOne != null)
                return theOne;
        }

        return null;
    }
1124386
public int setParent(Node parent)
    {
        if (parent != null)
        {
            depth = parent.getDepth() + 1;
        }
        this.parent = parent;
        return depth;
    }
72652
private function buildTree($account, &$data, $parent) {
    $data[] = array($account['name'], null, 1);
    if ($account['subAccounts']) {
      foreach($account['subAccounts'] as $subAccount) {
        $this->buildTree($subAccount, $data, $account['name']);
      }
    }
  }
104519
public SubMenuItem findParent(MenuItem toFind) {
        synchronized (subMenuItems) {
            SubMenuItem parent = MenuTree.ROOT;
            for (Map.Entry<MenuItem, ArrayList<MenuItem>> entry : subMenuItems.entrySet()) {
                for (MenuItem item : entry.getValue()) {
                    if (item.getId() == toFind.getId()) {
                        parent = asSubMenu(entry.getKey());
                    }
                }
            }
            return parent;
        }
    }
283415
public T accountPath(ImmutableList<ChildNumber> accountPath) {
            checkState(watchingKey == null, "either watch or accountPath");
            this.accountPath = checkNotNull(accountPath);
            return self();
        }
1179297
public void setParent( IVarDef parent)
    {
    parent_ = parent;
    pathName_ = null;
    effCondition_ = null;
    position_ = null;
    }
1102408
protected int _parent(int identity)
  {

    if (identity < m_size)
      return m_parent.elementAt(identity);

    // Check to see if the information requested has been processed, and,
    // if not, advance the iterator until we the information has been
    // processed.
    while (true)
    {
      boolean isMore = nextNode();

      if (identity >= m_size && !isMore)
        return NULL;
      else if (identity < m_size)
        return m_parent.elementAt(identity);
    }
  }
809965
def get_parent(self):
        
        if self._parent and self._parent.object_id == self.parent_id:
            return self._parent
        else:
            if self.parent_id:
                return self.drive.get_item(self.parent_id)
            else:
                # return the drive
                return self.drive
996645
@Override
  public Key getParent() {
    List<PathElement> ancestors = getAncestors();
    if (ancestors.isEmpty()) {
      return null;
    }
    PathElement parent = ancestors.get(ancestors.size() - 1);
    Key.Builder keyBuilder;
    if (parent.hasName()) {
      keyBuilder = Key.newBuilder(getProjectId(), parent.getKind(), parent.getName());
    } else {
      keyBuilder = Key.newBuilder(getProjectId(), parent.getKind(), parent.getId());
    }
    String namespace = getNamespace();
    if (namespace != null) {
      keyBuilder.setNamespace(namespace);
    }
    return keyBuilder.addAncestors(ancestors.subList(0, ancestors.size() - 1)).build();
  }
1166956
def parent_for_matching_rest_name(self, rest_names):
        

        parent = self

        while parent:
            if parent.rest_name in rest_names:
                return parent

            parent = parent.parent_object

        return None
1011007
@Nullable
  protected String getParentPath(String path) {
    // Root does not have a parent.
    if (isRoot(path)) {
      return null;
    }
    int separatorIndex = path.lastIndexOf(PATH_SEPARATOR);
    if (separatorIndex < 0) {
      return null;
    }
    return path.substring(0, separatorIndex);
  }
477688
private Object parentValue(Object pojo) {
        Object parentValue = parent.getValue(pojo);
        if (parentValue == null && autoCreateParent) {
            Object newParent = ReflectionUtils.newInstance(parent.getType().getRawType());
            parent.setValue(pojo, newParent);
            return newParent;
        }
        return parentValue;
    }
1247424
def get_parent_of(record, path)
      parent_object = path[0..-2].reduce(record) { |a, e| a.is_a?(Hash) ? a[e] : nil }
      [parent_object, path[-1]]
    end
292044
def FindParentMember(cls, typecheck_parent, name):
    """"""
    if typecheck_parent and hasattr(typecheck_parent, name):
      return getattr(typecheck_parent, name)
    return None
858966
public static LocalDocument findLocalDocumentByParentAndUrlName(Folder parentFolder, String urlName) {
    ResourceDAO resourceDAO = new ResourceDAO();
    
    Resource resource = resourceDAO.findByUrlNameAndParentFolder(urlName, parentFolder);
    if (resource instanceof LocalDocument) {
      return (LocalDocument) resource;
    }
    
    return null;
  }
1249821
public static <T> T findAttributeParent(String fromTagName, JspTag from, String attribute, Class<? extends T> clazz) throws NeedAttributeParentException {
		T parent = clazz.cast(SimpleTagSupport.findAncestorWithClass(from, clazz));
		if(parent==null) throw new NeedAttributeParentException(fromTagName, attribute);
		return parent;
	}
1158778
public void setParents(java.util.Collection<String> parents) {
        if (parents == null) {
            this.parents = null;
            return;
        }

        this.parents = new java.util.ArrayList<String>(parents);
    }