Prado\Collections\TPriorityList::insertAt PHP Method

insertAt() public method

Inserts an item at an index. It reads the priority of the item at index within the flattened list and then inserts the item at that priority-index.
public insertAt ( $index, $item )
    public function insertAt($index, $item)
    {
        if ($this->getReadOnly()) {
            throw new TInvalidOperationException('list_readonly', get_class($this));
        }
        if (($priority = $this->priorityAt($index, true)) !== false) {
            $this->insertAtIndexInPriority($item, $priority[1], $priority[0]);
        } else {
            throw new TInvalidDataValueException('list_index_invalid', $index);
        }
    }

Usage Example

Ejemplo n.º 1
0
 public function testInsertAtTPriorityList()
 {
     $plist = new TPriorityList($this->plist);
     $this->assertNull($plist->insertAt(0, $this->pitem3));
     $this->assertEquals(-10000000, $plist->priorityAt(0));
     try {
         $plist->insertAt(5, $this->pitem3);
         $this->fail('exception not raised when adding item at an out-of-range index');
     } catch (TInvalidDataValueException $e) {
     }
     $this->assertEquals(100, $plist->priorityAt(4));
 }