All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.collections.api.set.SetIterable Maven / Gradle / Ivy

There is a newer version: 12.0.0.M3
Show newest version
/*
 * Copyright (c) 2016 Goldman Sachs.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v. 1.0 which accompany this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 */

package org.eclipse.collections.api.set;

import java.util.Set;
import java.util.concurrent.ExecutorService;

import org.eclipse.collections.api.LazyIterable;
import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.annotation.Beta;
import org.eclipse.collections.api.block.predicate.Predicate;
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.ordered.OrderedIterable;
import org.eclipse.collections.api.partition.set.PartitionSet;
import org.eclipse.collections.api.tuple.Pair;

/**
 * A Read-only Set api, with the minor exception inherited from java.lang.Iterable (iterable.iterator().remove()).
 */
public interface SetIterable extends RichIterable
{
    /**
     * Returns the set of all objects that are a member of {@code this} or {@code set} or both. The union of [1, 2, 3]
     * and [2, 3, 4] is the set [1, 2, 3, 4]. If equal elements appear in both sets, then the output will contain the
     * copy from {@code this}.
     */
    SetIterable union(SetIterable set);

    /**
     * Same as {@link #union(SetIterable)} but adds all the objects to {@code targetSet} and returns it.
     */
    > R unionInto(SetIterable set, R targetSet);

    /**
     * Returns the set of all objects that are members of both {@code this} and {@code set}. The intersection of
     * [1, 2, 3] and [2, 3, 4] is the set [2, 3]. The output will contain instances from {@code this}, not {@code set}.
     */
    SetIterable intersect(SetIterable set);

    /**
     * Same as {@link #intersect(SetIterable)} but adds all the objects to {@code targetSet} and returns it.
     */
    > R intersectInto(SetIterable set, R targetSet);

    /**
     * Returns the set of all members of {@code this} that are not members of {@code subtrahendSet}. The difference of
     * [1, 2, 3] and [2, 3, 4] is [1].
     */
    SetIterable difference(SetIterable subtrahendSet);

    /**
     * Same as {@link #difference(SetIterable)} but adds all the objects to {@code targetSet} and returns it.
     */
    > R differenceInto(SetIterable subtrahendSet, R targetSet);

    /**
     * Returns the set of all objects that are a member of exactly one of {@code this} and {@code setB} (elements which
     * are in one of the sets, but not in both). For instance, for the sets [1, 2, 3] and [2, 3, 4], the symmetric
     * difference set is [1, 4] . It is the set difference of the union and the intersection.
     */
    SetIterable symmetricDifference(SetIterable setB);

    /**
     * Same as {@link #symmetricDifference(SetIterable)} but adds all the objects to {@code targetSet} and returns it.
     */
    > R symmetricDifferenceInto(SetIterable set, R targetSet);

    /**
     * Returns {@literal true} if all the members of {@code this} are also members of {@code candidateSuperset}.
     * For example, [1, 2] is a subset of [1, 2, 3], but [1, 4] is not.
     */
    boolean isSubsetOf(SetIterable candidateSuperset);

    /**
     * Returns {@literal true} if all the members of {@code this} are also members of {@code candidateSuperset} and the
     * two sets are not equal. For example, [1, 2] is a proper subset of [1, 2, 3], but [1, 2, 3] is not.
     */
    boolean isProperSubsetOf(SetIterable candidateSuperset);

    /**
     * Returns the set whose members are all possible ordered pairs (a, b) where a is a member of {@code this} and b is a
     * member of {@code set}.
     */
     LazyIterable> cartesianProduct(SetIterable set);

    @Override
    SetIterable tap(Procedure procedure);

    @Override
    SetIterable select(Predicate predicate);

    @Override
    

SetIterable selectWith(Predicate2 predicate, P parameter); @Override SetIterable reject(Predicate predicate); @Override

SetIterable rejectWith(Predicate2 predicate, P parameter); @Override PartitionSet partition(Predicate predicate); @Override

PartitionSet partitionWith(Predicate2 predicate, P parameter); @Override SetIterable selectInstancesOf(Class clazz); /** * @deprecated in 6.0. Use {@link OrderedIterable#zipWithIndex()} instead. */ @Override @Deprecated SetIterable> zipWithIndex(); /** * Returns a parallel iterable of this SetIterable. * * @since 6.0 */ @Beta ParallelSetIterable asParallel(ExecutorService executorService, int batchSize); /** * Follows the same general contract as {@link Set#equals(Object)}. */ @Override boolean equals(Object o); /** * Follows the same general contract as {@link Set#hashCode()}. */ @Override int hashCode(); ImmutableSetIterable toImmutable(); }