Sorts the `$this->_head` elements by key, then appends them to the
`$Head` XMLElement in order.
767052
protected function __generateHead()
    {
        ksort($this->_head);

        foreach ($this->_head as $position => $obj) {
            if (is_object($obj)) {
                $this->Head->appendChild($obj);
            }
        }
    }
479796
private function addHeadElementIfMissing(): bool
    {
        if ($this->getElementsByTagName('head')->length === 0) {
            $htmlElement = $this->getElementsByTagName('html')->item(0);
            if (!isset(self::$newObjectsCache['headelement'])) {
                self::$newObjectsCache['headelement'] = new \DOMElement('head');
            }
            $headElement = clone(self::$newObjectsCache['headelement']);
            if ($htmlElement->firstChild === null) {
                $htmlElement->appendChild($headElement);
            } else {
                $htmlElement->insertBefore($headElement, $htmlElement->firstChild);
            }
            return true;
        }
        return false;
    }
306200
private static void moveElements(List<?> input, Collection<Object> output, int maxElements) {
    for (int i = 0; i < maxElements; i++) {
      output.add(input.remove(0));
    }
  }
255433
public function removeElement(OrderElement $elements)
    {
        $this->elements->removeElement($elements);
        $elements->setOrder(null);
    }
16428
private void addOnlyOfTypeElements() {
        for (Node node : nodes) {
            Node n = DOMHelper.getPreviousSiblingElement(node);
            while (n != null) {
                if (DOMHelper.getNodeName(n).equals(DOMHelper.getNodeName(node))) {
                    break;
                }
                
                n = DOMHelper.getPreviousSiblingElement(n);
            }
            
            if (n == null) {
                n = DOMHelper.getNextSiblingElement(node);
                while (n != null) {
                    if (DOMHelper.getNodeName(n).equals(DOMHelper.getNodeName(node))) {
                        break;
                    }
                    
                    n = DOMHelper.getNextSiblingElement(n);
                }
                
                if (n == null) {
                    result.add(node);
                }
            }
        }
    }
554112
public function sortKeys()
    {
        if ($this->isNotEmpty()) {
            foreach ($this->rows as &$row) {
                ksort($row);
            }
        }
        return $this;
    }
422756
public function get_grouping_head()
    {
        if (!$this->is_single_grouping())
            throw new \Exception('Cannot use ' . __METHOD__ . ' here');
        foreach ($this->get_elements() as $record) {
            return $record;
        }
    }
79047
protected function addNode(DOMElement $element, $key, $value): void
    {
        $key   = \str_replace(' ', '-', $key);
        $child = $this->element($key);
        $element->appendChild($child);
        $this->convert($child, $value);
    }
718711
public function sort()
    {
        usort($this->set, function ($first, $second) {
            $ids = strcmp($first['id'], $second['id']);
            if ($ids === 0) {
                if ($first['context'] === null && $second['context'] === null) {
                    return 0;
                } else if ($first['context'] === null) {
                    return -1;
                } else if ($second['context'] === null) {
                    return 1;
                } else {
                    return strcmp($first['context'], $second['context']);
                }
            } else {
                return $ids;
            }
        });
    }
346379
public function accumulate($element, $key)
    {
        $accumulate = $this->accumulator;
        $accumulate($this->structure, $element, $key);
    }
314263
public function remove($key): bool {
        /** @var \doganoo\PHPAlgorithms\Datastructure\Lists\Node $previous */
        $previous = $head = $this->getHead();
        if ($head === null) {
            return true;
        }
        $i = 1;
        $headSize = $head->size();

        /*
         * The while loop iterates over all nodes until the
         * value is found.
         */
        while ($head !== null && $head->getKey() !== $key) {
            /*
             * since a node is going to be removed from the
             * node chain, the previous element has to be
             * on hold.
             * After previous is set to the actual element,
             * the current element pointer can moved to the
             * next one.
             *
             * If the value is found, $previous points to
             * the previous element of the value that is
             * searched and current points to the next element
             * after that one who should be deleted.
             */
            $previous = $head;
            $head = $head->getNext();
            $i++;
        }

        /*
         * If the value that should be deleted is not in the list,
         * this set instruction assigns the next node to the actual.
         *
         * If the while loop has ended early, the next node is
         * assigned to the previous node of the node that
         * should be deleted (if there is a node present).
         */
        if ($head !== null) {
            $previous->setNext($head->getNext());
        }
        return $i !== $headSize;
    }
636339
private function sortArray(&$element)
    {
        if (is_array($element)) {
            array_walk($element, [$this, 'sortArray']);
            array_key_exists(0, $element)
                ? sort($element)
                : ksort($element);
        }
    }
1165772
public function append()
    {
        $this->importNodes(\func_get_args(), function ($node, $imported_node) {
            $node->appendChild($imported_node);
        });

        return $this;
    }
419346
public function getOrderedElements($header)
    {
        if (!$header) {
            throw new InvalidArgument('The header string should not be empty.');
        }

        $elements = array();
        $orderKeys = array();
        foreach ($this->parseHeader($header) as $key => $h) {
            try {
                $element = $this->acceptFactory($h);
                $elements[] = $element;
                $orderKeys[] = [$element->getQuality(), $key, $element->getValue()];
            } catch (Exception\Exception $e) {
                // silently skip in case of invalid headers coming in from a client
            }
        }

        // sort based on quality and then original order. This is necessary as
        // to ensure that the first in the list for two items with the same
        // quality stays in that order in both PHP5 and PHP7.
        uasort($orderKeys, function ($a, $b) {
            $qA = $a[0];
            $qB = $b[0];

            if ($qA == $qB) {
                return $a[1] > $b[1];
            }

            return ($qA > $qB) ? -1 : 1;
        });

        $orderedElements = [];
        foreach ($orderKeys as $key) {
            $orderedElements[] = $elements[$key[1]];
        }

        return $orderedElements;
    }
247968
def sort
      element_order = params.fetch "element_order"

      element_order.each_with_index do |element_id, index|
        element = Element.find_by_id element_id
        element.update_attribute :position, index+1
      end

      head :no_content
    end
431043
private void addFirstChildElements() {
		for (Node node : nodes) {
			Index index = helper.getIndexInParent(node, false);
			if (index.index == 0)
				result.add(node);
		}
	}
1125827
function processBySchemaTree( $element )
    {
        $parent = $element->parentNode;

        if ( $parent instanceof DOMElement )
        {
            $schemaCheckResult = $this->XMLSchema->check( $parent, $element );
            if ( !$schemaCheckResult )
            {
                if ( $schemaCheckResult === false )
                {
                    // Remove indenting spaces
                    if ( $element->nodeType == XML_TEXT_NODE && !trim( $element->textContent ) )
                    {
                        $element = $parent->removeChild( $element );
                        return false;
                    }

                    $elementName = $element->nodeType == XML_ELEMENT_NODE ? '&lt;' . $element->nodeName . '&gt;' : $element->nodeName;
                    $this->handleError( self::ERROR_SCHEMA, ezpI18n::tr( 'kernel/classes/datatypes/ezxmltext', "%1 is not allowed to be a child of &lt;%2&gt;.",
                                        false, array( $elementName, $parent->nodeName ) ) );
                }
                $this->fixSubtree( $element, $element );
                return false;
            }
        }
        // TODO: break processing of any node that doesn't have parent
        //       and is not a root node.
        elseif ( $element->nodeName != 'section' )
        {
            return false;
        }
        return true;
    }