Example #1
0
 /**
  * @return boolean Wether the action was successfull or not
  */
 public function addAll(\blaze\collections\Collection $obj)
 {
     $ar = $obj->toArray();
     foreach ($ar as $val) {
         $this->add($val);
     }
 }
Example #2
0
 /**
  * {@inheritDoc}
  * When the bag has not enough space for all object nothing is added and false is returned.
  */
 public function addAll(\blaze\collections\Collection $obj)
 {
     if ($obj->count() + $this->count() <= $this->maxCount) {
         return $this->bag->addAll($obj);
     }
     return false;
 }
Example #3
0
 /**
  * {@inheritDoc}
  * When the list has not enough space for all object nothing is added and false is returned.
  */
 public function addAllAt(\int $index, \blaze\collections\Collection $obj)
 {
     if ($obj->count() + $this->count() <= $this->maxCount) {
         return $this->list->addAllAt($index, $c);
     } else {
         return false;
     }
 }
Example #4
0
 /**
  * @return boolean Wether the action was successfull or not
  */
 public function retainAll(\blaze\collections\Collection $obj)
 {
     $ret = false;
     foreach ($this as $val) {
         if (!$obj->contains($val)) {
             $this->remove($val);
             $ret = true;
         }
     }
     return $ret;
 }
 public function getIterator()
 {
     return $this->collection->getIterator();
 }
Example #6
0
 /**
  * @return boolean Wether the action was successfull or not
  */
 public function retainAll(\blaze\collections\Collection $obj)
 {
     $retained = array();
     $arr = $obj->toArray();
     for ($i = 0; $i < $this->size; $i++) {
         for ($j = 0; $j < $obj->size(); $j++) {
             if ($this->data[$i]->equals($arr[$j])) {
                 $retained[] = $this->data[$i];
                 break;
             }
         }
     }
     $changed = count($retained) != $this->size;
     $this->size = count($retained);
     $this->data = $retained;
     return $changed;
 }
Example #7
0
 /**
  * Returns the minimum element of the given collection, according to the natural ordering of its elements.
  */
 public static function min(Collection $src, \blaze\lang\Comparator $comp = null)
 {
     if ($src->size() == 0) {
         return null;
     }
     $arr = $src->toArray();
     $min = $arr[0];
     foreach ($arr as $val) {
         if ($comp == null && $min->compareTo($val) > 0 || $comp != null && $comp->compare($min, $val) > 0) {
             $min = $val;
         }
     }
     return $min;
 }
Example #8
0
 /**
  * @return boolean Wether the action was successfull or not
  */
 public function removeAll(\blaze\collections\Collection $obj)
 {
     $ar = $obj->toArray();
     $ret = false;
     for ($i = 0; $i < count($ar); $i++) {
         if ($this->remove($ar[$i])) {
             $ret = true;
         }
     }
     return $ret;
 }