com.gs.collections.impl.stack.immutable.ImmutableArrayStack Maven / Gradle / Ivy
Show all versions of gs-collections Show documentation
/*
* 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.immutable;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;
import java.util.Collection;
import java.util.Comparator;
import java.util.EmptyStackException;
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.ImmutableMap;
import com.gs.collections.api.map.MapIterable;
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.ImmutableListMultimap;
import com.gs.collections.api.partition.stack.PartitionImmutableStack;
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.StackIterable;
import com.gs.collections.api.stack.primitive.ImmutableBooleanStack;
import com.gs.collections.api.stack.primitive.ImmutableByteStack;
import com.gs.collections.api.stack.primitive.ImmutableCharStack;
import com.gs.collections.api.stack.primitive.ImmutableDoubleStack;
import com.gs.collections.api.stack.primitive.ImmutableFloatStack;
import com.gs.collections.api.stack.primitive.ImmutableIntStack;
import com.gs.collections.api.stack.primitive.ImmutableLongStack;
import com.gs.collections.api.stack.primitive.ImmutableShortStack;
import com.gs.collections.api.tuple.Pair;
import com.gs.collections.impl.block.factory.Comparators;
import com.gs.collections.impl.block.factory.Predicates;
import com.gs.collections.impl.block.procedure.MutatingAggregationProcedure;
import com.gs.collections.impl.block.procedure.NonMutatingAggregationProcedure;
import com.gs.collections.impl.block.procedure.checked.CheckedProcedure;
import com.gs.collections.impl.list.Interval;
import com.gs.collections.impl.list.mutable.FastList;
import com.gs.collections.impl.map.mutable.UnifiedMap;
import com.gs.collections.impl.multimap.list.FastListMultimap;
import com.gs.collections.impl.partition.stack.PartitionArrayStack;
import com.gs.collections.impl.stack.mutable.ArrayStack;
import com.gs.collections.impl.stack.mutable.primitive.BooleanArrayStack;
import com.gs.collections.impl.stack.mutable.primitive.ByteArrayStack;
import com.gs.collections.impl.stack.mutable.primitive.CharArrayStack;
import com.gs.collections.impl.stack.mutable.primitive.DoubleArrayStack;
import com.gs.collections.impl.stack.mutable.primitive.FloatArrayStack;
import com.gs.collections.impl.stack.mutable.primitive.IntArrayStack;
import com.gs.collections.impl.stack.mutable.primitive.LongArrayStack;
import com.gs.collections.impl.stack.mutable.primitive.ShortArrayStack;
import com.gs.collections.impl.utility.Iterate;
import com.gs.collections.impl.utility.LazyIterate;
import net.jcip.annotations.Immutable;
/**
* The immutable equivalent of ArrayStack. Wraps a FastList.
*/
@Immutable
final class ImmutableArrayStack implements ImmutableStack, Serializable
{
private static final long serialVersionUID = 1L;
private final FastList delegate;
private ImmutableArrayStack(T[] newElements)
{
this.delegate = FastList.newListWith(newElements);
}
private ImmutableArrayStack(FastList newElements)
{
this.delegate = newElements;
}
public static ImmutableStack newStack()
{
return new ImmutableArrayStack(FastList.newList());
}
public static ImmutableArrayStack newStack(Iterable extends E> iterable)
{
return new ImmutableArrayStack((E[]) Iterate.toArray(iterable));
}
public static ImmutableArrayStack newStackWith(E... elements)
{
return new ImmutableArrayStack(elements.clone());
}
public static ImmutableArrayStack newStackFromTopToBottom(Iterable extends T> items)
{
return new ImmutableArrayStack(FastList.newList(items).reverseThis());
}
public static ImmutableArrayStack newStackFromTopToBottom(T... items)
{
return new ImmutableArrayStack(FastList.newListWith(items).reverseThis());
}
public ImmutableStack push(T item)
{
FastList newDelegate = FastList.newList(this.delegate);
newDelegate.add(item);
return new ImmutableArrayStack(newDelegate);
}
public ImmutableStack pop()
{
this.checkEmptyStack();
FastList newDelegate = FastList.newList(this.delegate);
newDelegate.remove(this.delegate.size() - 1);
return new ImmutableArrayStack(newDelegate);
}
public ImmutableStack pop(int count)
{
this.checkNegativeCount(count);
if (this.checkZeroCount(count))
{
return this;
}
this.checkEmptyStack();
this.checkSizeLessThanCount(count);
FastList newDelegate = this.delegate.clone();
while (count > 0)
{
newDelegate.remove(this.delegate.size() - 1);
count--;
}
return new ImmutableArrayStack(newDelegate);
}
public T peek()
{
this.checkEmptyStack();
return this.delegate.getLast();
}
private void checkEmptyStack()
{
if (this.delegate.isEmpty())
{
throw new EmptyStackException();
}
}
public ListIterable peek(int count)
{
this.checkNegativeCount(count);
if (this.checkZeroCount(count))
{
return FastList.newList();
}
this.checkEmptyStack();
this.checkSizeLessThanCount(count);
return FastList.newList(this.asLazy().take(count));
}
private boolean checkZeroCount(int count)
{
return count == 0;
}
private void checkSizeLessThanCount(int count)
{
if (this.delegate.size() < count)
{
throw new IllegalArgumentException("Count must be less than size: Count = " + count + " Size = " + this.delegate.size());
}
}
private void checkSizeLessThanOrEqualToIndex(int index)
{
if (this.delegate.size() <= index)
{
throw new IllegalArgumentException("Count must be less than size: Count = " + index + " Size = " + this.delegate.size());
}
}
private void checkNegativeCount(int count)
{
if (count < 0)
{
throw new IllegalArgumentException("Count must be positive but was " + count);
}
}
public T peekAt(int index)
{
this.checkNegativeCount(index);
this.checkEmptyStack();
this.checkSizeLessThanOrEqualToIndex(index);
return this.delegate.get(this.delegate.size() - 1 - index);
}
public T getFirst()
{
return this.peek();
}
public T getLast()
{
throw new UnsupportedOperationException("Cannot call getLast() on " + this.getClass().getSimpleName());
}
public boolean contains(Object object)
{
return this.delegate.asReversed().contains(object);
}
public boolean containsAllIterable(Iterable> source)
{
return this.delegate.asReversed().containsAllIterable(source);
}
public boolean containsAll(Collection> source)
{
return this.delegate.asReversed().containsAll(source);
}
public boolean containsAllArguments(Object... elements)
{
return this.delegate.asReversed().containsAllArguments(elements);
}
public MutableStack toStack()
{
return ArrayStack.newStackFromTopToBottom(this);
}
public ImmutableStack select(Predicate super T> predicate)
{
return ImmutableArrayStack.newStackFromTopToBottom(this.delegate.asReversed().select(predicate).toList());
}
public ImmutableStack selectWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.select(Predicates.bind(predicate, parameter));
}
public > R select(Predicate super T> predicate, R target)
{
return this.delegate.asReversed().select(predicate, target);
}
public > R selectWith(Predicate2 super T, ? super P> predicate, P parameter, R targetCollection)
{
return this.delegate.asReversed().selectWith(predicate, parameter, targetCollection);
}
public ImmutableStack reject(Predicate super T> predicate)
{
return ImmutableArrayStack.newStackFromTopToBottom(this.delegate.asReversed().reject(predicate).toList());
}
public > R reject(Predicate super T> predicate, R target)
{
return this.delegate.asReversed().reject(predicate, target);
}
public ImmutableStack rejectWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.reject(Predicates.bind(predicate, parameter));
}
public > R rejectWith(Predicate2 super T, ? super P> predicate, P parameter, R targetCollection)
{
return this.delegate.asReversed().rejectWith(predicate, parameter, targetCollection);
}
public PartitionImmutableStack partition(Predicate super T> predicate)
{
PartitionArrayStack partitionMutableStack = new PartitionArrayStack();
this.delegate.asReversed().forEach(new PartitionArrayStack.PartitionProcedure(predicate, partitionMutableStack));
return partitionMutableStack.toImmutable();
}
public PartitionImmutableStack partitionWith(Predicate2 super T, ? super P> predicate, P parameter)
{
PartitionArrayStack partitionMutableStack = new PartitionArrayStack();
this.delegate.asReversed().forEach(new PartitionArrayStack.PartitionPredicate2Procedure(predicate, parameter, partitionMutableStack));
return partitionMutableStack.toImmutable();
}
public RichIterable selectInstancesOf(Class clazz)
{
return ImmutableArrayStack.newStackFromTopToBottom(this.delegate.asReversed().selectInstancesOf(clazz).toList());
}
public ImmutableStack collect(Function super T, ? extends V> function)
{
return ImmutableArrayStack.newStackFromTopToBottom(this.delegate.asReversed().collect(function));
}
public ImmutableBooleanStack collectBoolean(BooleanFunction super T> booleanFunction)
{
return BooleanArrayStack.newStackFromTopToBottom(this.delegate.asReversed().collectBoolean(booleanFunction)).toImmutable();
}
public R collectBoolean(BooleanFunction super T> booleanFunction, R target)
{
return this.delegate.asReversed().collectBoolean(booleanFunction, target);
}
public ImmutableByteStack collectByte(ByteFunction super T> byteFunction)
{
return ByteArrayStack.newStackFromTopToBottom(this.delegate.asReversed().collectByte(byteFunction)).toImmutable();
}
public R collectByte(ByteFunction super T> byteFunction, R target)
{
return this.delegate.asReversed().collectByte(byteFunction, target);
}
public ImmutableCharStack collectChar(CharFunction super T> charFunction)
{
return CharArrayStack.newStackFromTopToBottom(this.delegate.asReversed().collectChar(charFunction)).toImmutable();
}
public R collectChar(CharFunction super T> charFunction, R target)
{
return this.delegate.asReversed().collectChar(charFunction, target);
}
public ImmutableDoubleStack collectDouble(DoubleFunction super T> doubleFunction)
{
return DoubleArrayStack.newStackFromTopToBottom(this.delegate.asReversed().collectDouble(doubleFunction)).toImmutable();
}
public R collectDouble(DoubleFunction super T> doubleFunction, R target)
{
return this.delegate.asReversed().collectDouble(doubleFunction, target);
}
public ImmutableFloatStack collectFloat(FloatFunction super T> floatFunction)
{
return FloatArrayStack.newStackFromTopToBottom(this.delegate.asReversed().collectFloat(floatFunction)).toImmutable();
}
public R collectFloat(FloatFunction super T> floatFunction, R target)
{
return this.delegate.asReversed().collectFloat(floatFunction, target);
}
public ImmutableIntStack collectInt(IntFunction super T> intFunction)
{
return IntArrayStack.newStackFromTopToBottom(this.delegate.asReversed().collectInt(intFunction)).toImmutable();
}
public R collectInt(IntFunction super T> intFunction, R target)
{
return this.delegate.asReversed().collectInt(intFunction, target);
}
public ImmutableLongStack collectLong(LongFunction super T> longFunction)
{
return LongArrayStack.newStackFromTopToBottom(this.delegate.asReversed().collectLong(longFunction)).toImmutable();
}
public R collectLong(LongFunction super T> longFunction, R target)
{
return this.delegate.asReversed().collectLong(longFunction, target);
}
public ImmutableShortStack collectShort(ShortFunction super T> shortFunction)
{
return ShortArrayStack.newStackFromTopToBottom(this.delegate.asReversed().collectShort(shortFunction)).toImmutable();
}
public R collectShort(ShortFunction super T> shortFunction, R target)
{
return this.delegate.asReversed().collectShort(shortFunction, target);
}
public > R collect(Function super T, ? extends V> function, R target)
{
return this.delegate.asReversed().collect(function, target);
}
public ImmutableStack collectWith(Function2 super T, ? super P, ? extends V> function, P parameter)
{
return ImmutableArrayStack.newStackFromTopToBottom(this.delegate.asReversed().collectWith(function, parameter).toList());
}
public > R collectWith(Function2 super T, ? super P, ? extends V> function, P parameter, R targetCollection)
{
return this.delegate.asReversed().collectWith(function, parameter, targetCollection);
}
public ImmutableStack collectIf(Predicate super T> predicate, Function super T, ? extends V> function)
{
return ImmutableArrayStack.newStackFromTopToBottom(this.delegate.asReversed().collectIf(predicate, function).toList());
}
public > R collectIf(Predicate super T> predicate, Function super T, ? extends V> function, R target)
{
return this.delegate.asReversed().collectIf(predicate, function, target);
}
public ImmutableStack flatCollect(Function super T, ? extends Iterable> function)
{
return ImmutableArrayStack.newStackFromTopToBottom(this.delegate.asReversed().flatCollect(function).toList());
}
public > R flatCollect(Function super T, ? extends Iterable> function, R target)
{
return this.delegate.asReversed().flatCollect(function, target);
}
public T detect(Predicate super T> predicate)
{
return this.delegate.asReversed().detect(predicate);
}
public T detectWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.delegate.asReversed().detectWith(predicate, parameter);
}
public T detectIfNone(Predicate super T> predicate, Function0 extends T> function)
{
return this.delegate.asReversed().detectIfNone(predicate, function);
}
public
T detectWithIfNone(Predicate2 super T, ? super P> predicate, P parameter, Function0 extends T> function)
{
return this.delegate.asReversed().detectWithIfNone(predicate, parameter, function);
}
public int count(Predicate super T> predicate)
{
return this.delegate.asReversed().count(predicate);
}
public
int countWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.delegate.asReversed().countWith(predicate, parameter);
}
public boolean anySatisfy(Predicate super T> predicate)
{
return this.delegate.asReversed().anySatisfy(predicate);
}
public
boolean anySatisfyWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.delegate.asReversed().anySatisfyWith(predicate, parameter);
}
public boolean allSatisfy(Predicate super T> predicate)
{
return this.delegate.asReversed().allSatisfy(predicate);
}
public
boolean allSatisfyWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.delegate.asReversed().allSatisfyWith(predicate, parameter);
}
public boolean noneSatisfy(Predicate super T> predicate)
{
return this.delegate.asReversed().noneSatisfy(predicate);
}
public
boolean noneSatisfyWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.delegate.asReversed().noneSatisfyWith(predicate, parameter);
}
public IV injectInto(IV injectedValue, Function2 super IV, ? super T, ? extends IV> function)
{
return this.delegate.asReversed().injectInto(injectedValue, function);
}
public int injectInto(int injectedValue, IntObjectToIntFunction super T> intObjectToIntFunction)
{
return this.delegate.asReversed().injectInto(injectedValue, intObjectToIntFunction);
}
public long injectInto(long injectedValue, LongObjectToLongFunction super T> longObjectToLongFunction)
{
return this.delegate.asReversed().injectInto(injectedValue, longObjectToLongFunction);
}
public double injectInto(double injectedValue, DoubleObjectToDoubleFunction super T> doubleObjectToDoubleFunction)
{
return this.delegate.asReversed().injectInto(injectedValue, doubleObjectToDoubleFunction);
}
public float injectInto(float injectedValue, FloatObjectToFloatFunction super T> floatObjectToFloatFunction)
{
return this.delegate.asReversed().injectInto(injectedValue, floatObjectToFloatFunction);
}
public MutableList toList()
{
return this.delegate.asReversed().toList();
}
public MutableList toSortedList()
{
return this.delegate.asReversed().toSortedList();
}
public MutableList toSortedList(Comparator super T> comparator)
{
return this.delegate.asReversed().toSortedList(comparator);
}
public > MutableList toSortedListBy(Function super T, ? extends V> function)
{
return this.delegate.asReversed().toSortedListBy(function);
}
public MutableSet toSet()
{
return this.delegate.asReversed().toSet();
}
public MutableSortedSet toSortedSet()
{
return this.delegate.asReversed().toSortedSet();
}
public MutableSortedSet toSortedSet(Comparator super T> comparator)
{
return this.delegate.asReversed().toSortedSet(comparator);
}
public > MutableSortedSet toSortedSetBy(Function super T, ? extends V> function)
{
return this.delegate.asReversed().toSortedSetBy(function);
}
public MutableBag toBag()
{
return this.delegate.asReversed().toBag();
}
public MutableSortedBag toSortedBag()
{
return this.delegate.asReversed().toSortedBag();
}
public MutableSortedBag toSortedBag(Comparator super T> comparator)
{
return this.delegate.asReversed().toSortedBag(comparator);
}
public > MutableSortedBag toSortedBagBy(Function super T, ? extends V> function)
{
return this.delegate.asReversed().toSortedBagBy(function);
}
public MutableMap toMap(Function super T, ? extends NK> keyFunction, Function super T, ? extends NV> valueFunction)
{
return this.delegate.asReversed().toMap(keyFunction, valueFunction);
}
public MutableSortedMap toSortedMap(Function super T, ? extends NK> keyFunction, Function super T, ? extends NV> valueFunction)
{
return this.delegate.asReversed().toSortedMap(keyFunction, valueFunction);
}
public MutableSortedMap toSortedMap(Comparator super NK> comparator, Function super T, ? extends NK> keyFunction, Function super T, ? extends NV> valueFunction)
{
return this.delegate.asReversed().toSortedMap(comparator, keyFunction, valueFunction);
}
public LazyIterable asLazy()
{
return LazyIterate.adapt(this);
}
public Object[] toArray()
{
return this.delegate.asReversed().toArray();
}
public T[] toArray(T[] a)
{
return this.delegate.asReversed().toArray(a);
}
public T min(Comparator super T> comparator)
{
return this.delegate.asReversed().min(comparator);
}
public T max(Comparator super T> comparator)
{
return this.delegate.asReversed().max(comparator);
}
public T min()
{
return this.delegate.asReversed().min();
}
public T max()
{
return this.delegate.asReversed().max();
}
public > T minBy(Function super T, ? extends V> function)
{
return this.delegate.asReversed().toList().minBy(function);
}
public > T maxBy(Function super T, ? extends V> function)
{
return this.delegate.asReversed().maxBy(function);
}
public long sumOfInt(IntFunction super T> intFunction)
{
return this.delegate.asReversed().sumOfInt(intFunction);
}
public double sumOfFloat(FloatFunction super T> floatFunction)
{
return this.delegate.asReversed().sumOfFloat(floatFunction);
}
public long sumOfLong(LongFunction super T> longFunction)
{
return this.delegate.asReversed().sumOfLong(longFunction);
}
public double sumOfDouble(DoubleFunction super T> doubleFunction)
{
return this.delegate.asReversed().sumOfDouble(doubleFunction);
}
public ObjectLongMap sumByInt(Function groupBy, IntFunction super T> function)
{
return this.delegate.asReversed().sumByInt(groupBy, function);
}
public ObjectDoubleMap sumByFloat(Function groupBy, FloatFunction super T> function)
{
return this.delegate.asReversed().sumByFloat(groupBy, function);
}
public ObjectLongMap sumByLong(Function groupBy, LongFunction super T> function)
{
return this.delegate.asReversed().sumByLong(groupBy, function);
}
public ObjectDoubleMap sumByDouble(Function groupBy, DoubleFunction super T> function)
{
return this.delegate.asReversed().sumByDouble(groupBy, function);
}
public String makeString()
{
return this.delegate.asReversed().makeString();
}
public String makeString(String separator)
{
return this.delegate.asReversed().makeString(separator);
}
public String makeString(String start, String separator, String end)
{
return this.delegate.asReversed().makeString(start, separator, end);
}
public void appendString(Appendable appendable)
{
this.delegate.asReversed().appendString(appendable);
}
public void appendString(Appendable appendable, String separator)
{
this.delegate.asReversed().appendString(appendable, separator);
}
public void appendString(Appendable appendable, String start, String separator, String end)
{
this.delegate.asReversed().appendString(appendable, start, separator, end);
}
public ImmutableListMultimap groupBy(Function super T, ? extends V> function)
{
return this.groupBy(function, FastListMultimap.newMultimap()).toImmutable();
}
public > R groupBy(Function super T, ? extends V> function, R target)
{
return this.delegate.asReversed().groupBy(function, target);
}
public ImmutableListMultimap groupByEach(Function super T, ? extends Iterable> function)
{
return this.groupByEach(function, FastListMultimap.newMultimap()).toImmutable();
}
public > R groupByEach(Function super T, ? extends Iterable> function, R target)
{
return this.delegate.asReversed().groupByEach(function, target);
}
public ImmutableMap groupByUniqueKey(Function super T, ? extends V> function)
{
return this.groupByUniqueKey(function, UnifiedMap.newMap()).toImmutable();
}
public > R groupByUniqueKey(Function super T, ? extends V> function, R target)
{
return this.delegate.asReversed().groupByUniqueKey(function, target);
}
public ImmutableStack> zip(Iterable that)
{
return ImmutableArrayStack.newStackFromTopToBottom(this.delegate.asReversed().zip(that).toList());
}
public >> R zip(Iterable that, R target)
{
return this.delegate.asReversed().zip(that, target);
}
public ImmutableStack> zipWithIndex()
{
int maxIndex = this.delegate.size() - 1;
Interval indicies = Interval.fromTo(0, maxIndex);
return ImmutableArrayStack.newStackFromTopToBottom(this.delegate.asReversed().zip(indicies).toList());
}
public >> R zipWithIndex(R target)
{
return this.delegate.asReversed().zipWithIndex(target);
}
public ImmutableStack toImmutable()
{
return this;
}
public RichIterable> chunk(int size)
{
return this.delegate.asReversed().chunk(size);
}
public MapIterable aggregateInPlaceBy(Function super T, ? extends K> groupBy, Function0 extends V> zeroValueFactory, Procedure2 super V, ? super T> mutatingAggregator)
{
MutableMap map = UnifiedMap.newMap();
this.forEach(new MutatingAggregationProcedure(map, groupBy, zeroValueFactory, mutatingAggregator));
return map;
}
public MapIterable aggregateBy(Function super T, ? extends K> groupBy, Function0 extends V> zeroValueFactory, Function2 super V, ? super T, ? extends V> nonMutatingAggregator)
{
MutableMap map = UnifiedMap.newMap();
this.forEach(new NonMutatingAggregationProcedure(map, groupBy, zeroValueFactory, nonMutatingAggregator));
return map;
}
public int size()
{
return this.delegate.size();
}
public boolean isEmpty()
{
return this.delegate.isEmpty();
}
public boolean notEmpty()
{
return this.delegate.notEmpty();
}
public ImmutableStack tap(Procedure super T> procedure)
{
this.forEach(procedure);
return this;
}
public void forEach(Procedure super T> procedure)
{
this.each(procedure);
}
public void each(Procedure super T> procedure)
{
this.delegate.reverseForEach(procedure);
}
public void forEachWithIndex(ObjectIntProcedure super T> objectIntProcedure)
{
this.delegate.asReversed().forEachWithIndex(objectIntProcedure);
}
public void forEachWith(Procedure2 super T, ? super P> procedure, P parameter)
{
this.delegate.asReversed().forEachWith(procedure, parameter);
}
public Iterator iterator()
{
return this.delegate.asReversed().iterator();
}
@Override
public boolean equals(Object o)
{
if (this == o)
{
return true;
}
if (!(o instanceof StackIterable>))
{
return false;
}
StackIterable> that = (StackIterable>) o;
if (that instanceof ImmutableArrayStack>)
{
return this.delegate.equals(((ImmutableArrayStack>) that).delegate);
}
Iterator thisIterator = this.iterator();
Iterator> thatIterator = that.iterator();
while (thisIterator.hasNext() && thatIterator.hasNext())
{
if (!Comparators.nullSafeEquals(thisIterator.next(), thatIterator.next()))
{
return false;
}
}
return !thisIterator.hasNext() && !thatIterator.hasNext();
}
@Override
public String toString()
{
return this.delegate.asReversed().makeString("[", ", ", "]");
}
@Override
public int hashCode()
{
int hashCode = 1;
for (T each : this)
{
hashCode = 31 * hashCode + (each == null ? 0 : each.hashCode());
}
return hashCode;
}
private Object writeReplace()
{
return new ImmutableStackSerializationProxy(this);
}
private static class ImmutableStackSerializationProxy implements Externalizable
{
private static final long serialVersionUID = 1L;
private StackIterable stack;
@SuppressWarnings("UnusedDeclaration")
public ImmutableStackSerializationProxy()
{
// Empty constructor for Externalizable class
}
protected ImmutableStackSerializationProxy(StackIterable stack)
{
this.stack = stack;
}
public void writeExternal(final ObjectOutput out) throws IOException
{
out.writeInt(this.stack.size());
try
{
this.stack.forEach(new CheckedProcedure()
{
public void safeValue(T object) throws IOException
{
out.writeObject(object);
}
});
}
catch (RuntimeException e)
{
if (e.getCause() instanceof IOException)
{
throw (IOException) e.getCause();
}
throw e;
}
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
int size = in.readInt();
FastList deserializedDelegate = new FastList(size);
for (int i = 0; i < size; i++)
{
deserializedDelegate.add((T) in.readObject());
}
this.stack = ImmutableArrayStack.newStackFromTopToBottom(deserializedDelegate);
}
protected Object readResolve()
{
return this.stack;
}
}
}