org.eclipse.collections.api.stack.ImmutableStack Maven / Gradle / Ivy
/*
* Copyright (c) 2017 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.stack;
import org.eclipse.collections.api.bag.ImmutableBag;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.Function0;
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.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.map.ImmutableMap;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.map.primitive.ImmutableObjectDoubleMap;
import org.eclipse.collections.api.map.primitive.ImmutableObjectLongMap;
import org.eclipse.collections.api.multimap.list.ImmutableListMultimap;
import org.eclipse.collections.api.partition.stack.PartitionImmutableStack;
import org.eclipse.collections.api.stack.primitive.ImmutableBooleanStack;
import org.eclipse.collections.api.stack.primitive.ImmutableByteStack;
import org.eclipse.collections.api.stack.primitive.ImmutableCharStack;
import org.eclipse.collections.api.stack.primitive.ImmutableDoubleStack;
import org.eclipse.collections.api.stack.primitive.ImmutableFloatStack;
import org.eclipse.collections.api.stack.primitive.ImmutableIntStack;
import org.eclipse.collections.api.stack.primitive.ImmutableLongStack;
import org.eclipse.collections.api.stack.primitive.ImmutableShortStack;
import org.eclipse.collections.api.tuple.Pair;
public interface ImmutableStack extends StackIterable
{
ImmutableStack push(T item);
ImmutableStack pop();
ImmutableStack pop(int count);
@Override
ImmutableStack takeWhile(Predicate super T> predicate);
@Override
ImmutableStack dropWhile(Predicate super T> predicate);
@Override
PartitionImmutableStack partitionWhile(Predicate super T> predicate);
@Override
ImmutableStack distinct();
@Override
ImmutableStack tap(Procedure super T> procedure);
@Override
ImmutableStack select(Predicate super T> predicate);
@Override
ImmutableStack selectWith(Predicate2 super T, ? super P> predicate, P parameter);
@Override
ImmutableStack reject(Predicate super T> predicate);
@Override
ImmutableStack rejectWith(Predicate2 super T, ? super P> predicate, P parameter);
@Override
ImmutableStack selectInstancesOf(Class clazz);
@Override
PartitionImmutableStack partition(Predicate super T> predicate);
@Override
PartitionImmutableStack partitionWith(Predicate2 super T, ? super P> predicate, P parameter);
@Override
ImmutableStack collect(Function super T, ? extends V> function);
@Override
ImmutableBooleanStack collectBoolean(BooleanFunction super T> booleanFunction);
@Override
ImmutableByteStack collectByte(ByteFunction super T> byteFunction);
@Override
ImmutableCharStack collectChar(CharFunction super T> charFunction);
@Override
ImmutableDoubleStack collectDouble(DoubleFunction super T> doubleFunction);
@Override
ImmutableFloatStack collectFloat(FloatFunction super T> floatFunction);
@Override
ImmutableIntStack collectInt(IntFunction super T> intFunction);
@Override
ImmutableLongStack collectLong(LongFunction super T> longFunction);
@Override
ImmutableShortStack collectShort(ShortFunction super T> shortFunction);
@Override
ImmutableStack collectWith(Function2 super T, ? super P, ? extends V> function, P parameter);
@Override
ImmutableStack collectIf(Predicate super T> predicate, Function super T, ? extends V> function);
/**
* @since 9.1.
*/
@Override
default ImmutableStack collectWithIndex(ObjectIntToObjectFunction super T, ? extends V> function)
{
int[] index = {0};
return this.collect(each -> function.valueOf(each, index[0]++));
}
@Override
ImmutableStack flatCollect(Function super T, ? extends Iterable> function);
/**
* @since 9.2
*/
@Override
default ImmutableStack flatCollectWith(Function2 super T, ? super P, ? extends Iterable> function, P parameter)
{
return this.flatCollect(each -> function.apply(each, parameter));
}
@Override
ImmutableListMultimap groupBy(Function super T, ? extends V> function);
/**
* @since 9.0
*/
@Override
default ImmutableBag countBy(Function super T, ? extends V> function)
{
return this.asLazy().collect(function).toBag().toImmutable();
}
/**
* @since 9.0
*/
@Override
default ImmutableBag countByWith(Function2 super T, ? super P, ? extends V> function, P parameter)
{
return this.asLazy().collectWith(function, parameter).toBag().toImmutable();
}
/**
* @since 10.0.0
*/
@Override
default ImmutableBag countByEach(Function super T, ? extends Iterable> function)
{
return this.asLazy().flatCollect(function).toBag().toImmutable();
}
@Override
ImmutableListMultimap groupByEach(Function super T, ? extends Iterable> function);
@Override
default ImmutableMap groupByUniqueKey(Function super T, ? extends V> function)
{
MutableMap target = Maps.mutable.withInitialCapacity(this.size());
return this.groupByUniqueKey(function, target).toImmutable();
}
@Override
ImmutableStack> zip(Iterable that);
@Override
ImmutableStack> zipWithIndex();
@Override
default ImmutableMap aggregateInPlaceBy(
Function super T, ? extends K> groupBy,
Function0 extends V> zeroValueFactory,
Procedure2 super V, ? super T> mutatingAggregator)
{
MutableMap map = Maps.mutable.empty();
this.forEach(each ->
{
K key = groupBy.valueOf(each);
V value = map.getIfAbsentPut(key, zeroValueFactory);
mutatingAggregator.value(value, each);
});
return map.toImmutable();
}
@Override
default ImmutableMap aggregateBy(
Function super T, ? extends K> groupBy,
Function0 extends V> zeroValueFactory,
Function2 super V, ? super T, ? extends V> nonMutatingAggregator)
{
MutableMap map = this.aggregateBy(
groupBy,
zeroValueFactory,
nonMutatingAggregator,
Maps.mutable.empty());
return map.toImmutable();
}
@Override
ImmutableObjectLongMap sumByInt(Function super T, ? extends V> groupBy, IntFunction super T> function);
@Override
ImmutableObjectDoubleMap sumByFloat(Function super T, ? extends V> groupBy, FloatFunction super T> function);
@Override
ImmutableObjectLongMap sumByLong(Function super T, ? extends V> groupBy, LongFunction super T> function);
@Override
ImmutableObjectDoubleMap sumByDouble(Function super T, ? extends V> groupBy, DoubleFunction super T> function);
/**
* Size takes linear time on ImmutableStacks.
*/
@Override
int size();
}