/** * Adds a set of elements as long no duplicates are found * * @param CollectionInterface $collection * @return boolean */ public function addAll(CollectionInterface $collection = NULL) { $iterator = $collection->getIterator(); foreach ($iterator as $element) { if ($this->contains($element)) { throw new \InvalidArgumentException('Duplicate element are not allowed'); } } return parent::addAll($collection); }
/** * * @param CollectionInterface $collection * @return boolean */ public function containsAll(CollectionInterface $collection) { $iterator = $collection->getIterator(); foreach ($iterator as $element) { if (!$this->contains($element)) { return false; } } return true; }