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

com.gs.collections.impl.collection.mutable.AbstractUnmodifiableMutableCollection 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 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 collection;

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

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

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

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

    public 

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

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

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

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

PartitionMutableCollection partitionWith(Predicate2 predicate, P parameter) { return this.getMutableCollection().partitionWith(predicate, parameter); } public MutableCollection selectInstancesOf(Class clazz) { return this.getMutableCollection().selectInstancesOf(clazz); } public boolean removeIf(Predicate predicate) { throw new UnsupportedOperationException("Cannot call removeIf() on " + this.getClass().getSimpleName()); } public

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

T detectWith(Predicate2 predicate, P parameter) { return this.getMutableCollection().detectWith(predicate, parameter); } public

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

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

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

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

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { return this.getMutableCollection().noneSatisfyWith(predicate, parameter); } public IV injectInto(IV injectedValue, Function2 function) { return this.getMutableCollection().injectInto(injectedValue, function); } public int injectInto(int injectedValue, IntObjectToIntFunction function) { return this.getMutableCollection().injectInto(injectedValue, function); } public long injectInto(long injectedValue, LongObjectToLongFunction function) { return this.getMutableCollection().injectInto(injectedValue, function); } public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { return this.getMutableCollection().injectInto(injectedValue, function); } public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { return this.getMutableCollection().injectInto(injectedValue, function); } public long sumOfInt(IntFunction function) { return this.getMutableCollection().sumOfInt(function); } public double sumOfFloat(FloatFunction function) { return this.getMutableCollection().sumOfFloat(function); } public long sumOfLong(LongFunction function) { return this.getMutableCollection().sumOfLong(function); } public double sumOfDouble(DoubleFunction function) { return this.getMutableCollection().sumOfDouble(function); } 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 IV injectIntoWith( IV injectValue, Function3 function, P parameter) { return this.getMutableCollection().injectIntoWith(injectValue, function, parameter); } public MutableList toList() { return this.getMutableCollection().toList(); } public MutableList toSortedList() { return this.getMutableCollection().toSortedList(); } public MutableList toSortedList(Comparator comparator) { return this.getMutableCollection().toSortedList(comparator); } public > MutableList toSortedListBy(Function function) { return this.getMutableCollection().toSortedList(Comparators.byFunction(function)); } public MutableSortedSet toSortedSet() { return this.getMutableCollection().toSortedSet(); } public MutableSortedSet toSortedSet(Comparator comparator) { return this.getMutableCollection().toSortedSet(comparator); } public > MutableSortedSet toSortedSetBy(Function function) { return this.getMutableCollection().toSortedSetBy(function); } public MutableSet toSet() { return this.getMutableCollection().toSet(); } public MutableBag toBag() { return this.getMutableCollection().toBag(); } public MutableSortedBag toSortedBag() { return this.getMutableCollection().toSortedBag(); } public MutableSortedBag toSortedBag(Comparator comparator) { return this.getMutableCollection().toSortedBag(comparator); } public > MutableSortedBag toSortedBagBy(Function function) { return this.getMutableCollection().toSortedBag(Comparators.byFunction(function)); } public MutableMap toMap( Function keyFunction, Function valueFunction) { return this.getMutableCollection().toMap(keyFunction, valueFunction); } public MutableSortedMap toSortedMap( Function keyFunction, Function valueFunction) { return this.getMutableCollection().toSortedMap(keyFunction, valueFunction); } public MutableSortedMap toSortedMap(Comparator comparator, Function keyFunction, Function valueFunction) { return this.getMutableCollection().toSortedMap(comparator, keyFunction, valueFunction); } @Override public String toString() { return this.getMutableCollection().toString(); } public String makeString() { return this.getMutableCollection().makeString(); } public String makeString(String separator) { return this.getMutableCollection().makeString(separator); } public String makeString(String start, String separator, String end) { return this.getMutableCollection().makeString(start, separator, end); } public void appendString(Appendable appendable) { this.getMutableCollection().appendString(appendable); } public void appendString(Appendable appendable, String separator) { this.getMutableCollection().appendString(appendable, separator); } public void appendString(Appendable appendable, String start, String separator, String end) { this.getMutableCollection().appendString(appendable, start, separator, end); } public MutableMultimap groupBy(Function function) { return this.getMutableCollection().groupBy(function); } public > R groupBy( Function function, R target) { return this.getMutableCollection().groupBy(function, target); } public MutableMultimap groupByEach(Function> function) { return this.getMutableCollection().groupByEach(function); } public > R groupByEach( Function> function, R target) { return this.getMutableCollection().groupByEach(function, target); } public MutableMap groupByUniqueKey(Function function) { return this.getMutableCollection().groupByUniqueKey(function); } public > R groupByUniqueKey( Function function, R target) { return this.getMutableCollection().groupByUniqueKey(function, target); } public MutableCollection> zip(Iterable that) { return this.getMutableCollection().zip(that); } public >> R zip(Iterable that, R target) { return this.getMutableCollection().zip(that, target); } public MutableCollection> zipWithIndex() { return this.getMutableCollection().zipWithIndex(); } public >> R zipWithIndex(R target) { return this.getMutableCollection().zipWithIndex(target); } public RichIterable> chunk(int size) { return this.getMutableCollection().chunk(size); } public MutableCollection with(T element) { throw new UnsupportedOperationException("Cannot call with() on " + this.getClass().getSimpleName()); } public MutableCollection without(T element) { throw new UnsupportedOperationException("Cannot call without() on " + this.getClass().getSimpleName()); } public MutableCollection withAll(Iterable elements) { throw new UnsupportedOperationException("Cannot call withAll() on " + this.getClass().getSimpleName()); } public MutableCollection withoutAll(Iterable elements) { throw new UnsupportedOperationException("Cannot call withoutAll() on " + this.getClass().getSimpleName()); } 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; } }