com.gs.collections.impl.collection.mutable.AbstractUnmodifiableMutableCollection Maven / Gradle / Ivy
Show all versions of gs-collections Show documentation
/*
* Copyright 2015 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.collection.mutable;
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.Function3;
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.ImmutableCollection;
import com.gs.collections.api.collection.MutableCollection;
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.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.partition.PartitionMutableCollection;
import com.gs.collections.api.set.MutableSet;
import com.gs.collections.api.set.sorted.MutableSortedSet;
import com.gs.collections.api.tuple.Pair;
import com.gs.collections.api.tuple.Twin;
import com.gs.collections.impl.UnmodifiableIteratorAdapter;
import com.gs.collections.impl.block.factory.Comparators;
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;
import com.gs.collections.impl.utility.LazyIterate;
public class AbstractUnmodifiableMutableCollection implements MutableCollection
{
private final MutableCollection extends T> collection;
protected AbstractUnmodifiableMutableCollection(MutableCollection extends T> mutableCollection)
{
if (mutableCollection == null)
{
throw new NullPointerException("cannot create a UnmodifiableMutableCollection for null");
}
this.collection = mutableCollection;
}
public int size()
{
return this.collection.size();
}
public boolean isEmpty()
{
return this.collection.isEmpty();
}
public boolean contains(Object o)
{
return this.collection.contains(o);
}
public Iterator iterator()
{
return new UnmodifiableIteratorAdapter(this.collection.iterator());
}
public Object[] toArray()
{
return this.collection.toArray();
}
public S[] toArray(S[] a)
{
return this.collection.toArray(a);
}
public boolean add(T o)
{
throw new UnsupportedOperationException("Cannot call add() on " + this.getClass().getSimpleName());
}
public boolean remove(Object o)
{
throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName());
}
public boolean containsAll(Collection> c)
{
return this.collection.containsAll(c);
}
public boolean addAll(Collection extends T> c)
{
throw new UnsupportedOperationException("Cannot call addAll() on " + this.getClass().getSimpleName());
}
public boolean retainAll(Collection> c)
{
throw new UnsupportedOperationException("Cannot call retainAll() on " + this.getClass().getSimpleName());
}
public boolean removeAll(Collection> c)
{
throw new UnsupportedOperationException("Cannot call removeAll() on " + this.getClass().getSimpleName());
}
public void clear()
{
throw new UnsupportedOperationException("Cannot call clear() on " + this.getClass().getSimpleName());
}
protected MutableCollection getMutableCollection()
{
return (MutableCollection) this.collection;
}
public boolean addAllIterable(Iterable extends T> iterable)
{
throw new UnsupportedOperationException("Cannot call addAllIterable() on " + this.getClass().getSimpleName());
}
public boolean removeAllIterable(Iterable> iterable)
{
throw new UnsupportedOperationException("Cannot call removeAllIterable() on " + this.getClass().getSimpleName());
}
public boolean retainAllIterable(Iterable> iterable)
{
throw new UnsupportedOperationException("Cannot call retainAllIterable() on " + this.getClass().getSimpleName());
}
public MutableCollection asUnmodifiable()
{
return this;
}
public MutableCollection asSynchronized()
{
return SynchronizedMutableCollection.of(this);
}
public ImmutableCollection toImmutable()
{
return this.getMutableCollection().toImmutable();
}
public LazyIterable asLazy()
{
return LazyIterate.adapt(this);
}
public MutableCollection 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.getMutableCollection().forEach(procedure);
}
public void forEachWithIndex(ObjectIntProcedure super T> objectIntProcedure)
{
this.getMutableCollection().forEachWithIndex(objectIntProcedure);
}
public void forEachWith(Procedure2 super T, ? super P> procedure, P parameter)
{
this.getMutableCollection().forEachWith(procedure, parameter);
}
public boolean containsAllIterable(Iterable> source)
{
return this.getMutableCollection().containsAllIterable(source);
}
public boolean containsAllArguments(Object... elements)
{
return this.getMutableCollection().containsAllArguments(elements);
}
public boolean notEmpty()
{
return this.getMutableCollection().notEmpty();
}
public MutableCollection newEmpty()
{
return this.getMutableCollection().newEmpty();
}
public T getFirst()
{
return this.getMutableCollection().getFirst();
}
public T getLast()
{
return this.getMutableCollection().getLast();
}
public MutableCollection select(Predicate super T> predicate)
{
return this.getMutableCollection().select(predicate);
}
public > R select(Predicate super T> predicate, R target)
{
return this.getMutableCollection().select(predicate, target);
}
public MutableCollection selectWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.getMutableCollection().selectWith(predicate, parameter);
}
public > R selectWith(
Predicate2 super T, ? super P> predicate,
P parameter,
R targetCollection)
{
return this.getMutableCollection().selectWith(predicate, parameter, targetCollection);
}
public MutableCollection reject(Predicate super T> predicate)
{
return this.getMutableCollection().reject(predicate);
}
public > R reject(Predicate super T> predicate, R target)
{
return this.getMutableCollection().reject(predicate, target);
}
public MutableCollection rejectWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.getMutableCollection().rejectWith(predicate, parameter);
}
public > R rejectWith(
Predicate2 super T, ? super P> predicate,
P parameter,
R targetCollection)
{
return this.getMutableCollection().rejectWith(predicate, parameter, targetCollection);
}
public
Twin> selectAndRejectWith(
Predicate2 super T, ? super P> predicate,
P parameter)
{
return this.getMutableCollection().selectAndRejectWith(predicate, parameter);
}
public PartitionMutableCollection partition(Predicate super T> predicate)
{
return this.getMutableCollection().partition(predicate);
}
public PartitionMutableCollection partitionWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.getMutableCollection().partitionWith(predicate, parameter);
}
public MutableCollection selectInstancesOf(Class clazz)
{
return this.getMutableCollection().selectInstancesOf(clazz);
}
public boolean removeIf(Predicate super T> predicate)
{
throw new UnsupportedOperationException("Cannot call removeIf() on " + this.getClass().getSimpleName());
}
public boolean removeIfWith(Predicate2 super T, ? super P> predicate, P parameter)
{
throw new UnsupportedOperationException("Cannot call removeIfWith() on " + this.getClass().getSimpleName());
}
public MutableCollection collect(Function super T, ? extends V> function)
{
return this.getMutableCollection().collect(function);
}
public MutableBooleanCollection collectBoolean(BooleanFunction super T> booleanFunction)
{
return this.getMutableCollection().collectBoolean(booleanFunction);
}
public R collectBoolean(BooleanFunction super T> booleanFunction, R target)
{
return this.getMutableCollection().collectBoolean(booleanFunction, target);
}
public MutableByteCollection collectByte(ByteFunction super T> byteFunction)
{
return this.getMutableCollection().collectByte(byteFunction);
}
public R collectByte(ByteFunction super T> byteFunction, R target)
{
return this.getMutableCollection().collectByte(byteFunction, target);
}
public MutableCharCollection collectChar(CharFunction super T> charFunction)
{
return this.getMutableCollection().collectChar(charFunction);
}
public R collectChar(CharFunction super T> charFunction, R target)
{
return this.getMutableCollection().collectChar(charFunction, target);
}
public MutableDoubleCollection collectDouble(DoubleFunction super T> doubleFunction)
{
return this.getMutableCollection().collectDouble(doubleFunction);
}
public R collectDouble(DoubleFunction super T> doubleFunction, R target)
{
return this.getMutableCollection().collectDouble(doubleFunction, target);
}
public MutableFloatCollection collectFloat(FloatFunction super T> floatFunction)
{
return this.getMutableCollection().collectFloat(floatFunction);
}
public R collectFloat(FloatFunction super T> floatFunction, R target)
{
return this.getMutableCollection().collectFloat(floatFunction, target);
}
public MutableIntCollection collectInt(IntFunction super T> intFunction)
{
return this.getMutableCollection().collectInt(intFunction);
}
public R collectInt(IntFunction super T> intFunction, R target)
{
return this.getMutableCollection().collectInt(intFunction, target);
}
public MutableLongCollection collectLong(LongFunction super T> longFunction)
{
return this.getMutableCollection().collectLong(longFunction);
}
public R collectLong(LongFunction super T> longFunction, R target)
{
return this.getMutableCollection().collectLong(longFunction, target);
}
public MutableShortCollection collectShort(ShortFunction super T> shortFunction)
{
return this.getMutableCollection().collectShort(shortFunction);
}
public R collectShort(ShortFunction super T> shortFunction, R target)
{
return this.getMutableCollection().collectShort(shortFunction, target);
}
public > R collect(Function super T, ? extends V> function, R target)
{
return this.getMutableCollection().collect(function, target);
}
public MutableCollection flatCollect(Function super T, ? extends Iterable> function)
{
return this.getMutableCollection().flatCollect(function);
}
public > R flatCollect(Function super T, ? extends Iterable> function, R target)
{
return this.getMutableCollection().flatCollect(function, target);
}
public