
org.eclipse.collections.impl.collection.mutable.AbstractUnmodifiableMutableCollection Maven / Gradle / Ivy
/*
* Copyright (c) 2022 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.impl.collection.mutable;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
import org.eclipse.collections.api.BooleanIterable;
import org.eclipse.collections.api.ByteIterable;
import org.eclipse.collections.api.CharIterable;
import org.eclipse.collections.api.DoubleIterable;
import org.eclipse.collections.api.FloatIterable;
import org.eclipse.collections.api.IntIterable;
import org.eclipse.collections.api.LazyIterable;
import org.eclipse.collections.api.LongIterable;
import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.ShortIterable;
import org.eclipse.collections.api.bag.MutableBag;
import org.eclipse.collections.api.bag.sorted.MutableSortedBag;
import org.eclipse.collections.api.bimap.MutableBiMap;
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.Function3;
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.DoubleObjectToDoubleFunction;
import org.eclipse.collections.api.block.function.primitive.FloatFunction;
import org.eclipse.collections.api.block.function.primitive.FloatObjectToFloatFunction;
import org.eclipse.collections.api.block.function.primitive.IntFunction;
import org.eclipse.collections.api.block.function.primitive.IntObjectToIntFunction;
import org.eclipse.collections.api.block.function.primitive.LongFunction;
import org.eclipse.collections.api.block.function.primitive.LongObjectToLongFunction;
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.block.procedure.primitive.ObjectIntProcedure;
import org.eclipse.collections.api.collection.ImmutableCollection;
import org.eclipse.collections.api.collection.MutableCollection;
import org.eclipse.collections.api.collection.primitive.MutableBooleanCollection;
import org.eclipse.collections.api.collection.primitive.MutableByteCollection;
import org.eclipse.collections.api.collection.primitive.MutableCharCollection;
import org.eclipse.collections.api.collection.primitive.MutableDoubleCollection;
import org.eclipse.collections.api.collection.primitive.MutableFloatCollection;
import org.eclipse.collections.api.collection.primitive.MutableIntCollection;
import org.eclipse.collections.api.collection.primitive.MutableLongCollection;
import org.eclipse.collections.api.collection.primitive.MutableShortCollection;
import org.eclipse.collections.api.factory.primitive.ObjectDoubleMaps;
import org.eclipse.collections.api.factory.primitive.ObjectLongMaps;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.map.MutableMapIterable;
import org.eclipse.collections.api.map.primitive.MutableObjectDoubleMap;
import org.eclipse.collections.api.map.primitive.MutableObjectLongMap;
import org.eclipse.collections.api.map.sorted.MutableSortedMap;
import org.eclipse.collections.api.multimap.MutableMultimap;
import org.eclipse.collections.api.partition.PartitionMutableCollection;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.api.set.sorted.MutableSortedSet;
import org.eclipse.collections.api.tuple.Pair;
import org.eclipse.collections.api.tuple.Twin;
import org.eclipse.collections.impl.UnmodifiableIteratorAdapter;
import org.eclipse.collections.impl.block.factory.PrimitiveFunctions;
import org.eclipse.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;
}
@Override
public int size()
{
return this.collection.size();
}
@Override
public boolean isEmpty()
{
return this.collection.isEmpty();
}
@Override
public boolean contains(Object o)
{
return this.collection.contains(o);
}
@Override
public Iterator iterator()
{
return new UnmodifiableIteratorAdapter<>(this.collection.iterator());
}
@Override
public Object[] toArray()
{
return this.collection.toArray();
}
@Override
public S[] toArray(S[] a)
{
return this.collection.toArray(a);
}
@Override
public boolean add(T o)
{
throw new UnsupportedOperationException("Cannot call add() on " + this.getClass().getSimpleName());
}
@Override
public boolean remove(Object o)
{
throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName());
}
@Override
public boolean containsAll(Collection> c)
{
return this.collection.containsAll(c);
}
@Override
public boolean addAll(Collection extends T> c)
{
throw new UnsupportedOperationException("Cannot call addAll() on " + this.getClass().getSimpleName());
}
@Override
public boolean retainAll(Collection> c)
{
throw new UnsupportedOperationException("Cannot call retainAll() on " + this.getClass().getSimpleName());
}
@Override
public boolean removeAll(Collection> c)
{
throw new UnsupportedOperationException("Cannot call removeAll() on " + this.getClass().getSimpleName());
}
@Override
public void clear()
{
throw new UnsupportedOperationException("Cannot call clear() on " + this.getClass().getSimpleName());
}
protected MutableCollection getMutableCollection()
{
return (MutableCollection) this.collection;
}
@Override
public boolean addAllIterable(Iterable extends T> iterable)
{
throw new UnsupportedOperationException("Cannot call addAllIterable() on " + this.getClass().getSimpleName());
}
@Override
public boolean removeAllIterable(Iterable> iterable)
{
throw new UnsupportedOperationException("Cannot call removeAllIterable() on " + this.getClass().getSimpleName());
}
@Override
public boolean retainAllIterable(Iterable> iterable)
{
throw new UnsupportedOperationException("Cannot call retainAllIterable() on " + this.getClass().getSimpleName());
}
@Override
public MutableCollection asUnmodifiable()
{
return this;
}
@Override
public MutableCollection asSynchronized()
{
return SynchronizedMutableCollection.of(this);
}
@Override
public ImmutableCollection toImmutable()
{
return this.getMutableCollection().toImmutable();
}
@Override
public LazyIterable asLazy()
{
return LazyIterate.adapt(this);
}
@Override
public MutableCollection tap(Procedure super T> procedure)
{
this.forEach(procedure);
return this;
}
@Override
public void each(Procedure super T> procedure)
{
this.getMutableCollection().forEach(procedure);
}
@Override
public void forEachWithIndex(ObjectIntProcedure super T> objectIntProcedure)
{
this.getMutableCollection().forEachWithIndex(objectIntProcedure);
}
@Override
public void forEachWith(Procedure2 super T, ? super P> procedure, P parameter)
{
this.getMutableCollection().forEachWith(procedure, parameter);
}
@Override
public boolean containsAny(Collection> source)
{
return this.getMutableCollection().containsAny(source);
}
@Override
public boolean containsNone(Collection> source)
{
return this.getMutableCollection().containsNone(source);
}
@Override
public boolean containsAnyIterable(Iterable> source)
{
return this.getMutableCollection().containsAnyIterable(source);
}
@Override
public boolean containsNoneIterable(Iterable> source)
{
return this.getMutableCollection().containsNoneIterable(source);
}
@Override
public boolean containsAllIterable(Iterable> source)
{
return this.getMutableCollection().containsAllIterable(source);
}
@Override
public boolean containsAllArguments(Object... elements)
{
return this.getMutableCollection().containsAllArguments(elements);
}
@Override
public boolean notEmpty()
{
return this.getMutableCollection().notEmpty();
}
@Override
public MutableCollection newEmpty()
{
return this.getMutableCollection().newEmpty();
}
@Override
public T getFirst()
{
return this.getMutableCollection().getFirst();
}
@Override
public T getLast()
{
return this.getMutableCollection().getLast();
}
@Override
public T getOnly()
{
return this.getMutableCollection().getOnly();
}
@Override
public MutableCollection select(Predicate super T> predicate)
{
return this.getMutableCollection().select(predicate);
}
@Override
public > R select(Predicate super T> predicate, R target)
{
return this.getMutableCollection().select(predicate, target);
}
@Override
public MutableCollection selectWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.getMutableCollection().selectWith(predicate, parameter);
}
@Override
public > R selectWith(
Predicate2 super T, ? super P> predicate,
P parameter,
R targetCollection)
{
return this.getMutableCollection().selectWith(predicate, parameter, targetCollection);
}
@Override
public MutableCollection reject(Predicate super T> predicate)
{
return this.getMutableCollection().reject(predicate);
}
@Override
public > R reject(Predicate super T> predicate, R target)
{
return this.getMutableCollection().reject(predicate, target);
}
@Override
public MutableCollection rejectWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.getMutableCollection().rejectWith(predicate, parameter);
}
@Override
public > R rejectWith(
Predicate2 super T, ? super P> predicate,
P parameter,
R targetCollection)
{
return this.getMutableCollection().rejectWith(predicate, parameter, targetCollection);
}
@Override
public
Twin> selectAndRejectWith(
Predicate2 super T, ? super P> predicate,
P parameter)
{
return this.getMutableCollection().selectAndRejectWith(predicate, parameter);
}
@Override
public PartitionMutableCollection partition(Predicate super T> predicate)
{
return this.getMutableCollection().partition(predicate);
}
@Override
public PartitionMutableCollection partitionWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.getMutableCollection().partitionWith(predicate, parameter);
}
@Override
public MutableCollection selectInstancesOf(Class clazz)
{
return this.getMutableCollection().selectInstancesOf(clazz);
}
@Override
public boolean removeIf(Predicate super T> predicate)
{
throw new UnsupportedOperationException("Cannot call removeIf() on " + this.getClass().getSimpleName());
}
@Override
public boolean removeIfWith(Predicate2 super T, ? super P> predicate, P parameter)
{
throw new UnsupportedOperationException("Cannot call removeIfWith() on " + this.getClass().getSimpleName());
}
@Override
public MutableCollection collect(Function super T, ? extends V> function)
{
return this.getMutableCollection().collect(function);
}
@Override
public MutableBooleanCollection collectBoolean(BooleanFunction super T> booleanFunction)
{
return this.getMutableCollection().collectBoolean(booleanFunction);
}
@Override
public R collectBoolean(BooleanFunction super T> booleanFunction, R target)
{
return this.getMutableCollection().collectBoolean(booleanFunction, target);
}
@Override
public R flatCollectBoolean(
Function super T, ? extends BooleanIterable> function, R target)
{
return this.getMutableCollection().flatCollectBoolean(function, target);
}
@Override
public MutableByteCollection collectByte(ByteFunction super T> byteFunction)
{
return this.getMutableCollection().collectByte(byteFunction);
}
@Override
public R collectByte(ByteFunction super T> byteFunction, R target)
{
return this.getMutableCollection().collectByte(byteFunction, target);
}
@Override
public R flatCollectByte(
Function super T, ? extends ByteIterable> function, R target)
{
return this.getMutableCollection().flatCollectByte(function, target);
}
@Override
public MutableCharCollection collectChar(CharFunction super T> charFunction)
{
return this.getMutableCollection().collectChar(charFunction);
}
@Override
public R collectChar(CharFunction super T> charFunction, R target)
{
return this.getMutableCollection().collectChar(charFunction, target);
}
@Override
public R flatCollectChar(
Function super T, ? extends CharIterable> function, R target)
{
return this.getMutableCollection().flatCollectChar(function, target);
}
@Override
public MutableDoubleCollection collectDouble(DoubleFunction super T> doubleFunction)
{
return this.getMutableCollection().collectDouble(doubleFunction);
}
@Override
public R collectDouble(DoubleFunction super T> doubleFunction, R target)
{
return this.getMutableCollection().collectDouble(doubleFunction, target);
}
@Override
public R flatCollectDouble(
Function super T, ? extends DoubleIterable> function, R target)
{
return this.getMutableCollection().flatCollectDouble(function, target);
}
@Override
public MutableFloatCollection collectFloat(FloatFunction super T> floatFunction)
{
return this.getMutableCollection().collectFloat(floatFunction);
}
@Override
public R collectFloat(FloatFunction super T> floatFunction, R target)
{
return this.getMutableCollection().collectFloat(floatFunction, target);
}
@Override
public R flatCollectFloat(
Function super T, ? extends FloatIterable> function, R target)
{
return this.getMutableCollection().flatCollectFloat(function, target);
}
@Override
public MutableIntCollection collectInt(IntFunction super T> intFunction)
{
return this.getMutableCollection().collectInt(intFunction);
}
@Override
public R collectInt(IntFunction super T> intFunction, R target)
{
return this.getMutableCollection().collectInt(intFunction, target);
}
@Override
public R flatCollectInt(
Function super T, ? extends IntIterable> function, R target)
{
return this.getMutableCollection().flatCollectInt(function, target);
}
@Override
public MutableLongCollection collectLong(LongFunction super T> longFunction)
{
return this.getMutableCollection().collectLong(longFunction);
}
@Override
public R collectLong(LongFunction super T> longFunction, R target)
{
return this.getMutableCollection().collectLong(longFunction, target);
}
@Override
public R flatCollectLong(
Function super T, ? extends LongIterable> function, R target)
{
return this.getMutableCollection().flatCollectLong(function, target);
}
@Override
public MutableShortCollection collectShort(ShortFunction super T> shortFunction)
{
return this.getMutableCollection().collectShort(shortFunction);
}
@Override
public R collectShort(ShortFunction super T> shortFunction, R target)
{
return this.getMutableCollection().collectShort(shortFunction, target);
}
@Override
public R flatCollectShort(
Function super T, ? extends ShortIterable> function, R target)
{
return this.getMutableCollection().flatCollectShort(function, target);
}
@Override
public > R collect(Function super T, ? extends V> function, R target)
{
return this.getMutableCollection().collect(function, target);
}
@Override
public MutableCollection flatCollect(Function super T, ? extends Iterable> function)
{
return this.getMutableCollection().flatCollect(function);
}
@Override
public > R flatCollect(Function super T, ? extends Iterable> function, R target)
{
return this.getMutableCollection().flatCollect(function, target);
}
@Override
public