Given a solution set of packed boxes, repack them to achieve optimum weight distribution.

@param PackedBoxList $originalBoxes

@return PackedBoxList
163276
public function redistributeWeight(PackedBoxList $originalBoxes): PackedBoxList
    {
        $targetWeight = $originalBoxes->getMeanWeight();
        $this->logger->log(LogLevel::DEBUG, "repacking for weight distribution, weight variance {$originalBoxes->getWeightVariance()}, target weight {$targetWeight}");

        /** @var PackedBox[] $boxes */
        $boxes = iterator_to_array($originalBoxes);

        usort($boxes, function (PackedBox $boxA, PackedBox $boxB) {
            return $boxB->getWeight() <=> $boxA->getWeight();
        });

        do {
            $iterationSuccessful = false;

            foreach ($boxes as $a => &$boxA) {
                foreach ($boxes as $b => &$boxB) {
                    if ($b <= $a || $boxA->getWeight() === $boxB->getWeight()) {
                        continue; //no need to evaluate
                    }

                    $iterationSuccessful = $this->equaliseWeight($boxA, $boxB, $targetWeight);
                    if ($iterationSuccessful) {
                        $boxes = array_filter($boxes, function (?PackedBox $box) { //remove any now-empty boxes from the list
                            return $box instanceof PackedBox;
                        });
                        break 2;
                    }
                }
            }
        } while ($iterationSuccessful);

        //Combine back into a single list
        $packedBoxes = new PackedBoxList();
        $packedBoxes->insertFromArray($boxes);

        return $packedBoxes;
    }
162885
public function combineLists($list1 = '', $list2 = '')
    {
        if (!empty($list2) && !empty($list2)) {
            $list1 .= ',';
        }
        $list1 .= $list2;
        $returnValue = GeneralUtility::uniqueList($list1);
        return $returnValue;
    }
1198686
public function top(): PackedBox
    {
        if (!$this->isSorted) {
            usort($this->list, [$this, 'compare']);
            $this->isSorted = true;
        }

        return reset($this->list);
    }
1078203
private function replaceTokens(array $originalTokens, array $replacements)
    {
        $tokens = [];
        foreach ($originalTokens as $key => $token) {
            if (! array_key_exists($key, $replacements)) {
                $tokens[] = $token;
                continue;
            }

            foreach ($replacements[$key] as $replacementToken) {
                $tokens[] = $replacementToken;
            }
        }
        return $tokens;
    }
1116107
public function setEnclosures($enclosures)
    {
        $this->enclosures = array();

        foreach ($enclosures as $enclosure) {
            $this->addEnclosure($enclosure);
        }

        return $this;
    }
972201
public function getClone($context = null, $original = null)
    {
        $new = clone $this;

        if ($context !== null) {
            $new->context = (string) $context;
        }

        if ($original !== null) {
            $new->original = (string) $original;
        }

        return $new;
    }
302656
protected function _filterHeaders(array $originalHeaders)
    {
        $headerNames = $headers = array();
        foreach ($originalHeaders as $header => $value) {
            if (! is_string($header)) {
                throw new \InvalidArgumentException(sprintf(
                    'Invalid header name; expected non-empty string, received %s',
                    gettype($header)
                ));
            }

            if (! is_array($value) && ! is_string($value) && ! is_numeric($value)) {
                throw new \InvalidArgumentException(sprintf(
                    'Invalid header value type; expected number, string, or array; received %s',
                    (is_object($value) ? get_class($value) : gettype($value))
                ));
            }

            if (is_array($value)) {
                array_walk($value, function ($item) {
                    if (! is_string($item) && ! is_numeric($item)) {
                        throw new \InvalidArgumentException(sprintf(
                            'Invalid header value type; expected number, string, or array; received %s',
                            (is_object($item) ? get_class($item) : gettype($item))
                        ));
                    }
                });
            }

            if (! is_array($value)) {
                $value = array($value);
            }

            $headerNames[strtolower($header)] = $header;
            $headers[$header] = $value;
        }

        return array($headerNames, $headers);
    }
586349
public function createVertexClone(Vertex $originalVertex)
    {
        $id = $originalVertex->getId();
        if ($this->vertices->hasVertexId($id)) {
            throw new RuntimeException('Id of cloned vertex already exists');
        }
        $newVertex = new Vertex($this, $id);
        // TODO: properly set attributes of vertex
        $newVertex->getAttributeBag()->setAttributes($originalVertex->getAttributeBag()->getAttributes());
        $newVertex->setBalance($originalVertex->getBalance());
        $newVertex->setGroup($originalVertex->getGroup());

        return $newVertex;
    }
1171119
protected function buildConstraints($original)
    {
        $constraints = array();

        foreach ($constraints as $name => $params) {
            $constraints[] = $this->constraintFactory->buildConstraint($name, $params);
        }

        return $constraints;
    }
1361086
public function initializeNode($weightClasses)
    {
        if (!$this->isInitialized()) {
            $contentScore = 0;

            switch ($this->nodeName) {
                case 'div':
                    $contentScore += 5;
                    break;

                case 'pre':
                case 'td':
                case 'blockquote':
                    $contentScore += 3;
                    break;

                case 'address':
                case 'ol':
                case 'ul':
                case 'dl':
                case 'dd':
                case 'dt':
                case 'li':
                case 'form':
                    $contentScore -= 3;
                    break;

                case 'h1':
                case 'h2':
                case 'h3':
                case 'h4':
                case 'h5':
                case 'h6':
                case 'th':
                    $contentScore -= 5;
                    break;
            }

            $this->contentScore = $contentScore + ($weightClasses ? $this->getClassWeight() : 0);

            $this->initialized = true;
        }

        return $this;
    }
669455
private
    function repart($fighterGroups, $max)
    {
        $fighters = new Collection();
        for ($i = 0; $i < $max; $i++) {
            foreach ($fighterGroups as $fighterGroup) {
                $fighter = $fighterGroup->values()->get($i);
                if ($fighter != null) {
                    $fighters->push($fighter);
                }
            }
        }
        return $fighters;
    }
465275
public Packer inset(final Insets insets) {
        gc.insets = insets;
        setConstraints(comp, gc);
        return this;
    }
821202
public function getHeaders(bool $originalCase = false): array {
        if (!$originalCase) {
            return $this->headers;
        }

        $headers = [];

        foreach ($this->headers as $header => $values) {
            $headers[$this->headerCaseMap[$header]] = $values;
        }

        return $headers;
    }
549857
public function pack(PosMap $pos)
    {
        $generated = $pos->generated;
        $source = $pos->source;
        $offsets = [$generated->column - $this->gColumn];
        $this->gColumn = $generated->column;
        if ($source->fileIndex !== null) {
            $offsets[] = $source->fileIndex - $this->sFile;
            $offsets[] = $source->line - $this->sLine;
            $offsets[] = $source->column - $this->sColumn;
            $this->sFile = $source->fileIndex;
            $this->sLine = $source->line;
            $this->sColumn = $source->column;
            if ($source->nameIndex !== null) {
                $offsets[] = $source->nameIndex - $this->sName;
                $this->sName = $source->nameIndex;
            }
        }
        return $this->encoder->encode($offsets);
    }
928383
function mergeKeys( &$originalKeys, $keys )
    {
        foreach ( $keys as $key )
        {
            if ( count( $key ) >= 2 )
                $originalKeys[$key[0]] = $key[1];
        }
    }
1078020
private function reduceUploadedFiles($uploadedFiles)
    {
        return array_reduce($uploadedFiles, function ($carry, $item) {
            if ($item instanceof UploadedFileInterface) {
                $carry[] = $item;
            } else {
                $carry = array_merge($carry, $this->reduceUploadedFiles($item));
            }
            return $carry;
        }, []);
    }
57133
private void mergeResponsesSortedSet(SortedSet<Object> originalList, SortedSet<Object> shardList) {
		for (Object item : shardList) {
			originalList.add(item);
		}
	}