Prado\Collections\TPriorityList::remove PHP Method

remove() public method

The list will search for the item. The first matching item found will be removed from the list.
public remove ( $item, $priority = false ) : integer
return integer index within the flattened list at which the item is being removed
    public function remove($item, $priority = false)
    {
        if ($this->getReadOnly()) {
            throw new TInvalidOperationException('list_readonly', get_class($this));
        }
        if (($p = $this->priorityOf($item, true)) !== false) {
            if ($priority !== false) {
                if ($priority === null) {
                    $priority = $this->getDefaultPriority();
                }
                $priority = (string) round(TPropertyValue::ensureFloat($priority), $this->_p);
                if ($p[0] != $priority) {
                    throw new TInvalidDataValueException('list_item_inexistent');
                }
            }
            $this->removeAtIndexInPriority($p[1], $p[0]);
            return $p[2];
        } else {
            throw new TInvalidDataValueException('list_item_inexistent');
        }
    }

Usage Example

コード例 #1
0
ファイル: TPriorityListTest.php プロジェクト: pradosoft/prado
 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));
 }