Get the intersection between this collection and another one.

@param \qtism\common\collections\AbstractCollection $collection
@return \qtism\common\collections\AbstractCollection
322498
public function intersect(AbstractCollection $collection)
    {
        if (get_class($this) === get_class($collection)) {
            $newData = array_intersect($this->dataPlaceHolder, $collection->getDataPlaceHolder());

            return new static($newData);
        } else {
            $msg = "Intersection may apply only on two collections of the same type.";
            throw new InvalidArgumentException($msg);
        }
    }
192749
public static <T> Collection<T> intersect(Collection<T> first,
                                              Collection<T> second) {
        E.checkNotNull(first, "first");
        E.checkNotNull(second, "second");

        HashSet<T> results = null;
        if (first instanceof HashSet) {
            @SuppressWarnings("unchecked")
            HashSet<T> clone = (HashSet<T>) ((HashSet<T>) first).clone();
            results = clone;
        } else {
            results = new HashSet<>(first);
        }
        results.retainAll(second);
        return results;
    }
550616
public function getDictionary($collection)
	{
		$dictionary = array();

		foreach ($collection as $value)
		{
			$dictionary[$value->getKey()] = $value;
		}

		return $dictionary;
	}
1209370
public function getKeys($collection)
    {
        $cursor = $this->server->executeQuery($this->database . '.' . $collection,
            new \MongoDb\Driver\Query([], ['limit' => 1]));

        $result = current($cursor->toArray());

        $this->queriesResultCache[ 'collectionKeys' ][ $collection ] = [];

        foreach (get_object_vars($result) as $key => $value) {
            $this->queriesResultCache[ 'collectionKeys' ][ $collection ][] = $key;
        }

        return $this->queriesResultCache[ 'collectionKeys' ][ $collection ];
    }
1067237
public function intersects(Collection $list) : bool
    {
        $intersect = [];
        $main = $this->getSize();
        $oth = $list->getSize();

        if ($main > $oth) {
            foreach ($list->getList() as $item) {
                $intersect[] = in_array($item, $this->toArray());
            }
        } elseif ($oth > $main) {
            foreach ($this->getList() as $item) {
                $intersect[] = in_array($item, $list->toArray());
            }
        }

        return in_array(true, $intersect);
    }
236121
public function getAll($collection, array $options = [])
    {
        /** @var AbstractHttpRequest $request */
        $request          = $this->getRequest();
        $request->options = $options;
        $request->path    = $this->client->fullDatabasePath . static::API_PATH;
        $request->path .= '?collection=' . $collection;
        $request->method = static::METHOD_GET;

        return $this->getReturnObject($request);
    }
1068209
public function get_one($collection = "")
	{
		if (empty($collection))
		{
			throw new \Mongo_DbException("In order to retrieve documents from MongoDB you must provide a collection name.");
		}

		if ($this->profiling)
		{
			$query = json_encode(array(
			'type'			=> 'findOne',
			'collection'	=> $collection,
			'select'		=> $this->selects,
			'where'			=> $this->wheres,
			));

			$benchmark = \Profiler::start((string) $this->db, $query);
		}

		$returns = $this->db->{$collection}->findOne($this->wheres, $this->selects);

		if (isset($benchmark))
		{
			\Profiler::stop($benchmark);
		}

		$this->_clear();

		return $returns;
	}
1045797
public function intersect( common_Collection $collection)
    {
        $returnValue = null;

        
         $returnValue = new core_kernel_classes_ContainerCollection(new common_Object(__METHOD__));
         $returnValue->sequence = array_uintersect($this->sequence, $collection->sequence, 'core_kernel_classes_ContainerComparator::compare');
        

        return $returnValue;
    }
102572
public static function fromCollection($collection) {
		if (!(is_array($collection) || $collection instanceof Iterator)) {
			throw new InvalidArgumentException('$collection is neither an array nor an iterator');
		}

		return self::toCollection($collection);
	}
691959
public function getCollectionId($collection)
    {
        if ($collection instanceof Collection) {
            $collectionId = $collection->getId();

            return $collectionId;
        }

        $collectionId = $collection;

        return $collectionId;
    }
358411
public function createCollection(Collection $collection): Collection
    {
        $query = $this->connection->createQueryBuilder()
            ->insert('ngbm_collection')
            ->values(
                [
                    'id' => ':id',
                    'status' => ':status',
                    'start' => ':start',
                    'length' => ':length',
                    'translatable' => ':translatable',
                    'main_locale' => ':main_locale',
                    'always_available' => ':always_available',
                ]
            )
            ->setValue(
                'id',
                $collection->id !== null ?
                    (int) $collection->id :
                    $this->connectionHelper->getAutoIncrementValue('ngbm_collection')
            )
            ->setParameter('status', $collection->status, Type::INTEGER)
            ->setParameter('start', $collection->offset, Type::INTEGER)
            ->setParameter('length', $collection->limit, Type::INTEGER)
            ->setParameter('translatable', $collection->isTranslatable, Type::BOOLEAN)
            ->setParameter('main_locale', $collection->mainLocale, Type::STRING)
            ->setParameter('always_available', $collection->alwaysAvailable, Type::BOOLEAN);

        $query->execute();

        $collection->id = $collection->id ?? (int) $this->connectionHelper->lastInsertId('ngbm_collection');

        return $collection;
    }
1185325
public static function toMap($collection) {
		$map = new Map();
		foreach ($collection as $k => $v) {
			$map->set($k, self::toCollection($v));
		}

		return $map;
	}
1062438
public function getFilters($collection = self::DEFAULT_COLLECTION)
    {
        if (!isset($this->_collections[$collection])) {
            $this->_collections[$collection] = $this->_loadCollection($collection);
        }

        return $this->_collections[$collection];
    }
53317
protected function collection_query( &$collection ) 
	{
		$local_keys = array();
		
		foreach( $collection as $item )
		{
			$local_keys[] = $item->raw( $this->local_key );
		}
		
		// set the correct collection where
		$this->query->wheres = array();
		$this->query->where( $this->foreign_key, 'in', $local_keys );
		$this->query->group_result( $this->foreign_key );
		
		$this->query->limit( null );
	}
439431
function intersection(Set $that) {
        $intersection = $this->cloneEmpty();

        $this->addIf($intersection, $this, [$that, 'has']);

        return $intersection;
    }
801919
public function collection($collection, $wrap = true)
    {
        $collection = $this->database->selectCollection($collection);
        $wrap && $collection = new Collection($collection);

        return $collection;
    }
162764
public function loadCollection(Collections\AbstractCollection $collection)
    {
        $identifiers = $collection->getIdentifiers();
        if (empty($identifiers)) {
            // Nothing to query.
            return [];
        }
        if ($collection instanceof Collections\InverseCollection) {
            $recordSet = $this->retrieveInverseRecords($collection->getOwner()->getType(), $collection->getType(), $collection->getIdentifiers(), $collection->getQueryField());
        } else {
            $recordSet = $this->retrieveRecords($collection->getType(), $collection->getIdentifiers());
        }

        $models = [];
        foreach ($recordSet as $record) {
            if (true === $this->cache->has($record['type'], $record['identifier'])) {
                $models[] = $this->cache->get($record['type'], $record['identifier']);
                continue;
            }
            $models[] = $this->loadModel($collection->getType(), $record);
        }
        return $models;
    }