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

org.eclipse.collections.impl.collection.mutable.AbstractUnmodifiableMutableCollection Maven / Gradle / Ivy

There is a newer version: 11.1.0-r13
Show newest version
/*
 * 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 collection;

    protected AbstractUnmodifiableMutableCollection(MutableCollection 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 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 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 procedure)
    {
        this.forEach(procedure);
        return this;
    }

    @Override
    public void each(Procedure procedure)
    {
        this.getMutableCollection().forEach(procedure);
    }

    @Override
    public void forEachWithIndex(ObjectIntProcedure objectIntProcedure)
    {
        this.getMutableCollection().forEachWithIndex(objectIntProcedure);
    }

    @Override
    public 

void forEachWith(Procedure2 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 predicate) { return this.getMutableCollection().select(predicate); } @Override public > R select(Predicate predicate, R target) { return this.getMutableCollection().select(predicate, target); } @Override public

MutableCollection selectWith(Predicate2 predicate, P parameter) { return this.getMutableCollection().selectWith(predicate, parameter); } @Override public > R selectWith( Predicate2 predicate, P parameter, R targetCollection) { return this.getMutableCollection().selectWith(predicate, parameter, targetCollection); } @Override public MutableCollection reject(Predicate predicate) { return this.getMutableCollection().reject(predicate); } @Override public > R reject(Predicate predicate, R target) { return this.getMutableCollection().reject(predicate, target); } @Override public

MutableCollection rejectWith(Predicate2 predicate, P parameter) { return this.getMutableCollection().rejectWith(predicate, parameter); } @Override public > R rejectWith( Predicate2 predicate, P parameter, R targetCollection) { return this.getMutableCollection().rejectWith(predicate, parameter, targetCollection); } @Override public

Twin> selectAndRejectWith( Predicate2 predicate, P parameter) { return this.getMutableCollection().selectAndRejectWith(predicate, parameter); } @Override public PartitionMutableCollection partition(Predicate predicate) { return this.getMutableCollection().partition(predicate); } @Override public

PartitionMutableCollection partitionWith(Predicate2 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 predicate) { throw new UnsupportedOperationException("Cannot call removeIf() on " + this.getClass().getSimpleName()); } @Override public

boolean removeIfWith(Predicate2 predicate, P parameter) { throw new UnsupportedOperationException("Cannot call removeIfWith() on " + this.getClass().getSimpleName()); } @Override public MutableCollection collect(Function function) { return this.getMutableCollection().collect(function); } @Override public MutableBooleanCollection collectBoolean(BooleanFunction booleanFunction) { return this.getMutableCollection().collectBoolean(booleanFunction); } @Override public R collectBoolean(BooleanFunction booleanFunction, R target) { return this.getMutableCollection().collectBoolean(booleanFunction, target); } @Override public R flatCollectBoolean( Function function, R target) { return this.getMutableCollection().flatCollectBoolean(function, target); } @Override public MutableByteCollection collectByte(ByteFunction byteFunction) { return this.getMutableCollection().collectByte(byteFunction); } @Override public R collectByte(ByteFunction byteFunction, R target) { return this.getMutableCollection().collectByte(byteFunction, target); } @Override public R flatCollectByte( Function function, R target) { return this.getMutableCollection().flatCollectByte(function, target); } @Override public MutableCharCollection collectChar(CharFunction charFunction) { return this.getMutableCollection().collectChar(charFunction); } @Override public R collectChar(CharFunction charFunction, R target) { return this.getMutableCollection().collectChar(charFunction, target); } @Override public R flatCollectChar( Function function, R target) { return this.getMutableCollection().flatCollectChar(function, target); } @Override public MutableDoubleCollection collectDouble(DoubleFunction doubleFunction) { return this.getMutableCollection().collectDouble(doubleFunction); } @Override public R collectDouble(DoubleFunction doubleFunction, R target) { return this.getMutableCollection().collectDouble(doubleFunction, target); } @Override public R flatCollectDouble( Function function, R target) { return this.getMutableCollection().flatCollectDouble(function, target); } @Override public MutableFloatCollection collectFloat(FloatFunction floatFunction) { return this.getMutableCollection().collectFloat(floatFunction); } @Override public R collectFloat(FloatFunction floatFunction, R target) { return this.getMutableCollection().collectFloat(floatFunction, target); } @Override public R flatCollectFloat( Function function, R target) { return this.getMutableCollection().flatCollectFloat(function, target); } @Override public MutableIntCollection collectInt(IntFunction intFunction) { return this.getMutableCollection().collectInt(intFunction); } @Override public R collectInt(IntFunction intFunction, R target) { return this.getMutableCollection().collectInt(intFunction, target); } @Override public R flatCollectInt( Function function, R target) { return this.getMutableCollection().flatCollectInt(function, target); } @Override public MutableLongCollection collectLong(LongFunction longFunction) { return this.getMutableCollection().collectLong(longFunction); } @Override public R collectLong(LongFunction longFunction, R target) { return this.getMutableCollection().collectLong(longFunction, target); } @Override public R flatCollectLong( Function function, R target) { return this.getMutableCollection().flatCollectLong(function, target); } @Override public MutableShortCollection collectShort(ShortFunction shortFunction) { return this.getMutableCollection().collectShort(shortFunction); } @Override public R collectShort(ShortFunction shortFunction, R target) { return this.getMutableCollection().collectShort(shortFunction, target); } @Override public R flatCollectShort( Function function, R target) { return this.getMutableCollection().flatCollectShort(function, target); } @Override public > R collect(Function function, R target) { return this.getMutableCollection().collect(function, target); } @Override public MutableCollection flatCollect(Function> function) { return this.getMutableCollection().flatCollect(function); } @Override public > R flatCollect(Function> function, R target) { return this.getMutableCollection().flatCollect(function, target); } @Override public MutableCollection collectWith(Function2 function, P parameter) { return this.getMutableCollection().collectWith(function, parameter); } @Override public > R collectWith( Function2 function, P parameter, R targetCollection) { return this.getMutableCollection().collectWith(function, parameter, targetCollection); } @Override public MutableCollection collectIf( Predicate predicate, Function function) { return this.getMutableCollection().collectIf(predicate, function); } @Override public > R collectIf( Predicate predicate, Function function, R target) { return this.getMutableCollection().collectIf(predicate, function, target); } @Override public T detect(Predicate predicate) { return this.getMutableCollection().detect(predicate); } @Override public

T detectWith(Predicate2 predicate, P parameter) { return this.getMutableCollection().detectWith(predicate, parameter); } @Override public Optional detectOptional(Predicate predicate) { return this.getMutableCollection().detectOptional(predicate); } @Override public

Optional detectWithOptional(Predicate2 predicate, P parameter) { return this.getMutableCollection().detectWithOptional(predicate, parameter); } @Override public T detectIfNone(Predicate predicate, Function0 function) { return this.getMutableCollection().detectIfNone(predicate, function); } @Override public

T detectWithIfNone( Predicate2 predicate, P parameter, Function0 function) { return this.getMutableCollection().detectWithIfNone(predicate, parameter, function); } @Override public T min(Comparator comparator) { return this.getMutableCollection().min(comparator); } @Override public T max(Comparator comparator) { return this.getMutableCollection().max(comparator); } @Override public T min() { return this.getMutableCollection().min(); } @Override public T max() { return this.getMutableCollection().max(); } @Override public > T minBy(Function function) { return this.getMutableCollection().minBy(function); } @Override public > T maxBy(Function function) { return this.getMutableCollection().maxBy(function); } @Override public int count(Predicate predicate) { return this.getMutableCollection().count(predicate); } @Override public

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

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

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

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { return this.getMutableCollection().noneSatisfyWith(predicate, parameter); } @Override public IV injectInto(IV injectedValue, Function2 function) { return this.getMutableCollection().injectInto(injectedValue, function); } @Override public int injectInto(int injectedValue, IntObjectToIntFunction function) { return this.getMutableCollection().injectInto(injectedValue, function); } @Override public long injectInto(long injectedValue, LongObjectToLongFunction function) { return this.getMutableCollection().injectInto(injectedValue, function); } @Override public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { return this.getMutableCollection().injectInto(injectedValue, function); } @Override public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { return this.getMutableCollection().injectInto(injectedValue, function); } @Override public long sumOfInt(IntFunction function) { return this.getMutableCollection().sumOfInt(function); } @Override public double sumOfFloat(FloatFunction function) { return this.getMutableCollection().sumOfFloat(function); } @Override public long sumOfLong(LongFunction function) { return this.getMutableCollection().sumOfLong(function); } @Override public double sumOfDouble(DoubleFunction function) { return this.getMutableCollection().sumOfDouble(function); } @Override public MutableObjectLongMap sumByInt(Function groupBy, IntFunction function) { MutableObjectLongMap result = ObjectLongMaps.mutable.empty(); return this.injectInto(result, PrimitiveFunctions.sumByIntFunction(groupBy, function)); } @Override public MutableObjectDoubleMap sumByFloat(Function groupBy, FloatFunction function) { MutableObjectDoubleMap result = ObjectDoubleMaps.mutable.empty(); return this.injectInto(result, PrimitiveFunctions.sumByFloatFunction(groupBy, function)); } @Override public MutableObjectLongMap sumByLong(Function groupBy, LongFunction function) { MutableObjectLongMap result = ObjectLongMaps.mutable.empty(); return this.injectInto(result, PrimitiveFunctions.sumByLongFunction(groupBy, function)); } @Override public MutableObjectDoubleMap sumByDouble(Function groupBy, DoubleFunction function) { MutableObjectDoubleMap result = ObjectDoubleMaps.mutable.empty(); return this.injectInto(result, PrimitiveFunctions.sumByDoubleFunction(groupBy, function)); } @Override public IV injectIntoWith( IV injectValue, Function3 function, P parameter) { return this.getMutableCollection().injectIntoWith(injectValue, function, parameter); } @Override public > R into(R target) { return this.getMutableCollection().into(target); } @Override public MutableList toList() { return this.getMutableCollection().toList(); } @Override public MutableList toSortedList() { return this.getMutableCollection().toSortedList(); } @Override public MutableList toSortedList(Comparator comparator) { return this.getMutableCollection().toSortedList(comparator); } @Override public MutableSortedSet toSortedSet() { return this.getMutableCollection().toSortedSet(); } @Override public MutableSortedSet toSortedSet(Comparator comparator) { return this.getMutableCollection().toSortedSet(comparator); } @Override public MutableSet toSet() { return this.getMutableCollection().toSet(); } @Override public MutableBag toBag() { return this.getMutableCollection().toBag(); } @Override public MutableSortedBag toSortedBag() { return this.getMutableCollection().toSortedBag(); } @Override public MutableSortedBag toSortedBag(Comparator comparator) { return this.getMutableCollection().toSortedBag(comparator); } @Override public MutableMap toMap( Function keyFunction, Function valueFunction) { return this.getMutableCollection().toMap(keyFunction, valueFunction); } @Override public > R toMap( Function keyFunction, Function valueFunction, R target) { return this.getMutableCollection().toMap(keyFunction, valueFunction, target); } @Override public MutableSortedMap toSortedMap( Function keyFunction, Function valueFunction) { return this.getMutableCollection().toSortedMap(keyFunction, valueFunction); } @Override public MutableSortedMap toSortedMap( Comparator comparator, Function keyFunction, Function valueFunction) { return this.getMutableCollection().toSortedMap(comparator, keyFunction, valueFunction); } @Override public , NK, NV> MutableSortedMap toSortedMapBy( Function sortBy, Function keyFunction, Function valueFunction) { return this.getMutableCollection().toSortedMapBy(sortBy, keyFunction, valueFunction); } @Override public MutableBiMap toBiMap(Function keyFunction, Function valueFunction) { return this.getMutableCollection().toBiMap(keyFunction, valueFunction); } @Override public String toString() { return this.getMutableCollection().toString(); } @Override public String makeString() { return this.getMutableCollection().makeString(); } @Override public String makeString(String separator) { return this.getMutableCollection().makeString(separator); } @Override public String makeString(String start, String separator, String end) { return this.getMutableCollection().makeString(start, separator, end); } @Override public void appendString(Appendable appendable) { this.getMutableCollection().appendString(appendable); } @Override public void appendString(Appendable appendable, String separator) { this.getMutableCollection().appendString(appendable, separator); } @Override public void appendString(Appendable appendable, String start, String separator, String end) { this.getMutableCollection().appendString(appendable, start, separator, end); } @Override public MutableMultimap groupBy(Function function) { return this.getMutableCollection().groupBy(function); } @Override public > R groupBy( Function function, R target) { return this.getMutableCollection().groupBy(function, target); } @Override public MutableMultimap groupByEach(Function> function) { return this.getMutableCollection().groupByEach(function); } @Override public > R groupByEach( Function> function, R target) { return this.getMutableCollection().groupByEach(function, target); } @Override public MutableMap groupByUniqueKey(Function function) { return this.getMutableCollection().groupByUniqueKey(function); } @Override public > R groupByUniqueKey( Function function, R target) { return this.getMutableCollection().groupByUniqueKey(function, target); } @Override public MutableCollection> zip(Iterable that) { return this.getMutableCollection().zip(that); } @Override public >> R zip(Iterable that, R target) { return this.getMutableCollection().zip(that, target); } @Override public MutableCollection> zipWithIndex() { return this.getMutableCollection().zipWithIndex(); } @Override public >> R zipWithIndex(R target) { return this.getMutableCollection().zipWithIndex(target); } @Override public RichIterable> chunk(int size) { return this.getMutableCollection().chunk(size); } @Override public MutableCollection with(T element) { throw new UnsupportedOperationException("Cannot call with() on " + this.getClass().getSimpleName()); } @Override public MutableCollection without(T element) { throw new UnsupportedOperationException("Cannot call without() on " + this.getClass().getSimpleName()); } @Override public MutableCollection withAll(Iterable elements) { throw new UnsupportedOperationException("Cannot call withAll() on " + this.getClass().getSimpleName()); } @Override public MutableCollection withoutAll(Iterable elements) { throw new UnsupportedOperationException("Cannot call withoutAll() on " + this.getClass().getSimpleName()); } }