Prado\Collections\TPriorityList::insertBefore PHP 메소드

insertBefore() 공개 메소드

This inserts an item before another item within the list. It uses the same priority as the found index item and places the new item before it.
public insertBefore ( $indexitem, $item ) : integer
리턴 integer where the item has been inserted in the flattened list
    public function insertBefore($indexitem, $item)
    {
        if ($this->getReadOnly()) {
            throw new TInvalidOperationException('list_readonly', get_class($this));
        }
        if (($priority = $this->priorityOf($indexitem, true)) === false) {
            throw new TInvalidDataValueException('list_item_inexistent');
        }
        $this->insertAtIndexInPriority($item, $priority[1], $priority[0]);
        return $priority[2];
    }

Usage Example

예제 #1
0
 public function testRemoveTPriorityList()
 {
     $plist = new TPriorityList($this->plist);
     $this->assertEquals(2, $plist->remove($this->pitem2));
     $this->assertEquals(1, $plist->getPriorityCount());
     $plist = new TPriorityList($this->plist);
     try {
         $plist->remove($this->pitem5);
         $this->fail('Exception not raised: TInvalidDataValueException: The item cannot be found in the list');
     } catch (TInvalidDataValueException $v) {
     }
     try {
         $plist->remove($this->pitem3, null);
         $this->fail('Exception not raised: TInvalidDataValueException: The item cannot be found in the list');
     } catch (TInvalidDataValueException $v) {
     }
     try {
         $plist->remove($this->pitem1, 100);
         $this->fail('Exception not raised: TInvalidDataValueException: The item cannot be found in the list');
     } catch (TInvalidDataValueException $v) {
     }
     $plist->insertBefore($this->pitem3, $this->pitem4);
     $this->assertEquals(4, $plist->remove($this->pitem3, 100));
 }