Prado\Collections\TPriorityList::priorityAt PHP Метод

priorityAt() публичный Метод

Retutrns the priority of an item at a particular flattened index.
public priorityAt ( $index, $withindex = false ) : numeric | array
Результат numeric | array the priority of the item in the list, false if not found. if withindex is true, an array is returned of [0 => $priority, 1 => $priorityIndex, 2 => flattenedIndex, 'priority' => $priority, 'index' => $priorityIndex, 'absindex' => flattenedIndex]
    public function priorityAt($index, $withindex = false)
    {
        if ($index < 0 || $index >= $this->getCount()) {
            throw new TInvalidDataValueException('list_index_invalid', $index);
        }
        $absindex = $index;
        $this->sortPriorities();
        foreach ($this->_d as $priority => $items) {
            if ($index >= ($c = count($items))) {
                $index -= $c;
            } else {
                return $withindex ? array($priority, $index, $absindex, 'priority' => $priority, 'index' => $index, 'absindex' => $absindex) : $priority;
            }
        }
        return false;
    }

Usage Example

Пример #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));
 }