/**
  * Retrieve the maintenance task entry, from unique identfier
  * @param $maintenanceTaskEntryIdentifier   Identifier to locate entry
  * @return mixed|null                       Returns the maintenance task entry or null on error
  * @throws InvalidArgumentException         if the provided argument is not set or of correct type
  */
 public function retrieveMaintenanceTaskEntry($maintenanceTaskEntryIdentifier)
 {
     if (!isset($maintenanceTaskEntryIdentifier)) {
         //argument check
         throw new InvalidArgumentException("Missing Argument");
     } else {
         if (!is_numeric($maintenanceTaskEntryIdentifier)) {
             //argument check
             throw new InvalidArgumentException("maintenanceTaskEntryIdentifier is not a number");
         }
     }
     if ($this->maintenanceTaskList->isEmpty()) {
         //if list is empty, unable to return entry
         return null;
     } else {
         $this->maintenanceTaskList->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
         //set iteration FIFO
         for ($this->maintenanceTaskList->rewind(); $this->maintenanceTaskList->valid(); $this->maintenanceTaskList->next()) {
             if ($this->maintenanceTaskList->current()->getTaskEntryIdentifier() == $maintenanceTaskEntryIdentifier) {
                 //if entry identifier matches supplied identifier
                 return $this->maintenanceTaskList->current();
             }
             //return the matching entry
         }
     }
     return null;
     //entry with given identifier not found
 }
Exemplo n.º 2
0
 /**
  * (excerpt from http://docs.hhvm.com/manual/en/splstack.setiteratormode.php)
  *
  *
  * @mode       mixed   There is only one iteration parameter you can
  *                     modify. The behavior of the iterator (either one or
  *                     the other): SplDoublyLinkedList::IT_MODE_DELETE
  *                     (Elements are deleted by the iterator)
  *                     SplDoublyLinkedList::IT_MODE_KEEP (Elements are
  *                     traversed by the iterator)
  *
  *                     The default mode is 0x2 :
  *                     SplDoublyLinkedList::IT_MODE_LIFO |
  *                     SplDoublyLinkedList::IT_MODE_KEEP Warning
  *
  *                     The direction of iteration can no longer be changed
  *                     for SplStacks. Trying to do so will result in a
  *                     RuntimeException being thrown.
  *
  * @return     mixed   No value is returned.
  */
 public function setIteratorMode($mode)
 {
     if (($mode & self::IT_MODE_LIFO) == 0) {
         throw new RuntimeException('Iterators\' LIFO/FIFO modes for SplStack/SplQueue objects are frozen');
     }
     parent::setIteratorMode($mode);
 }
 /**
  * @param $vertex
  * @return \SplDoublyLinkedList
  */
 public function createTransitionsList($vertex)
 {
     $list = new \SplDoublyLinkedList();
     $list->setIteratorMode(\SplDoublyLinkedList::IT_MODE_FIFO | \SplDoublyLinkedList::IT_MODE_KEEP);
     $list->push($vertex);
     return $list;
 }
Exemplo n.º 4
0
 public static function castDoublyLinkedList(\SplDoublyLinkedList $c, array $a, Stub $stub, $isNested)
 {
     $mode = $c->getIteratorMode();
     $c->setIteratorMode(\SplDoublyLinkedList::IT_MODE_KEEP | $mode & ~\SplDoublyLinkedList::IT_MODE_DELETE);
     $a += array("~mode" => new ConstStub(($mode & \SplDoublyLinkedList::IT_MODE_LIFO ? 'IT_MODE_LIFO' : 'IT_MODE_FIFO') . ' | ' . ($mode & \SplDoublyLinkedList::IT_MODE_KEEP ? 'IT_MODE_KEEP' : 'IT_MODE_DELETE'), $mode), "~dllist" => iterator_to_array($c));
     $c->setIteratorMode($mode);
     return $a;
 }
Exemplo n.º 5
0
 public static function castDoublyLinkedList(\SplDoublyLinkedList $c, array $a, Stub $stub, $isNested)
 {
     $prefix = Caster::PREFIX_VIRTUAL;
     $mode = $c->getIteratorMode();
     $c->setIteratorMode(\SplDoublyLinkedList::IT_MODE_KEEP | $mode & ~\SplDoublyLinkedList::IT_MODE_DELETE);
     $a += array($prefix . 'mode' => new ConstStub(($mode & \SplDoublyLinkedList::IT_MODE_LIFO ? 'IT_MODE_LIFO' : 'IT_MODE_FIFO') . ' | ' . ($mode & \SplDoublyLinkedList::IT_MODE_KEEP ? 'IT_MODE_KEEP' : 'IT_MODE_DELETE'), $mode), $prefix . 'dllist' => iterator_to_array($c));
     $c->setIteratorMode($mode);
     return $a;
 }
 /**
  * {@inheritdoc}
  */
 public function tokenize($userAgent)
 {
     $iterator = new \SplDoublyLinkedList();
     $iterator->setIteratorMode(\SplDoublyLinkedList::IT_MODE_FIFO);
     foreach ($this->getTokens($userAgent) as $position => $token) {
         $token = trim($token);
         $iterator->push(new Node($token, $position, $this->resolveType($token)));
     }
     return $iterator;
 }
Exemplo n.º 7
0
 public function __construct()
 {
     $listLink = new SplDoublyLinkedList();
     $listLink->push('Albin');
     $listLink->push('to');
     $listLink->push('the');
     $listLink->push('interface;');
     $listLink->push('not');
     $listLink->push('the');
     $listLink->push('Sandi');
     echo "<strong>Free good advice :</strong><br />";
     $listLink->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
     for ($listLink->rewind(); $listLink->valid(); $listLink->next()) {
         echo $listLink->current() . " ";
     }
     echo "<br /><br /><strong>Yoda talk: last in first out:</strong><br />";
     $listLink->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO);
     for ($listLink->rewind(); $listLink->valid(); $listLink->next()) {
         echo $listLink->current() . " ";
     }
 }
 function it_tokenize_useragent()
 {
     $tokenized = $this->tokenize('Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0); 360Spider(compatible; HaosouSpider; http://www.haosou.com/help/help_3_2.html)');
     $nodes = new \SplDoublyLinkedList();
     $nodes->setIteratorMode(\SplDoublyLinkedList::IT_MODE_FIFO);
     $nodes->push(new Node('mozilla', 0, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node('/', 1, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node('5.0', 2, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node('', 3, NodeInterface::TYPE_SPACE));
     $nodes->push(new Node('(', 4, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node('compatible', 5, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node(';', 6, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node('', 7, NodeInterface::TYPE_SPACE));
     $nodes->push(new Node('msie', 8, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node('', 9, NodeInterface::TYPE_SPACE));
     $nodes->push(new Node('9.0', 10, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node(';', 11, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node('', 12, NodeInterface::TYPE_SPACE));
     $nodes->push(new Node('windows', 13, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node('', 14, NodeInterface::TYPE_SPACE));
     $nodes->push(new Node('nt', 15, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node('', 16, NodeInterface::TYPE_SPACE));
     $nodes->push(new Node('6.1', 17, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node(';', 18, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node('', 19, NodeInterface::TYPE_SPACE));
     $nodes->push(new Node('trident', 20, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node('/', 21, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node('5.0', 22, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node(')', 23, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node(';', 24, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node('', 25, NodeInterface::TYPE_SPACE));
     $nodes->push(new Node('360spider', 26, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node('(', 27, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node('compatible', 28, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node(';', 29, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node('', 30, NodeInterface::TYPE_SPACE));
     $nodes->push(new Node('haosouspider', 31, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node(';', 32, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node('', 33, NodeInterface::TYPE_SPACE));
     $nodes->push(new Node('http://www.haosou.com/help/help_3_2.html', 34, NodeInterface::TYPE_TEXT));
     $nodes->push(new Node(')', 35, NodeInterface::TYPE_TEXT));
     $tokenized->shouldReturnAnInstanceOf('\\Iterator');
     /** @var NodeInterface $node */
     foreach ($nodes as $node) {
         $tokenized[$node->getPosition()]->getValue()->shouldReturn($node->getValue());
         $tokenized[$node->getPosition()]->getType()->shouldReturn($node->getType());
     }
 }
Exemplo n.º 9
0
$dlanguages = new SplDoublyLinkedList();
$dlanguages->push(['Languages', 'Uses', 'Ranking']);
$dlanguages->push(['C++', 'computing', 99.59999999999999]);
$dlanguages->push(['C', 'computing', 99.90000000000001]);
$dlanguages->push(['Java', 'application', 100]);
$dlanguages->push(['C#', 'application', 91.8]);
$dlanguages->push(['Python', 'application', 95.8]);
$dlanguages->push(['PHP', 'web', 84.5]);
$dlanguages->push(['Perl', 'web', 66.90000000000001]);
$dlanguages->push(['R', 'computing', 84.7]);
$dlanguages->push(['Ruby', 'web', 75.3]);
$dlanguages->push(['VB.NET', 'application', 63.4]);
$dlanguages->push(['Javascript', 'web', 83]);
$dlanguages->push(['Matlab', 'computing', 72.40000000000001]);
echo "\nDOUBLY LINK LIST LOOP: FIFO\n";
$dlanguages->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
for ($dlanguages->rewind(); $dlanguages->valid(); $dlanguages->next()) {
    echo $dlanguages->current()[0] . "\n";
    echo $dlanguages->current()[1] . "\n";
    echo $dlanguages->current()[2] . "\n";
}
/* FIXED ARRAY  */
$fdatabases = new SplFixedArray(11);
$fdatabases[0] = ['Databases', 'Type', 'Size', 'Ranking'];
$fdatabases[1] = ['Oracle', 'Proprietary', 'Server', 1497.55];
$fdatabases[2] = ['SQL Server', 'Proprietary', 'Server', 1123.16];
$fdatabases[3] = ['PostgreSQL', 'Open-Source', 'Server', 280.09];
$fdatabases[4] = ['MySQL', 'Open-Source', 'Server', 1298.54];
$fdatabases[5] = ['DB2', 'Proprietary', 'Server', 196.13];
$fdatabases[6] = ['SQLite', 'Open-Source', 'File', 100.85];
$fdatabases[7] = ['MS Access', 'Proprietary', 'File', 140.21];
<?php

$stack = new SplDoublyLinkedList();
$stack->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_DELETE);
$stack->push(13);
$stack->push(17);
$stack->push(19);
foreach ($stack as $item) {
    var_dump($item);
}
var_dump(count($stack));
foreach ($stack as $item) {
    var_dump($item);
}
var_dump(count($stack));
Exemplo n.º 11
0
    /**
     * @dataProvider provideCastSplDoublyLinkedList
     */
    public function testCastSplDoublyLinkedList($modeValue, $modeDump)
    {
        $var = new \SplDoublyLinkedList();
        $var->setIteratorMode($modeValue);
        $dump = <<<EOTXT
SplDoublyLinkedList {
%Amode: {$modeDump}
  dllist: []
}
EOTXT;
        $this->assertDumpMatchesFormat($dump, $var);
    }
<?php

$dll = new SplDoublyLinkedList(2);
$dll->setIteratorMode(new SplDoublyLinkedList(2));
<?php

$list = new SplDoublyLinkedList();
$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP);
echo $list->getIteratorMode();
Exemplo n.º 14
0
 public function __construct()
 {
     $list = new \SplDoublyLinkedList();
     $list->setIteratorMode(\SplDoublyLinkedList::IT_MODE_LIFO | \SplDoublyLinkedList::IT_MODE_DELETE);
     $this->collected = $list;
 }
<?php

$dll = new SplDoublyLinkedList();
$dll->push(2);
$dll->push(3);
$dll->push(4);
$dll->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO);
foreach ($dll as $k => $v) {
    echo "{$k}=>{$v}\n";
}
$dll->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
foreach ($dll as $k => $v) {
    echo "{$k}=>{$v}\n";
}
$dll->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_DELETE);
var_dump($dll->count());
foreach ($dll as $k => $v) {
    echo "{$k}=>{$v}\n";
}
var_dump($dll->count());
?>
===DONE===
Exemplo n.º 16
0
// offsetUnset($index)
// 删除参数索引的节点
$list->offsetUnset(3);
// add($index, $value);
// 对指定的索引新增一个新值。 当一个节点用offsetUnset时,并没有直接删除,该节点还仍然会保存在内存中。用add可以重新给该节点设置值
$list->add(3, 'first');
// unshift($value)
// 在链表的开始节点插入value作为新的开始节点
$list->unshift('second');
// shift()
// 将链表的第一个移除
$list->shift();
// setIteratorMode(int $mode)
// 设置链表的模式。等价于下面的情况:
// IT_MODE_LIFO: 栈模式,先进后出;IT_MODE_FIFO:队列模式,先进先出
// IT_MODE_DELETE; IT_MODE_KEEP
$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
// getIteratorMode()
// 获得链表的模式
$list->getIteratorMode();
echo "example: \n";
echo "FIFO (First In First Out): \n";
$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
for ($list->rewind(); $list->valid(); $list->next()) {
    echo $list->current() . "\n";
}
echo "LIFO (First In First Out): \n";
$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO);
for ($list->rewind(); $list->valid(); $list->next()) {
    echo $list->current() . "\n";
}
Exemplo n.º 17
0
 /**
  * Sets the mode of iteration.
  *
  * After changing the direction mode(FIFO or LIFO) on a filled stream, it should be rewinded.
  *
  * @param int $mode See the documentation for `SplDoublyLinkedList::setIteratorMode` for more details.
  * @link http://www.php.net/manual/en/spldoublylinkedlist.setiteratormode.php
  */
 public function setIteratorMode($mode)
 {
     $this->tokens->setIteratorMode($mode);
 }