Exemple #1
0
 /**
  * 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);
 }
Exemple #2
0
 /**
  * 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++;
 }
Exemple #3
0
 /**
  * Verifica se os objetos são iguais
  * @param TObject $o
  * @return boolean
  */
 public function equals(TObject $o)
 {
     if ($this->hashCode() == $o->hashCode()) {
         return TRUE;
     }
     return FALSE;
 }
 /**
  * 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;
 }