/** * Insere o elemento especificado na frente da fila * @param mixed $e * @return void */ public function addFirst($e) { if (!is_object($e)) { $e = TObject::create($e); } if (!$this->checkType($e)) { throw new UnexpectedValueException("Tipo de dados esperado {$this->getTypeCast()} em " . __METHOD__); } return array_unshift($this->collection, $e); }
/** * Insere o elemento especificado na posição especificada nesta lista. * Desloca o elemento atualmente naquela posição (se houver) e quaisquer * elementos subsequentes para a direita (adiciona um aos seus índices). * @param int $index * @param mixed $element */ public function addIn($index, $element) { if (!is_int($index)) { throw new UnexpectedValueException('Índice informado não é um INTEIRO'); } if ($index > $this->size() || $index < 0) { throw new IndexOutOfBoundsException('Indice fora do intervalo'); } if (!is_object($element)) { $element = TObject::create($element); } $this->checkType($element); if (isset($this->collection[$index])) { array_splice($this->collection, $index, 0, array($element)); } else { $this->collection[$index] = $element; } $this->modCount++; }
/** * Verifica se o tipo do elemento passado é o aceito pela coleção * @param mixed $e * @return boolean Retorna TRUE caso seja um tipo aceito */ protected function checkType($e) { if ($this->getTypeCast() == 'mixed') { return true; } if (is_object($e) && is_a($e, $this->getTypeCast())) { return true; } if (!is_object($e)) { $n = TObject::create($e); if (is_a($n, $this->getTypeCast())) { return true; } } return false; }