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

org.eclipse.collections.api.stack.MutableStack Maven / Gradle / Ivy

There is a newer version: 12.0.0.M3
Show newest version
/*
 * 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 java.util.Collection;

import org.eclipse.collections.api.bag.MutableBag;
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.list.ListIterable;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.map.primitive.MutableObjectDoubleMap;
import org.eclipse.collections.api.map.primitive.MutableObjectLongMap;
import org.eclipse.collections.api.multimap.list.MutableListMultimap;
import org.eclipse.collections.api.partition.stack.PartitionMutableStack;
import org.eclipse.collections.api.stack.primitive.MutableBooleanStack;
import org.eclipse.collections.api.stack.primitive.MutableByteStack;
import org.eclipse.collections.api.stack.primitive.MutableCharStack;
import org.eclipse.collections.api.stack.primitive.MutableDoubleStack;
import org.eclipse.collections.api.stack.primitive.MutableFloatStack;
import org.eclipse.collections.api.stack.primitive.MutableIntStack;
import org.eclipse.collections.api.stack.primitive.MutableLongStack;
import org.eclipse.collections.api.stack.primitive.MutableShortStack;
import org.eclipse.collections.api.tuple.Pair;

public interface MutableStack extends StackIterable
{
    /**
     * Adds an item to the top of the stack.
     */
    void push(T item);

    /**
     * Removes and returns the top element of the stack.
     */
    T pop();

    /**
     * Removes and returns a ListIterable of the number of elements specified by the count, beginning with the top of the stack.
     */
    ListIterable pop(int count);

    /**
     * Removes and returns a ListIterable of the number of elements specified by the count,
     * beginning with the top of the stack and puts them into the targeted collection type.
     */
    > R pop(int count, R targetCollection);

    /**
     * Removes and returns a ListIterable of the number of elements specified by the count,
     * beginning with the top of the stack and puts them into a new stack.
     */
    > R pop(int count, R targetStack);

    void clear();

    @Override
    MutableStack takeWhile(Predicate predicate);

    @Override
    MutableStack dropWhile(Predicate predicate);

    @Override
    PartitionMutableStack partitionWhile(Predicate predicate);

    @Override
    MutableStack distinct();

    MutableStack asUnmodifiable();

    MutableStack asSynchronized();

    @Override
    MutableStack tap(Procedure procedure);

    @Override
    MutableStack select(Predicate predicate);

    @Override
    

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

MutableStack rejectWith(Predicate2 predicate, P parameter); @Override MutableStack selectInstancesOf(Class clazz); @Override PartitionMutableStack partition(Predicate predicate); @Override

PartitionMutableStack partitionWith(Predicate2 predicate, P parameter); @Override MutableStack collect(Function function); @Override MutableBooleanStack collectBoolean(BooleanFunction booleanFunction); @Override MutableByteStack collectByte(ByteFunction byteFunction); @Override MutableCharStack collectChar(CharFunction charFunction); @Override MutableDoubleStack collectDouble(DoubleFunction doubleFunction); @Override MutableFloatStack collectFloat(FloatFunction floatFunction); @Override MutableIntStack collectInt(IntFunction intFunction); @Override MutableLongStack collectLong(LongFunction longFunction); @Override MutableShortStack collectShort(ShortFunction shortFunction); @Override MutableStack collectWith(Function2 function, P parameter); @Override MutableStack collectIf(Predicate predicate, Function function); /** * @since 9.1. */ @Override default MutableStack collectWithIndex(ObjectIntToObjectFunction function) { int[] index = {0}; return this.collect(each -> function.valueOf(each, index[0]++)); } @Override MutableStack flatCollect(Function> function); /** * @since 9.2 */ @Override default MutableStack flatCollectWith(Function2> function, P parameter) { return this.flatCollect(each -> function.apply(each, parameter)); } @Override MutableObjectLongMap sumByInt(Function groupBy, IntFunction function); @Override MutableObjectDoubleMap sumByFloat(Function groupBy, FloatFunction function); @Override MutableObjectLongMap sumByLong(Function groupBy, LongFunction function); @Override MutableObjectDoubleMap sumByDouble(Function groupBy, DoubleFunction function); @Override MutableListMultimap groupBy(Function function); /** * @since 9.0 */ @Override default MutableBag countBy(Function function) { return this.asLazy().collect(function).toBag(); } /** * @since 9.0 */ @Override default MutableBag countByWith(Function2 function, P parameter) { return this.asLazy().collectWith(function, parameter).toBag(); } /** * @since 10.0.0 */ @Override default MutableBag countByEach(Function> function) { return this.asLazy().flatCollect(function).toBag(); } @Override MutableListMultimap groupByEach(Function> function); @Override default MutableMap groupByUniqueKey(Function function) { return this.groupByUniqueKey(function, Maps.mutable.withInitialCapacity(this.size())); } @Override MutableStack> zip(Iterable that); @Override MutableStack> zipWithIndex(); @Override default MutableMap aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 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; } @Override default MutableMap aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { MutableMap map = Maps.mutable.empty(); this.forEach(each -> { K key = groupBy.valueOf(each); map.updateValueWith(key, zeroValueFactory, nonMutatingAggregator, each); }); return map; } }