Returns the root element or its alternative branches if it is an {@link Alternatives} or an
{@link UnorderedGroup}. In case of an {@link UnorderedGroup} the result contains only the elements that are not
yet processed up to the relevant cursor position.
320432
protected Collection<AbstractElement> getElementsToParse(AbstractElement root,
			List<AbstractElement> handledUnorderedGroupElements) {
		if (root instanceof UnorderedGroup) {
			if (handledUnorderedGroupElements.isEmpty())
				return ((CompoundElement) root).getElements();
			List<AbstractElement> result = Lists.newArrayList(root);
			for (AbstractElement child : ((UnorderedGroup) root).getElements()) {
				if (!handledUnorderedGroupElements.contains(child)) {
					result.add(child);
				}
			}
			return result;
		}
		return getElementsToParse(root);
	}
514142
@Nonnull
  public ExpressionTreeElement getRoot() {
    if (last.isEmptySlot()) {
      return this.last;
    } else {
      ExpressionTreeElement element = last;
      while (!Thread.currentThread().isInterrupted()) {
        final ExpressionTreeElement next = element.getParent();
        if (next == null) {
          return element;
        } else {
          element = next;
        }
      }
    }
    return ExpressionTreeElement.EMPTY_SLOT;
  }
534574
function getElementRoot(element) {
        var curr = element;
        while (curr.parentNode) {
            curr = curr.parentNode;
        }
        return curr;
    }
1278255
public Optional<String> getRoot() {
        final LinkedList<String> uuids = context.get();
        return uuids.isEmpty()
                ? Optional.empty()
                : Optional.of(uuids.getLast());
    }
586391
private static Element getFirstChildElement(Node parent) {
		NodeList nodeList = parent.getChildNodes();
		for (int i = 0; i < nodeList.getLength(); i++) {
			Node node = nodeList.item(i);
			if (node instanceof Element) {
				return (Element) node;
			}
		}
		return null;
	}
644115
public boolean nextInnerElement(ElementContext parent) throws XMLException, IOException {
		if (event.context.isEmpty()) return false;
		if (Type.START_ELEMENT.equals(event.type) && event.context.getFirst() == parent && event.isClosed)
			return false; // we are one the opening tag of the parent, and it is closed, so it has no content
		if (Type.END_ELEMENT.equals(event.type) && event.context.getFirst() == parent)
			return false;
		try {
			do {
				next();
				if (Type.END_ELEMENT.equals(event.type)) {
					if (event.context.getFirst() == parent)
						return false;
				}
				if (Type.START_ELEMENT.equals(event.type)) {
					if (event.context.size() > 1 && event.context.get(1) == parent)
						return true;
				}
			} while (true);
		} catch (EOFException e) {
			return false;
		}
	}
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;
  }
60301
private String getRealIconRoot()
    {
        if (_iconRoot != null)
            return _iconRoot;
        if (_parent != null)
            return _parent.getRealIconRoot();
        return null;
    }
674027
@SuppressWarnings( "unchecked" )
    public <V> Key<V> getRoot() {
        if ( this.getParent() == null ) {
            return (Key<V>) this;
        } else {
            return this.getParent().getRoot();
        }
    }
1004800
public static <T extends TreeNode<T>> T getRoot(T node) {
        if (node == null) return null;
        if (node.getParent() != null) return getRoot(node.getParent());
        return node;
    }
860430
public Node nextSibling() {
        if (parentNode == null)
            return null; // root

        final List<Node> siblings = parentNode.ensureChildNodes();
        final int index = siblingIndex+1;
        if (siblings.size() > index)
            return siblings.get(index);
        else
            return null;
    }
802587
@Override
    public String getRootFolderId() {
        if (rootNodeId == null) {
            Document layout = getUserLayoutDOM();

            Element rootNode =
                    this.xpathOperations.evaluate("//layout/folder", layout, XPathConstants.NODE);
            if (rootNode == null
                    || !rootNode.getAttribute(Constants.ATT_TYPE)
                            .equals(Constants.ROOT_FOLDER_ID)) {
                LOG.error(
                        "Unable to locate root node in layout of "
                                + owner.getUserName()
                                + ". Resetting corrupted layout.");
                resetLayout((String) null);

                rootNode =
                        this.xpathOperations.evaluate(
                                "//layout/folder", layout, XPathConstants.NODE);
                if (rootNode == null
                        || !rootNode.getAttribute(Constants.ATT_TYPE)
                                .equals(Constants.ROOT_FOLDER_ID)) {
                    throw new PortalException(
                            "Corrupted layout detected for "
                                    + owner.getUserName()
                                    + " and resetting layout failed.");
                }
            }
            rootNodeId = rootNode.getAttribute("ID");
        }
        return rootNodeId;
    }
1038982
public static final Element getNextSiblingElement(Node node) {
    	
    	List<Node> siblings = node.getParent().getChildren();
    	Node n = null;
    	
    	int index = siblings.indexOf(node) + 1;
    	if(index>0 && index<siblings.size()) {
	    	n = siblings.get(index);
	    	while(!(n instanceof Element) && ++index < siblings.size()) {
	    		n = siblings.get(index);
	    	}
	    	
	    	if(index==siblings.size()) {
	    		n = null;
	    	}
    	}
    	
        return (Element) n;
    }
1289384
public IntList getRoots() {
    IntList roots = new IntArrayList();
    for(int i = 0; i < used; i++) {
      // roots or one element in component
      if(parent[i] == i) {
        roots.add(i);
      }
    }
    return roots;
  }
288077
private static final int siblingIndex(Element element) {

        // The document element has index 0
        if (element.getParentNode() == element.getOwnerDocument())
            return 0;

        // All other elements are compared with siblings with the same name
        // TODO: How to deal with namespaces here? Omit or keep?
        else
            return $(element).parent().children(JOOX.tag(element.getTagName(), false)).get().indexOf(element);
    }
89056
public static Element[] getChildren( Element root, String name )
    {
        if( null == root )
        {
            return new Element[0];
        }
        NodeList list = root.getElementsByTagName( name );
        int n = list.getLength();
        ArrayList<Element> result = new ArrayList<Element>();
        for( int i = 0; i < n; i++ )
        {
            Node item = list.item( i );
            if( item instanceof Element )
            {
                result.add( (Element) item );
            }
        }
        Element[] retval = new Element[result.size()];
        result.toArray( retval );
        return retval;
    }
1143135
private static URL findBaseURI(final Element root) {
        URL baseURI = null;
        final List<Element> linksList = root.getChildren("link", OS_NS);
        if (linksList != null) {
            for (final Element element : linksList) {
                final Element link = element;
                if (!root.equals(link.getParent())) {
                    break;
                }
                String href = link.getAttribute("href").getValue();
                if (link.getAttribute("rel", OS_NS) == null || link.getAttribute("rel", OS_NS).getValue().equals("alternate")) {
                    href = resolveURI(null, link, href);
                    try {
                        baseURI = new URL(href);
                        break;
                    } catch (final MalformedURLException e) {
                        System.err.println("Base URI is malformed: " + href);
                    }
                }
            }
        }
        return baseURI;
    }