compare one collection against another. collections are
considered equal if both collection classes are of the same
type and both item arrays are considered equal with strict
comparison.

@param Collection $that
@return bool
554989
public function equals(Collection $that) : bool {
        return
            get_class($this) == get_class($that) &&
            $this->items === $that->items;
    }
1220844
function (other) {
        assertNotNull(other);

        // intersection of anything with empty set is empty set, so return if count is 0
        if (this.count() === 0) {
            return;
        }

        var c = collectionCount(other);

        if (c !== -1) {
            if (c === 0) {
                this.clear();
                return;
            }

            // If other is a HashSet, it has unique elements according to its equality comparer,
            // but if they're using different equality comparers, then assumption of uniqueness
            // will fail. So first check if other is a hashset using the same equality comparer;
            // intersect is a lot faster if we can assume uniqueness.

            if (areEqualityComparersEqual(this, other)) {
                var arr = this.table.entries(true),
                    item;

                c = this.count();

                while (c-- > 0) {
                    item = arr[c];
                    if (!other.contains(item)) {
                        this.table.remove(item);
                    }
                }

                return;
            }
        }

        this.intersectWith(new HashSet(other, this.compare));
    }
388004
public function compareTo(Year $that) : int
    {
        if ($this->year > $that->year) {
            return 1;
        }

        if ($this->year < $that->year) {
            return -1;
        }

        return 0;
    }
367292
public function indexOf($collection=null, $item=null) {
    list($collection, $item) = self::_wrapArgs(func_get_args(), 2);
    
    $collection = self::_collection($collection);
    
    $key = array_search($item, $collection, true);
    return self::_wrap((is_bool($key)) ? -1 : $key);
  }
605088
private function isALegacyJsonComparison(Types\Type $one, Types\Type $other) : bool
    {
        if (! $one instanceof Types\JsonType || ! $other instanceof Types\JsonType) {
            return false;
        }

        return ( ! $one instanceof Types\JsonArrayType && $other instanceof Types\JsonArrayType)
            || ( ! $other instanceof Types\JsonArrayType && $one instanceof Types\JsonArrayType);
    }
344741
protected function doFilterWithRepository(
        Collection $collection,
        Repository $repository,
        WhereExpressionCollector $whereExpressionCollector,
        &$params
    ) {
        if ($this->isNumeric) {
            $equals = new MySqlEquals($this->columnName, $this->equalTo);
            return $equals->doFilterWithRepository($collection, $repository, $whereExpressionCollector, $params);
        }

        return true;
    }
739678
public static function compare()
    {
        $args = func_get_args();

        $operator = array_shift($args);

        return call_user_func_array(self::getComparator($operator), $args);
    }
1016033
function (other) {
        assertNotNull(other);

        var c = collectionCount(other);

        if (c !== -1) {
            // if other is the empty set then this is a superset
            if (c === 0) {
                return true;
            }

            else if (areEqualityComparersEqual(this, other)) {
                if (c > this.count()) {
                    return false;
                }
            }
        }

        return containsAllElements(this, other);
    }
457854
protected function verifyContainsEntitiesOnly(Collection $collection) {
			$check = $collection->forAll(function($key, $element) {
				return $element instanceof EntityInterface;
			});

			if (!$check)
				throw new \InvalidArgumentException('Items in the collection must all implement ' .
					EntityInterface::class);
		}
802000
public function sameValueAs(ValueObjectInterface $collection)
    {
        if (false === Util::classEquals($this, $collection) || false === $this->count()->sameValueAs($collection->count())) {
            return false;
        }

        $arrayCollection = $collection->toArray();

        foreach ($this->items as $index => $item) {
            if (!isset($arrayCollection[$index]) || false === $item->sameValueAs($arrayCollection[$index])) {
                return false;
            }
        }

        return true;
    }
81435
public static function isCollectionType(string $type): bool
    {
        if (in_array($type, self::$collectionTypes, true)) {
            return true;
        }

        if (class_exists($type) === true || interface_exists($type) === true) {
            foreach (self::$collectionTypes as $collectionType) {
                if (is_subclass_of($type, $collectionType) === true) {
                    return true;
                }
            }
        }

        return false;
    }
527920
public function isEqualByInstance(CollectionInstanceInterface $instance_in)
    {
        $this->rewind();
        while (!empty($this->current())) {
            if ($this->hasEqualArrays($this->current()->toArray(), $instance_in->toArray())) {
                return true;
            }
            $this->next();
        }
        $this->rewind();
        return false;
    }
889162
public function hasCollection($collection)
    {
        if (empty($this->queriesResultCache[ 'collectionNames' ])) {
            $this->getCollections();
        }

        return (bool)in_array($collection, $this->queriesResultCache[ 'collectionNames' ]);
    }
23794
public function getEqualByInstance(CollectionInstanceInterface $instance_in)
    {
        $this->rewind();
        while (!empty($this->current())) {
            if ($this->hasEqualArrays($this->current()->toArray(), $instance_in->toArray())) {
                return $this->current();
            }
            $this->next();
        }
        return null;
    }
979757
public function sortByType($collection, $types)
    {
        if ($collection instanceof \Traversable) {
            $collection = iterator_to_array($collection);
        }

        // store a map of the original sorting, so the usort can use this to keep the original sorting if the types are
        // equal
        $idToIndexMap = array();
        foreach ($collection as $index => $item) {
            $idToIndexMap[$item->getId()] = $index;
        }

        $numTypes = count($types);

        usort(
            $collection,
            function ($left, $right) use ($types, $idToIndexMap, $numTypes) {
                $localClassNameLeft = Str::classname(get_class($left));
                $localClassNameRight = Str::classname(get_class($right));

                // if same type, use original sorting
                if ($localClassNameRight === $localClassNameLeft) {
                    $indexLeft = $idToIndexMap[$left->getId()];
                    $indexRight = $idToIndexMap[$right->getId()];
                } else {
                    $indexLeft = array_search($localClassNameLeft, $types);
                    $indexRight = array_search($localClassNameRight, $types);

                    // assume that types that aren't defined, should come last.
                    if (false === $indexLeft) {
                        $indexLeft = $numTypes + 1;
                    }
                    if (false === $indexRight) {
                        $indexRight = $numTypes + 1;
                    }
                }

                if ($indexLeft < $indexRight) {
                    return -1;
                }
                if ($indexLeft > $indexRight) {
                    return 1;
                }
                return 0;
            }
        );

        return $collection;
    }
1233365
protected function compareCollection(DocumentSchema $document)
    {
        if ($document->getDatabase() != $this->schema->getDatabase()) {
            return false;
        }

        return $document->getCollection() == $this->schema->getCollection();
    }
823283
public function diff(Collection $collection) : self
    {
        foreach ($this->elements as $element) {
            if (!$collection->contains($element)) {
                $this->removeElement($element);
            }
        }

        foreach ($collection as $element) {
            if (!$this->contains($element)) {
                $this->add($element);
            }
        }

        return $this;
    }