@param PositionInterface $position
@param bool              $isCollection
@param bool              $isNull

@return DocumentDataInterface
346105
private function createParsedDocumentData(
        PositionInterface $position,
        bool $isCollection,
        bool $isNull
    ): DocumentDataInterface {
        return new class (
            $position,
            $isCollection,
            $isNull
        ) implements DocumentDataInterface
        {
            /**
             * @var PositionInterface
             */
            private $position;
            /**
             * @var bool
             */
            private $isCollection;

            /**
             * @var bool
             */
            private $isNull;

            /**
             * @param PositionInterface $position
             * @param bool              $isCollection
             * @param bool              $isNull
             */
            public function __construct(
                PositionInterface $position,
                bool $isCollection,
                bool $isNull
            ) {
                $this->position     = $position;
                $this->isCollection = $isCollection;
                $this->isNull       = $isNull;
            }

            /**
             * @inheritdoc
             */
            public function getPosition(): PositionInterface
            {
                return $this->position;
            }

            /**
             * @inheritdoc
             */
            public function isCollection(): bool
            {
                return $this->isCollection;
            }

            /**
             * @inheritdoc
             */
            public function isNull(): bool
            {
                return $this->isNull;
            }
        };
    }
1040896
protected function sortChildrenByPosition($parent, $childrenPropertyPath)
    {
        $collection = $this->getPropertyAccessor()->getValue($parent, $childrenPropertyPath);

        if ($collection instanceOf PersistentCollection) {
            /** @var PersistentCollection $collection */
            if (false === $collection->isInitialized()) {
                $collection->initialize();
            }
            $collection = $collection->unwrap();
        }

        if (!$collection instanceOf ArrayCollection) {
            throw new \InvalidArgumentException('Expected ArrayCollection.');
        }

        /** @var ArrayCollection $collection */
        $iterator = $collection->getIterator();
        $iterator->uasort(function (SortableInterface $a, SortableInterface $b) {
            return
                ($a->getPosition() == $b->getPosition()) ? 0 :
                    ($a->getPosition() < $b->getPosition()) ? -1 : 1;
        });

        $collection->clear();
        foreach ($iterator as $key => $item) {
            $collection->set($key, $item);
        }
    }
656026
private static void createPositions(List<ComponentPosition> statsPositionList,
      Map<Integer, Integer> positionsData, List<Integer> docSet)
      throws IOException {
    if (statsPositionList != null) {
      for (ComponentPosition position : statsPositionList) {
        position.dataCollector.initNewList(1);
        Integer tmpValue;
        long[] values = new long[docSet.size()];
        int value;
        int number = 0;
        for (int docId : docSet) {
          tmpValue = positionsData.get(docId);
          value = tmpValue == null ? 0 : tmpValue.intValue();
          if (((position.minimumLong == null)
              || (value >= position.minimumLong))
              && ((position.maximumLong == null)
                  || (value <= position.maximumLong))) {
            values[number] = value;
            number++;
          }
        }
        if (number > 0) {
          position.dataCollector.add(values, number);
        }
        position.dataCollector.closeNewList();
      }
    }
  }
1290307
protected function incrementPositionsOfItemsAbove($position = null)
    {
        if ($this->isNotInList()) return;

        if (null === $position) {
            $position = $this->getListifyPosition();
        }

        $this->listifyScopedQuery()
            ->where($this->positionColumn(), '<', $position)
            ->increment($this->positionColumn());
    }
1005653
private function loadNextDocBlockContent(int $startPosition): int
    {
        return $this->file->findNext(
            [
                T_DOC_COMMENT_WHITESPACE,
                T_DOC_COMMENT_STAR
            ],
            $startPosition + 1,
            $this->getDocHelper()->getBlockEndPosition(),
            true
        );
    }
676570
public function updatePosition(UpdatePositionEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $this->genericUpdatePosition(OrderStatusQuery::create(), $event, $dispatcher);
    }
656383
protected function toPosition(string $id, $position): self
    {
        $element = $this->find($id);

        return $this
            ->without($id)
            ->insert($element, $position);
    }
126306
public function match($node, $position, $items)
    {
        return Dom::searchNode($node, $this->_items) === false;
    }
714865
public function createFormForLocation(Location $location, $useAjax = false)
    {
        $contentInfo = $location->contentInfo;

        $contentType = $this->contentTypeService->loadContentType($contentInfo->contentTypeId);

        $data = new DataWrapper(new InformationCollectionStruct(), $contentType, $location);

        $formBuilder = $this->formFactory
            ->createBuilder(
                Kernel::VERSION_ID < 20800 ?
                    'ezforms_information_collection' :
                    InformationCollectionType::class,
                $data,
                array(
                    'csrf_protection' => $this->useCsrf,
                )
            );

        if ($useAjax) {
            $formBuilder->setAction($this->router->generate('netgen_information_collection_handle_ajax', array('location' => $location->id)));
        }

        return $formBuilder;
    }
1167310
private function internalCreateBlock(
        APIBlockCreateStruct $blockCreateStruct,
        PersistenceBlock $targetBlock,
        string $placeholder,
        ?int $position = null
    ): Block {
        $persistenceLayout = $this->layoutHandler->loadLayout($targetBlock->layoutId, Value::STATUS_DRAFT);

        $createdBlock = $this->transaction(
            function () use ($blockCreateStruct, $persistenceLayout, $targetBlock, $placeholder, $position): PersistenceBlock {
                $blockDefinition = $blockCreateStruct->getDefinition();

                $createdBlock = $this->blockHandler->createBlock(
                    BlockCreateStruct::fromArray(
                        [
                            'status' => $targetBlock->status,
                            'position' => $position,
                            'definitionIdentifier' => $blockDefinition->getIdentifier(),
                            'viewType' => $blockCreateStruct->viewType,
                            'itemViewType' => $blockCreateStruct->itemViewType,
                            'name' => $blockCreateStruct->name,
                            'alwaysAvailable' => $blockCreateStruct->alwaysAvailable,
                            'isTranslatable' => $blockCreateStruct->isTranslatable,
                            'parameters' => iterator_to_array(
                                $this->parameterMapper->serializeValues(
                                    $blockDefinition,
                                    $blockCreateStruct->getParameterValues()
                                )
                            ),
                            'config' => iterator_to_array(
                                $this->configMapper->serializeValues(
                                    $blockCreateStruct->getConfigStructs(),
                                    $blockDefinition->getConfigDefinitions()
                                )
                            ),
                        ]
                    ),
                    $persistenceLayout,
                    $targetBlock,
                    $placeholder
                );

                $collectionCreateStructs = $blockCreateStruct->getCollectionCreateStructs();
                if (count($collectionCreateStructs) > 0) {
                    foreach ($collectionCreateStructs as $identifier => $collectionCreateStruct) {
                        $createdCollection = $this->collectionHandler->createCollection(
                            CollectionCreateStruct::fromArray(
                                [
                                    'status' => Value::STATUS_DRAFT,
                                    'offset' => $collectionCreateStruct->offset,
                                    'limit' => $collectionCreateStruct->limit,
                                    'alwaysAvailable' => $blockCreateStruct->alwaysAvailable,
                                    'isTranslatable' => $blockCreateStruct->isTranslatable,
                                    'mainLocale' => $persistenceLayout->mainLocale,
                                ]
                            )
                        );

                        if ($collectionCreateStruct->queryCreateStruct instanceof APIQueryCreateStruct) {
                            $queryType = $collectionCreateStruct->queryCreateStruct->getQueryType();
                            $this->collectionHandler->createQuery(
                                $createdCollection,
                                QueryCreateStruct::fromArray(
                                    [
                                        'type' => $queryType->getType(),
                                        'parameters' => iterator_to_array(
                                            $this->parameterMapper->serializeValues(
                                                $queryType,
                                                $collectionCreateStruct->queryCreateStruct->getParameterValues()
                                            )
                                        ),
                                    ]
                                )
                            );
                        }

                        if ($blockCreateStruct->isTranslatable) {
                            foreach ($persistenceLayout->availableLocales as $locale) {
                                if ($locale !== $persistenceLayout->mainLocale) {
                                    $createdCollection = $this->collectionHandler->createCollectionTranslation(
                                        $createdCollection,
                                        $locale,
                                        $createdCollection->mainLocale
                                    );
                                }
                            }
                        }

                        $this->blockHandler->createCollectionReference(
                            $createdBlock,
                            $createdCollection,
                            (string) $identifier
                        );
                    }
                }

                return $createdBlock;
            }
        );

        return $this->mapper->mapBlock($createdBlock);
    }
246022
private function addTrashContainerField(FormInterface $form, Location $location = null): void
    {
        if (null === $location) {
            return;
        }

        $isContainer = new IsContainer();
        $hasChildren = new HasChildren($this->locationService);

        if (!$isContainer->and($hasChildren)->isSatisfiedBy($location)) {
            return;
        }

        $locationChildren = $this->locationService->loadLocationChildren($location);

        $translatorParameters = [
            '%children_count%' => $locationChildren->totalCount,
            '%content_name%' => $location->getContent()->getName(),
        ];

        $form->add('trashContainer', ChoiceType::class, [
            'expanded' => true,
            'multiple' => true,
            'choices' => [
                /** @Desc("%children_count% content items under location %content_name%") */
                $this->translator->trans('location_trash_form.trash_container', $translatorParameters, 'forms') => self::TRASH_WITH_CHILDREN,
            ],
        ]);
    }
433766
public function readVarint($isCollectionElement = false) {
		if($isCollectionElement) {
				$length = $this->readShort();
		} else {
				$length = strlen($this->data);
		}

		$hex = unpack('H*', $this->read($length));
		return $this->bchexdec($hex[1]);
	}
872020
public function getNodeAtPosition(Position $position)
    {
        if ($this->sourceFileNode === null) {
            return null;
        }

        $offset = $position->toOffset($this->sourceFileNode->getFileContents());
        $node = $this->sourceFileNode->getDescendantNodeAtPosition($offset);
        if ($node !== null && $node->getStart() > $offset) {
            return null;
        }
        return $node;
    }
427984
public function setPosition($position)
    {
        $this->position = max(min($position, $this->max), 0);
        return $this;
    }
146065
public function addPageComponent(PageComponent $pageComponent, $position = -1) {
        if (!is_int($position)) {
            throw new \InvalidArgumentException('position should be of type int');
        }

        if ($position < 0) {
            $position = count($this->pageComponents);
        }

        Utils::array_insert($this->pageComponents, $pageComponent, $position);

        return $this;
    }
1041235
public function movePageDisplayOrderToSibling(Page $c, $position = 'before')
    {
        $myCID = $this->getCollectionPointerOriginalID() ?: $this->getCollectionID();
        $relatedCID = $c->getCollectionPointerOriginalID() ?: $c->getCollectionID();
        $pageIDs = [];
        $db = Database::connection();
        $r = $db->executeQuery('select cID from Pages where cParentID = ? and cID <> ? order by cDisplayOrder asc', [$this->getCollectionParentID(), $myCID]);
        while (($cID = $r->fetchColumn()) !== false) {
            if ($cID == $relatedCID && $position == 'before') {
                $pageIDs[] = $myCID;
            }
            $pageIDs[] = $cID;
            if ($cID == $relatedCID && $position == 'after') {
                $pageIDs[] = $myCID;
            }
        }
        $displayOrder = 0;
        foreach ($pageIDs as $cID) {
            $co = self::getByID($cID);
            $co->updateDisplayOrder($displayOrder);
            ++$displayOrder;
        }
    }
709133
public function media(string $collection = 'default', Closure $callback = null, $position = null): self
    {
        $element = $this->createMediaElement($collection);

        if ($position) {
            $this->insert($element, $position, $callback);
        } else {
            $this->push($element, $callback);
        }

        return $this;
    }