Insert item before index.

@param Node $item
@param int $index
@throws \OutOfBoundsException
Index out of bounds.
@return $this
182351
public function insertItem(Node $item, $index) {
    $items = $this->getItems();
    if ($items->isEmpty()) {
      if ($index !== 0) {
        throw new \OutOfBoundsException('index out of bounds');
      }
      $this->append($item);
    }
    else {
      $max_index = count($items) - 1;
      if ($index < 0 || $index > $max_index) {
        throw new \OutOfBoundsException('index out of bounds');
      }
      $items[$index]->before([
        $item,
        Token::comma(),
        Token::space(),
      ]);
    }
    return $this;
  }
743723
public function set($index, $element)
    {
        if (!is_null($index)
            && is_scalar($index)
        ) {
            $this->_iterator = null;
            return $this->_items[$index] = $element;
        } else {
            // given index name is not valid
            throw new ListException('Element could not be added to list. Index is not valid.', E_NOTICE);
        }
    }
1043036
public function set($index, $item)
    {
        $this->offsetSet($index, $this->parser->text($item));
    }
179584
public function addItem(Item $item)
    {
        if (!$this->items->contains($item)) {
            $this->items->add($item);
            $item->setCountry($this);
        }

        return $this;
    }
658877
def insertTopLevelItem( self, index, item ):
        
        self.treeWidget().insertTopLevelItem(index, item)
        
        if self.updatesEnabled():
            try:
                item.sync(recursive = True)
            except AttributeError:
                pass
202004
public function setAbstractNode( $index, $node )
	{
		if ( is_null( $this->_childs ) )
		{
			throw new IndexOutOfRangeException();
		}

		$this->_childs[ $index ] = $node;
	}
1276120
public function setItem(Item $item)
    {
        $this->childOf = $item->id;
        $this->_item = $item;
        
        return $this;
    }
64792
public function insert( $index, $element ) {
		$this->validate_index( $index );
		$this->type->validate_element( $element );

		$a = array_slice( $this->elements, 0, $index );
		$b = array_slice( $this->elements, $index, count( $this->elements ) );

		$a[] = $element;

		return $this->new_from_trusted( array_merge( $a, $b ) );
	}
1181752
public static function InsertBefore( $iter, $index, $iter2 )
	{
		return new NodeIterator( function() use( $iter, $index, $iter2 ) { return ExtFuncs::InsertIterator( $iter->CloneInstance(), $index, $iter2->CloneInstance() ); } );
	}
1202527
public function insert($index, $child, $replace = FALSE)
	{
		if ($child instanceof self || is_scalar($child)) {
			if ($index === NULL) { // append
				$this->children[] = $child;

			} else { // insert or replace
				array_splice($this->children, (int)$index, $replace ? 1 : 0, [$child]);
			}

		} else {
			throw new InvalidArgumentException(sprintf('Child node must be scalar or Html object, %s given.', is_object($child) ? get_class($child) : gettype($child)));
		}

		return $this;
	}
343312
public synchronized void insert(XEvent event, int index)
			throws IndexOutOfBoundsException, IOException {
		if (index < 0 || index > size) {
			throw new IndexOutOfBoundsException();
		}
		// check if we can append
		if (index == size) {
			append(event);
			return;
		}
		// adjust size and overflow size
		size++;
		overflowSize++;
		// add to overflow set
		for (int i = overflowSize - 2; i >= 0; i--) {
			if (overflowIndices[i] >= index) {
				overflowIndices[i + 1] = overflowIndices[i] + 1;
				overflowEntries[i + 1] = overflowEntries[i];
			} else {
				overflowIndices[i + 1] = index;
				overflowEntries[i + 1] = event;
				if (overflowSize == overflowIndices.length) {
					consolidate();
				}
				return;
			}
		}
		// if we arrive here, we must insert at zero
		overflowIndices[0] = index;
		overflowEntries[0] = event;
		if (overflowSize == overflowIndices.length) {
			consolidate();
		}
	}
988088
public function add_item( $item ) {
		if ( is_array( $item ) ) {
			foreach ( $item as $single_item ) {
				$this->add_item( $single_item );
			}
		} else {
			$priority                   = $item->get_priority();
			$this->items[ $priority ][] = $item;
		}
	}
760324
public function insert($index, self $str){
		
		if(!$this->offsetExists($index)){
			throw new \OutOfRangeException('$index is invalid');
		}
		
		return new static(
				$this->substring(0, $index) .
				$str->_Value .
				$this->substring($index),
			$this->_Encoding);
		
	}
37346
public function add($element, $index = null)
    {
        if (null === $index || '' === $index) {
            $this->elements[] = $element;
        } else {
            $this->elements[$index] = $element;
        }

        return $this;
    }
1242269
final public function beforePutItem(array &$item, Node $node): void
    {
        $this->loadIndexes();
        $this->addShardAttributes($item, $node);
        if ($node instanceof Indexed) {
            $item[NodeTable::INDEXED_KEY_NAME] = ['BOOL' => true];
        }

        foreach ($this->gsi as $gsi) {
            $gsi->beforePutItem($item, $node);
        }

        $this->doBeforePutItem($item, $node);
    }
1039853
public function removeItem($item) {
    if (is_int($item)) {
      $index = $item;
      if ($index < 0) {
        throw new \OutOfBoundsException('index out of bounds');
      }
      $items = $this->getItems();
      if ($index >= count($items)) {
        throw new \OutOfBoundsException('index out of bounds');
      }
      $item = $items[$index];
      $is_last = $index === count($items) - 1;
    }
    else {
      if ($item->parent() !== $this) {
        throw new \InvalidArgumentException('invalid item');
      }
      $items = $this->getItems();
      $last_index = count($items) - 1;
      $last_item = $items[$last_index];
      $is_last = $last_item === $item;
    }
    if (count($items) === 1) {
      // No separators to remove.
    }
    elseif ($is_last) {
      $item->previousUntil(function ($node) {
        if ($node instanceof HiddenNode) {
          return FALSE;
        }
        if ($node instanceof TokenNode && $node->getType() === ',') {
          return FALSE;
        }
        return TRUE;
      })->remove();
    }
    else {
      $item->nextUntil(function ($node) {
        if ($node instanceof HiddenNode) {
          return FALSE;
        }
        if ($node instanceof TokenNode && $node->getType() === ',') {
          return FALSE;
        }
        return TRUE;
      })->remove();
    }
    $item->remove();
    return $this;
  }
1268764
public function addItem(Item $item)
    {
        $this->items->put($item->getName(), $item);

        return $this;
    }