org.eclipse.collections.api.bag.ImmutableBag Maven / Gradle / Ivy
/*
* Copyright (c) 2018 Goldman Sachs and others.
* 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.bag;
import org.eclipse.collections.api.bag.primitive.ImmutableBooleanBag;
import org.eclipse.collections.api.bag.primitive.ImmutableByteBag;
import org.eclipse.collections.api.bag.primitive.ImmutableCharBag;
import org.eclipse.collections.api.bag.primitive.ImmutableDoubleBag;
import org.eclipse.collections.api.bag.primitive.ImmutableFloatBag;
import org.eclipse.collections.api.bag.primitive.ImmutableIntBag;
import org.eclipse.collections.api.bag.primitive.ImmutableLongBag;
import org.eclipse.collections.api.bag.primitive.ImmutableShortBag;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.Function2;
import org.eclipse.collections.api.block.function.primitive.BooleanFunction;
import org.eclipse.collections.api.block.function.primitive.ByteFunction;
import org.eclipse.collections.api.block.function.primitive.CharFunction;
import org.eclipse.collections.api.block.function.primitive.DoubleFunction;
import org.eclipse.collections.api.block.function.primitive.FloatFunction;
import org.eclipse.collections.api.block.function.primitive.IntFunction;
import org.eclipse.collections.api.block.function.primitive.LongFunction;
import org.eclipse.collections.api.block.function.primitive.ObjectIntToObjectFunction;
import org.eclipse.collections.api.block.function.primitive.ShortFunction;
import org.eclipse.collections.api.block.predicate.Predicate;
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.block.predicate.primitive.IntPredicate;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.multimap.bag.ImmutableBagMultimap;
import org.eclipse.collections.api.ordered.OrderedIterable;
import org.eclipse.collections.api.partition.bag.PartitionImmutableBag;
import org.eclipse.collections.api.set.ImmutableSet;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.api.tuple.Pair;
import org.eclipse.collections.api.tuple.primitive.ObjectIntPair;
/**
* @since 1.0
*/
public interface ImmutableBag extends UnsortedBag, ImmutableBagIterable
{
@Override
ImmutableBag newWith(T element);
@Override
ImmutableBag newWithout(T element);
@Override
ImmutableBag newWithAll(Iterable extends T> elements);
@Override
ImmutableBag newWithoutAll(Iterable extends T> elements);
@Override
ImmutableBag selectByOccurrences(IntPredicate predicate);
/**
* @since 9.2
*/
@Override
default ImmutableBag selectDuplicates()
{
return this.selectByOccurrences(occurrences -> occurrences > 1);
}
/**
* @since 9.2
*/
@Override
default ImmutableSet selectUnique()
{
MutableSet result = Sets.mutable.empty();
this.forEachWithOccurrences((each, occurrences) ->
{
if (occurrences == 1)
{
result.add(each);
}
});
return result.toImmutable();
}
@Override
ImmutableBag tap(Procedure super T> procedure);
@Override
ImmutableBag select(Predicate super T> predicate);
@Override
ImmutableBag selectWith(Predicate2 super T, ? super P> predicate, P parameter);
@Override
ImmutableBag reject(Predicate super T> predicate);
@Override
ImmutableBag rejectWith(Predicate2 super T, ? super P> predicate, P parameter);
@Override
PartitionImmutableBag partition(Predicate super T> predicate);
@Override
PartitionImmutableBag partitionWith(Predicate2 super T, ? super P> predicate, P parameter);
@Override
ImmutableBag selectInstancesOf(Class clazz);
@Override
ImmutableBag collect(Function super T, ? extends V> function);
@Override
ImmutableBooleanBag collectBoolean(BooleanFunction super T> booleanFunction);
@Override
ImmutableByteBag collectByte(ByteFunction super T> byteFunction);
@Override
ImmutableCharBag collectChar(CharFunction super T> charFunction);
@Override
ImmutableDoubleBag collectDouble(DoubleFunction super T> doubleFunction);
@Override
ImmutableFloatBag collectFloat(FloatFunction super T> floatFunction);
@Override
ImmutableIntBag collectInt(IntFunction super T> intFunction);
@Override
ImmutableLongBag collectLong(LongFunction super T> longFunction);
@Override
ImmutableShortBag collectShort(ShortFunction super T> shortFunction);
@Override
ImmutableBag collectWith(Function2 super T, ? super P, ? extends V> function, P parameter);
@Override
ImmutableBag collectIf(Predicate super T> predicate, Function super T, ? extends V> function);
@Override
ImmutableBag collectWithOccurrences(ObjectIntToObjectFunction super T, ? extends V> function);
@Override
ImmutableBag flatCollect(Function super T, ? extends Iterable> function);
/**
* @since 9.2
*/
@Override
default ImmutableBag flatCollectWith(Function2 super T, ? super P, ? extends Iterable> function, P parameter)
{
return this.flatCollect(each -> function.apply(each, parameter));
}
/**
* @since 9.0
*/
@Override
default ImmutableBag countBy(Function super T, ? extends V> function)
{
return this.collect(function);
}
/**
* @since 9.0
*/
@Override
default ImmutableBag countByWith(Function2 super T, ? super P, ? extends V> function, P parameter)
{
return this.collectWith(function, parameter);
}
/**
* @since 10.0.0
*/
@Override
default ImmutableBag countByEach(Function super T, ? extends Iterable> function)
{
return this.flatCollect(function);
}
@Override
ImmutableBagMultimap groupBy(Function super T, ? extends V> function);
@Override
ImmutableBagMultimap groupByEach(Function super T, ? extends Iterable> function);
/**
* @deprecated in 6.0. Use {@link OrderedIterable#zip(Iterable)} instead.
*/
@Override
@Deprecated
ImmutableBag> zip(Iterable that);
/**
* @deprecated in 6.0. Use {@link OrderedIterable#zipWithIndex()} instead.
*/
@Override
@Deprecated
ImmutableSet> zipWithIndex();
/**
* @since 6.0
*/
@Override
ImmutableList> topOccurrences(int count);
/**
* @since 6.0
*/
@Override
ImmutableList> bottomOccurrences(int count);
}