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

com.gs.collections.impl.stack.mutable.UnmodifiableStack Maven / Gradle / Ivy

Go to download

GS Collections is a collections framework for Java. It has JDK-compatible List, Set and Map implementations with a rich API and set of utility classes that work with any JDK compatible Collections, Arrays, Maps or Strings. The iteration protocol was inspired by the Smalltalk collection framework.

There is a newer version: 7.0.3
Show newest version
/*
 * Copyright 2014 Goldman Sachs.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.gs.collections.impl.stack.mutable;

import java.io.Serializable;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;

import com.gs.collections.api.LazyIterable;
import com.gs.collections.api.RichIterable;
import com.gs.collections.api.bag.MutableBag;
import com.gs.collections.api.bag.sorted.MutableSortedBag;
import com.gs.collections.api.block.function.Function;
import com.gs.collections.api.block.function.Function0;
import com.gs.collections.api.block.function.Function2;
import com.gs.collections.api.block.function.primitive.BooleanFunction;
import com.gs.collections.api.block.function.primitive.ByteFunction;
import com.gs.collections.api.block.function.primitive.CharFunction;
import com.gs.collections.api.block.function.primitive.DoubleFunction;
import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction;
import com.gs.collections.api.block.function.primitive.FloatFunction;
import com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction;
import com.gs.collections.api.block.function.primitive.IntFunction;
import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction;
import com.gs.collections.api.block.function.primitive.LongFunction;
import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction;
import com.gs.collections.api.block.function.primitive.ShortFunction;
import com.gs.collections.api.block.predicate.Predicate;
import com.gs.collections.api.block.predicate.Predicate2;
import com.gs.collections.api.block.procedure.Procedure;
import com.gs.collections.api.block.procedure.Procedure2;
import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure;
import com.gs.collections.api.collection.primitive.MutableBooleanCollection;
import com.gs.collections.api.collection.primitive.MutableByteCollection;
import com.gs.collections.api.collection.primitive.MutableCharCollection;
import com.gs.collections.api.collection.primitive.MutableDoubleCollection;
import com.gs.collections.api.collection.primitive.MutableFloatCollection;
import com.gs.collections.api.collection.primitive.MutableIntCollection;
import com.gs.collections.api.collection.primitive.MutableLongCollection;
import com.gs.collections.api.collection.primitive.MutableShortCollection;
import com.gs.collections.api.list.ListIterable;
import com.gs.collections.api.list.MutableList;
import com.gs.collections.api.map.MutableMap;
import com.gs.collections.api.map.primitive.ObjectDoubleMap;
import com.gs.collections.api.map.primitive.ObjectLongMap;
import com.gs.collections.api.map.sorted.MutableSortedMap;
import com.gs.collections.api.multimap.MutableMultimap;
import com.gs.collections.api.multimap.list.MutableListMultimap;
import com.gs.collections.api.partition.stack.PartitionMutableStack;
import com.gs.collections.api.set.MutableSet;
import com.gs.collections.api.set.sorted.MutableSortedSet;
import com.gs.collections.api.stack.ImmutableStack;
import com.gs.collections.api.stack.MutableStack;
import com.gs.collections.api.stack.primitive.MutableBooleanStack;
import com.gs.collections.api.stack.primitive.MutableByteStack;
import com.gs.collections.api.stack.primitive.MutableCharStack;
import com.gs.collections.api.stack.primitive.MutableDoubleStack;
import com.gs.collections.api.stack.primitive.MutableFloatStack;
import com.gs.collections.api.stack.primitive.MutableIntStack;
import com.gs.collections.api.stack.primitive.MutableLongStack;
import com.gs.collections.api.stack.primitive.MutableShortStack;
import com.gs.collections.api.tuple.Pair;
import com.gs.collections.impl.UnmodifiableIteratorAdapter;
import com.gs.collections.impl.block.factory.PrimitiveFunctions;
import com.gs.collections.impl.block.procedure.MutatingAggregationProcedure;
import com.gs.collections.impl.block.procedure.NonMutatingAggregationProcedure;
import com.gs.collections.impl.map.mutable.UnifiedMap;
import com.gs.collections.impl.map.mutable.primitive.ObjectDoubleHashMap;
import com.gs.collections.impl.map.mutable.primitive.ObjectLongHashMap;

public final class UnmodifiableStack implements MutableStack, Serializable
{
    private static final long serialVersionUID = 1L;

    private final MutableStack mutableStack;

    UnmodifiableStack(MutableStack mutableStack)
    {
        if (mutableStack == null)
        {
            throw new IllegalArgumentException("Cannot create a UnmodifiableStack on a null stack");
        }
        this.mutableStack = mutableStack;
    }

    public static > UnmodifiableStack of(S stack)
    {
        return new UnmodifiableStack(stack);
    }

    public T pop()
    {
        throw new UnsupportedOperationException("Cannot call pop() on " + this.getClass().getSimpleName());
    }

    public ListIterable pop(int count)
    {
        throw new UnsupportedOperationException("Cannot call pop() on " + this.getClass().getSimpleName());
    }

    public > R pop(int count, R targetCollection)
    {
        throw new UnsupportedOperationException("Cannot call pop() on " + this.getClass().getSimpleName());
    }

    public > R pop(int count, R targetStack)
    {
        throw new UnsupportedOperationException("Cannot call pop() on " + this.getClass().getSimpleName());
    }

    public void clear()
    {
        throw new UnsupportedOperationException("Cannot call clear() on " + this.getClass().getSimpleName());
    }

    public void push(T item)
    {
        throw new UnsupportedOperationException("Cannot call push() on " + this.getClass().getSimpleName());
    }

    public Iterator iterator()
    {
        return new UnmodifiableIteratorAdapter(this.mutableStack.iterator());
    }

    public MutableStack select(Predicate predicate)
    {
        return this.mutableStack.select(predicate);
    }

    public 

MutableStack selectWith(Predicate2 predicate, P parameter) { return this.mutableStack.selectWith(predicate, parameter); } public MutableStack reject(Predicate predicate) { return this.mutableStack.reject(predicate); } public

MutableStack rejectWith(Predicate2 predicate, P parameter) { return this.mutableStack.rejectWith(predicate, parameter); } public PartitionMutableStack partition(Predicate predicate) { return this.mutableStack.partition(predicate); } public

PartitionMutableStack partitionWith(Predicate2 predicate, P parameter) { return this.mutableStack.partitionWith(predicate, parameter); } public RichIterable selectInstancesOf(Class clazz) { return this.mutableStack.selectInstancesOf(clazz); } public MutableStack collect(Function function) { return this.mutableStack.collect(function); } public MutableBooleanStack collectBoolean(BooleanFunction booleanFunction) { return this.mutableStack.collectBoolean(booleanFunction); } public R collectBoolean(BooleanFunction booleanFunction, R target) { return this.mutableStack.collectBoolean(booleanFunction, target); } public MutableByteStack collectByte(ByteFunction byteFunction) { return this.mutableStack.collectByte(byteFunction); } public R collectByte(ByteFunction byteFunction, R target) { return this.mutableStack.collectByte(byteFunction, target); } public MutableCharStack collectChar(CharFunction charFunction) { return this.mutableStack.collectChar(charFunction); } public R collectChar(CharFunction charFunction, R target) { return this.mutableStack.collectChar(charFunction, target); } public MutableDoubleStack collectDouble(DoubleFunction doubleFunction) { return this.mutableStack.collectDouble(doubleFunction); } public R collectDouble(DoubleFunction doubleFunction, R target) { return this.mutableStack.collectDouble(doubleFunction, target); } public MutableFloatStack collectFloat(FloatFunction floatFunction) { return this.mutableStack.collectFloat(floatFunction); } public R collectFloat(FloatFunction floatFunction, R target) { return this.mutableStack.collectFloat(floatFunction, target); } public MutableIntStack collectInt(IntFunction intFunction) { return this.mutableStack.collectInt(intFunction); } public R collectInt(IntFunction intFunction, R target) { return this.mutableStack.collectInt(intFunction, target); } public MutableLongStack collectLong(LongFunction longFunction) { return this.mutableStack.collectLong(longFunction); } public R collectLong(LongFunction longFunction, R target) { return this.mutableStack.collectLong(longFunction, target); } public MutableShortStack collectShort(ShortFunction shortFunction) { return this.mutableStack.collectShort(shortFunction); } public R collectShort(ShortFunction shortFunction, R target) { return this.mutableStack.collectShort(shortFunction, target); } public MutableStack collectWith(Function2 function, P parameter) { return this.mutableStack.collectWith(function, parameter); } public MutableStack collectIf(Predicate predicate, Function function) { return this.mutableStack.collectIf(predicate, function); } public MutableStack flatCollect(Function> function) { return this.mutableStack.flatCollect(function); } public MutableStack> zip(Iterable that) { return this.mutableStack.zip(that); } public MutableStack> zipWithIndex() { return this.mutableStack.zipWithIndex(); } public int size() { return this.mutableStack.size(); } public boolean isEmpty() { return this.mutableStack.isEmpty(); } public boolean notEmpty() { return this.mutableStack.notEmpty(); } public T getFirst() { return this.mutableStack.getFirst(); } public T getLast() { return this.mutableStack.getLast(); } public boolean contains(Object object) { return this.mutableStack.contains(object); } public boolean containsAllIterable(Iterable source) { return this.mutableStack.containsAllIterable(source); } public boolean containsAll(Collection source) { return this.mutableStack.containsAll(source); } public boolean containsAllArguments(Object... elements) { return this.mutableStack.containsAllArguments(elements); } public > R select(Predicate predicate, R target) { return this.mutableStack.select(predicate, target); } public > R selectWith(Predicate2 predicate, P parameter, R targetCollection) { return this.mutableStack.selectWith(predicate, parameter, targetCollection); } public > R reject(Predicate predicate, R target) { return this.mutableStack.reject(predicate, target); } public > R rejectWith(Predicate2 predicate, P parameter, R targetCollection) { return this.mutableStack.rejectWith(predicate, parameter, targetCollection); } public > R collect(Function function, R target) { return this.mutableStack.collect(function, target); } public > R collectWith(Function2 function, P parameter, R targetCollection) { return this.mutableStack.collectWith(function, parameter, targetCollection); } public > R collectIf(Predicate predicate, Function function, R target) { return this.mutableStack.collectIf(predicate, function, target); } public > R flatCollect(Function> function, R target) { return this.mutableStack.flatCollect(function, target); } public T detect(Predicate predicate) { return this.mutableStack.detect(predicate); } public

T detectWith(Predicate2 predicate, P parameter) { return this.mutableStack.detectWith(predicate, parameter); } public T detectIfNone(Predicate predicate, Function0 function) { return this.mutableStack.detectIfNone(predicate, function); } public

T detectWithIfNone(Predicate2 predicate, P parameter, Function0 function) { return this.mutableStack.detectWithIfNone(predicate, parameter, function); } public int count(Predicate predicate) { return this.mutableStack.count(predicate); } public

int countWith(Predicate2 predicate, P parameter) { return this.mutableStack.countWith(predicate, parameter); } public boolean anySatisfy(Predicate predicate) { return this.mutableStack.anySatisfy(predicate); } public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { return this.mutableStack.anySatisfyWith(predicate, parameter); } public boolean allSatisfy(Predicate predicate) { return this.mutableStack.allSatisfy(predicate); } public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { return this.mutableStack.allSatisfyWith(predicate, parameter); } public boolean noneSatisfy(Predicate predicate) { return this.mutableStack.noneSatisfy(predicate); } public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { return this.mutableStack.noneSatisfyWith(predicate, parameter); } public IV injectInto(IV injectedValue, Function2 function) { return this.mutableStack.injectInto(injectedValue, function); } public int injectInto(int injectedValue, IntObjectToIntFunction intObjectToIntFunction) { return this.mutableStack.injectInto(injectedValue, intObjectToIntFunction); } public long injectInto(long injectedValue, LongObjectToLongFunction longObjectToLongFunction) { return this.mutableStack.injectInto(injectedValue, longObjectToLongFunction); } public float injectInto(float injectedValue, FloatObjectToFloatFunction floatObjectToFloatFunction) { return this.mutableStack.injectInto(injectedValue, floatObjectToFloatFunction); } public double injectInto(double injectedValue, DoubleObjectToDoubleFunction doubleObjectToDoubleFunction) { return this.mutableStack.injectInto(injectedValue, doubleObjectToDoubleFunction); } public MutableList toList() { return this.mutableStack.toList(); } public MutableList toSortedList() { return this.mutableStack.toSortedList(); } public MutableList toSortedList(Comparator comparator) { return this.mutableStack.toSortedList(comparator); } public > MutableList toSortedListBy(Function function) { return this.mutableStack.toSortedListBy(function); } public MutableSet toSet() { return this.mutableStack.toSet(); } public MutableSortedSet toSortedSet() { return this.mutableStack.toSortedSet(); } public MutableSortedSet toSortedSet(Comparator comparator) { return this.mutableStack.toSortedSet(comparator); } public MutableStack toStack() { return this.mutableStack.toStack(); } public ImmutableStack toImmutable() { return this.mutableStack.toImmutable(); } public > MutableSortedSet toSortedSetBy(Function function) { return this.mutableStack.toSortedSetBy(function); } public MutableBag toBag() { return this.mutableStack.toBag(); } public MutableSortedBag toSortedBag() { return this.mutableStack.toSortedBag(); } public MutableSortedBag toSortedBag(Comparator comparator) { return this.mutableStack.toSortedBag(comparator); } public > MutableSortedBag toSortedBagBy(Function function) { return this.mutableStack.toSortedBagBy(function); } public MutableMap toMap(Function keyFunction, Function valueFunction) { return this.mutableStack.toMap(keyFunction, valueFunction); } public MutableSortedMap toSortedMap(Function keyFunction, Function valueFunction) { return this.mutableStack.toSortedMap(keyFunction, valueFunction); } public MutableSortedMap toSortedMap(Comparator comparator, Function keyFunction, Function valueFunction) { return this.mutableStack.toSortedMap(comparator, keyFunction, valueFunction); } public LazyIterable asLazy() { return this.mutableStack.asLazy(); } public Object[] toArray() { return this.mutableStack.toArray(); } public T[] toArray(T[] a) { return this.mutableStack.toArray(a); } public T min(Comparator comparator) { return this.mutableStack.min(comparator); } public T max(Comparator comparator) { return this.mutableStack.max(comparator); } public T min() { return this.mutableStack.min(); } public T max() { return this.mutableStack.max(); } public > T minBy(Function function) { return this.mutableStack.minBy(function); } public > T maxBy(Function function) { return this.mutableStack.maxBy(function); } public long sumOfInt(IntFunction intFunction) { return this.mutableStack.sumOfInt(intFunction); } public double sumOfFloat(FloatFunction floatFunction) { return this.mutableStack.sumOfFloat(floatFunction); } public long sumOfLong(LongFunction longFunction) { return this.mutableStack.sumOfLong(longFunction); } public double sumOfDouble(DoubleFunction doubleFunction) { return this.mutableStack.sumOfDouble(doubleFunction); } public ObjectLongMap sumByInt(Function groupBy, IntFunction function) { ObjectLongHashMap result = ObjectLongHashMap.newMap(); return this.injectInto(result, PrimitiveFunctions.sumByIntFunction(groupBy, function)); } public ObjectDoubleMap sumByFloat(Function groupBy, FloatFunction function) { ObjectDoubleHashMap result = ObjectDoubleHashMap.newMap(); return this.injectInto(result, PrimitiveFunctions.sumByFloatFunction(groupBy, function)); } public ObjectLongMap sumByLong(Function groupBy, LongFunction function) { ObjectLongHashMap result = ObjectLongHashMap.newMap(); return this.injectInto(result, PrimitiveFunctions.sumByLongFunction(groupBy, function)); } public ObjectDoubleMap sumByDouble(Function groupBy, DoubleFunction function) { ObjectDoubleHashMap result = ObjectDoubleHashMap.newMap(); return this.injectInto(result, PrimitiveFunctions.sumByDoubleFunction(groupBy, function)); } public String makeString() { return this.mutableStack.makeString(); } public String makeString(String separator) { return this.mutableStack.makeString(separator); } public String makeString(String start, String separator, String end) { return this.mutableStack.makeString(start, separator, end); } public void appendString(Appendable appendable) { this.mutableStack.appendString(appendable); } public void appendString(Appendable appendable, String separator) { this.mutableStack.appendString(appendable, separator); } public void appendString(Appendable appendable, String start, String separator, String end) { this.mutableStack.appendString(appendable, start, separator, end); } public MutableListMultimap groupBy(Function function) { return this.mutableStack.groupBy(function); } public > R groupBy(Function function, R target) { return this.mutableStack.groupBy(function, target); } public MutableListMultimap groupByEach(Function> function) { return this.mutableStack.groupByEach(function); } public > R groupByEach(Function> function, R target) { return this.mutableStack.groupByEach(function, target); } public MutableMap groupByUniqueKey(Function function) { return this.mutableStack.groupByUniqueKey(function); } public > R groupByUniqueKey(Function function, R target) { return this.mutableStack.groupByUniqueKey(function, target); } public >> R zip(Iterable that, R target) { return this.mutableStack.zip(that, target); } public >> R zipWithIndex(R target) { return this.mutableStack.zipWithIndex(target); } public RichIterable> chunk(int size) { return this.mutableStack.chunk(size); } public MutableStack tap(Procedure procedure) { this.forEach(procedure); return this; } public void forEach(Procedure procedure) { this.each(procedure); } public void each(Procedure procedure) { this.mutableStack.forEach(procedure); } public T peek() { return this.mutableStack.peek(); } public ListIterable peek(int count) { return this.mutableStack.peek(count); } public T peekAt(int index) { return this.mutableStack.peekAt(index); } @Override public String toString() { return this.mutableStack.toString(); } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { this.mutableStack.forEachWithIndex(objectIntProcedure); } public

void forEachWith(Procedure2 procedure, P parameter) { this.mutableStack.forEachWith(procedure, parameter); } public MutableStack asUnmodifiable() { return this; } public MutableStack asSynchronized() { return this.mutableStack.asSynchronized(); } @Override public boolean equals(Object obj) { return this.mutableStack.equals(obj); } @Override public int hashCode() { return this.mutableStack.hashCode(); } public MutableMap aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator) { MutableMap map = UnifiedMap.newMap(); this.forEach(new MutatingAggregationProcedure(map, groupBy, zeroValueFactory, mutatingAggregator)); return map; } public MutableMap aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { MutableMap map = UnifiedMap.newMap(); this.forEach(new NonMutatingAggregationProcedure(map, groupBy, zeroValueFactory, nonMutatingAggregator)); return map; } }