com.gs.collections.impl.collection.mutable.AbstractMultiReaderMutableCollection 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 java.util.concurrent.locks.ReadWriteLock;
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.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.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.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;
/**
* AbstractMultiReaderMutableCollection is a common abstraction that provides thread-safe collection behaviors.
* Subclasses of this class must provide implementations of getDelegate() and getLock().
*/
public abstract class AbstractMultiReaderMutableCollection implements MutableCollection
{
protected abstract MutableCollection getDelegate();
protected abstract ReadWriteLock getLock();
protected void acquireWriteLock()
{
this.getLock().writeLock().lock();
}
protected void unlockWriteLock()
{
this.getLock().writeLock().unlock();
}
protected void acquireReadLock()
{
this.getLock().readLock().lock();
}
protected void unlockReadLock()
{
this.getLock().readLock().unlock();
}
protected void withReadLockRun(Runnable block)
{
this.acquireReadLock();
try
{
block.run();
}
finally
{
this.unlockReadLock();
}
}
public boolean contains(Object item)
{
this.acquireReadLock();
try
{
return this.getDelegate().contains(item);
}
finally
{
this.unlockReadLock();
}
}
public boolean containsAll(Collection> collection)
{
this.acquireReadLock();
try
{
return this.getDelegate().containsAll(collection);
}
finally
{
this.unlockReadLock();
}
}
public boolean containsAllIterable(Iterable> source)
{
this.acquireReadLock();
try
{
return this.getDelegate().containsAllIterable(source);
}
finally
{
this.unlockReadLock();
}
}
public boolean containsAllArguments(Object... elements)
{
this.acquireReadLock();
try
{
return this.getDelegate().containsAllArguments(elements);
}
finally
{
this.unlockReadLock();
}
}
public boolean noneSatisfy(Predicate super T> predicate)
{
this.acquireReadLock();
try
{
return this.getDelegate().noneSatisfy(predicate);
}
finally
{
this.unlockReadLock();
}
}
public boolean noneSatisfyWith(
Predicate2 super T, ? super P> predicate,
P parameter)
{
this.acquireReadLock();
try
{
return this.getDelegate().noneSatisfyWith(predicate, parameter);
}
finally
{
this.unlockReadLock();
}
}
public boolean allSatisfy(Predicate super T> predicate)
{
this.acquireReadLock();
try
{
return this.getDelegate().allSatisfy(predicate);
}
finally
{
this.unlockReadLock();
}
}
public
boolean allSatisfyWith(
Predicate2 super T, ? super P> predicate,
P parameter)
{
this.acquireReadLock();
try
{
return this.getDelegate().allSatisfyWith(predicate, parameter);
}
finally
{
this.unlockReadLock();
}
}
public boolean anySatisfy(Predicate super T> predicate)
{
this.acquireReadLock();
try
{
return this.getDelegate().anySatisfy(predicate);
}
finally
{
this.unlockReadLock();
}
}
public
boolean anySatisfyWith(
Predicate2 super T, ? super P> predicate,
P parameter)
{
this.acquireReadLock();
try
{
return this.getDelegate().anySatisfyWith(predicate, parameter);
}
finally
{
this.unlockReadLock();
}
}
public MutableList toList()
{
this.acquireReadLock();
try
{
return this.getDelegate().toList();
}
finally
{
this.unlockReadLock();
}
}
public MutableMap toMap(
Function super T, ? extends NK> keyFunction,
Function super T, ? extends NV> valueFunction)
{
this.acquireReadLock();
try
{
return this.getDelegate().toMap(keyFunction, valueFunction);
}
finally
{
this.unlockReadLock();
}
}
public MutableSortedMap toSortedMap(
Function super T, ? extends NK> keyFunction,
Function super T, ? extends NV> valueFunction)
{
this.acquireReadLock();
try
{
return this.getDelegate().toSortedMap(keyFunction, valueFunction);
}
finally
{
this.unlockReadLock();
}
}
public MutableSortedMap toSortedMap(Comparator super NK> comparator,
Function super T, ? extends NK> keyFunction,
Function super T, ? extends NV> valueFunction)
{
this.acquireReadLock();
try
{
return this.getDelegate().toSortedMap(comparator, keyFunction, valueFunction);
}
finally
{
this.unlockReadLock();
}
}
public LazyIterable asLazy()
{
this.acquireReadLock();
try
{
return this.getDelegate().asLazy();
}
finally
{
this.unlockReadLock();
}
}
public MutableSet toSet()
{
this.acquireReadLock();
try
{
return this.getDelegate().toSet();
}
finally
{
this.unlockReadLock();
}
}
public MutableBag toBag()
{
this.acquireReadLock();
try
{
return this.getDelegate().toBag();
}
finally
{
this.unlockReadLock();
}
}
public MutableSortedBag toSortedBag()
{
this.acquireReadLock();
try
{
return this.getDelegate().toSortedBag();
}
finally
{
this.unlockReadLock();
}
}
public MutableSortedBag toSortedBag(Comparator super T> comparator)
{
this.acquireReadLock();
try
{
return this.getDelegate().toSortedBag(comparator);
}
finally
{
this.unlockReadLock();
}
}
public > MutableSortedBag toSortedBagBy(
Function super T, ? extends V> function)
{
this.acquireReadLock();
try
{
return this.getDelegate().toSortedBagBy(function);
}
finally
{
this.unlockReadLock();
}
}
public MutableList toSortedList()
{
this.acquireReadLock();
try
{
return this.getDelegate().toSortedList();
}
finally
{
this.unlockReadLock();
}
}
public MutableList toSortedList(Comparator super T> comparator)
{
this.acquireReadLock();
try
{
return this.getDelegate().toSortedList(comparator);
}
finally
{
this.unlockReadLock();
}
}
public > MutableList toSortedListBy(
Function super T, ? extends V> function)
{
this.acquireReadLock();
try
{
return this.getDelegate().toSortedListBy(function);
}
finally
{
this.unlockReadLock();
}
}
public MutableSortedSet toSortedSet()
{
this.acquireReadLock();
try
{
return this.getDelegate().toSortedSet();
}
finally
{
this.unlockReadLock();
}
}
public MutableSortedSet toSortedSet(Comparator super T> comparator)
{
this.acquireReadLock();
try
{
return this.getDelegate().toSortedSet(comparator);
}
finally
{
this.unlockReadLock();
}
}
public > MutableSortedSet toSortedSetBy(
Function super T, ? extends V> function)
{
this.acquireReadLock();
try
{
return this.getDelegate().toSortedSetBy(function);
}
finally
{
this.unlockReadLock();
}
}
public int count(Predicate super T> predicate)
{
this.acquireReadLock();
try
{
return this.getDelegate().count(predicate);
}
finally
{
this.unlockReadLock();
}
}
public int countWith(
Predicate2 super T, ? super P> predicate,
P parameter)
{
this.acquireReadLock();
try
{
return this.getDelegate().countWith(predicate, parameter);
}
finally
{
this.unlockReadLock();
}
}
public T detect(Predicate super T> predicate)
{
this.acquireReadLock();
try
{
return this.getDelegate().detect(predicate);
}
finally
{
this.unlockReadLock();
}
}
public T min(Comparator super T> comparator)
{
this.acquireReadLock();
try
{
return this.getDelegate().min(comparator);
}
finally
{
this.unlockReadLock();
}
}
public T max(Comparator super T> comparator)
{
this.acquireReadLock();
try
{
return this.getDelegate().max(comparator);
}
finally
{
this.unlockReadLock();
}
}
public T min()
{
this.acquireReadLock();
try
{
return this.getDelegate().min();
}
finally
{
this.unlockReadLock();
}
}
public T max()
{
this.acquireReadLock();
try
{
return this.getDelegate().max();
}
finally
{
this.unlockReadLock();
}
}
public > T minBy(Function super T, ? extends V> function)
{
this.acquireReadLock();
try
{
return this.getDelegate().minBy(function);
}
finally
{
this.unlockReadLock();
}
}
public > T maxBy(Function super T, ? extends V> function)
{
this.acquireReadLock();
try
{
return this.getDelegate().maxBy(function);
}
finally
{
this.unlockReadLock();
}
}
public T detectIfNone(
Predicate super T> predicate,
Function0 extends T> function)
{
this.acquireReadLock();
try
{
return this.getDelegate().detectIfNone(predicate, function);
}
finally
{
this.unlockReadLock();
}
}
public T detectWith(
Predicate2 super T, ? super P> predicate,
P parameter)
{
this.acquireReadLock();
try
{
return this.getDelegate().detectWith(predicate, parameter);
}
finally
{
this.unlockReadLock();
}
}
public
T detectWithIfNone(
Predicate2 super T, ? super P> predicate,
P parameter,
Function0 extends T> function)
{
this.acquireReadLock();
try
{
return this.getDelegate().detectWithIfNone(predicate, parameter, function);
}
finally
{
this.unlockReadLock();
}
}
public T getFirst()
{
this.acquireReadLock();
try
{
return this.getDelegate().getFirst();
}
finally
{
this.unlockReadLock();
}
}
public T getLast()
{
this.acquireReadLock();
try
{
return this.getDelegate().getLast();
}
finally
{
this.unlockReadLock();
}
}
public boolean notEmpty()
{
this.acquireReadLock();
try
{
return this.getDelegate().notEmpty();
}
finally
{
this.unlockReadLock();
}
}
public
Twin> selectAndRejectWith(
Predicate2 super T, ? super P> predicate,
P parameter)
{
this.acquireReadLock();
try
{
return this.getDelegate().selectAndRejectWith(predicate, parameter);
}
finally
{
this.unlockReadLock();
}
}
public > R collect(
Function super T, ? extends V> function,
R target)
{
this.acquireReadLock();
try
{
return this.getDelegate().collect(function, target);
}
finally
{
this.unlockReadLock();
}
}
public R collectBoolean(BooleanFunction super T> booleanFunction, R target)
{
this.acquireReadLock();
try
{
return this.getDelegate().collectBoolean(booleanFunction, target);
}
finally
{
this.unlockReadLock();
}
}
public R collectByte(ByteFunction super T> byteFunction, R target)
{
this.acquireReadLock();
try
{
return this.getDelegate().collectByte(byteFunction, target);
}
finally
{
this.unlockReadLock();
}
}
public R collectChar(CharFunction super T> charFunction, R target)
{
this.acquireReadLock();
try
{
return this.getDelegate().collectChar(charFunction, target);
}
finally
{
this.unlockReadLock();
}
}
public R collectDouble(DoubleFunction super T> doubleFunction, R target)
{
this.acquireReadLock();
try
{
return this.getDelegate().collectDouble(doubleFunction, target);
}
finally
{
this.unlockReadLock();
}
}
public R collectFloat(FloatFunction super T> floatFunction, R target)
{
this.acquireReadLock();
try
{
return this.getDelegate().collectFloat(floatFunction, target);
}
finally
{
this.unlockReadLock();
}
}
public R collectInt(IntFunction super T> intFunction, R target)
{
this.acquireReadLock();
try
{
return this.getDelegate().collectInt(intFunction, target);
}
finally
{
this.unlockReadLock();
}
}
public R collectLong(LongFunction super T> longFunction, R target)
{
this.acquireReadLock();
try
{
return this.getDelegate().collectLong(longFunction, target);
}
finally
{
this.unlockReadLock();
}
}
public R collectShort(ShortFunction super T> shortFunction, R target)
{
this.acquireReadLock();
try
{
return this.getDelegate().collectShort(shortFunction, target);
}
finally
{
this.unlockReadLock();
}
}
public > R flatCollect(
Function super T, ? extends Iterable> function,
R target)
{
this.acquireReadLock();
try
{
return this.getDelegate().flatCollect(function, target);
}
finally
{
this.unlockReadLock();
}
}
public > R collectIf(
Predicate super T> predicate,
Function super T, ? extends V> function,
R target)
{
this.acquireReadLock();
try
{
return this.getDelegate().collectIf(predicate, function, target);
}
finally
{
this.unlockReadLock();
}
}
public > R collectWith(
Function2 super T, ? super P, ? extends V> function,
P parameter,
R targetCollection)
{
this.acquireReadLock();
try
{
return this.getDelegate().collectWith(function, parameter, targetCollection);
}
finally
{
this.unlockReadLock();
}
}
public
> R selectWith(
Predicate2 super T, ? super P> predicate,
P parameter,
R targetCollection)
{
this.acquireReadLock();
try
{
return this.getDelegate().selectWith(predicate, parameter, targetCollection);
}
finally
{
this.unlockReadLock();
}
}
public > R reject(
Predicate super T> predicate,
R target)
{
this.acquireReadLock();
try
{
return this.getDelegate().reject(predicate, target);
}
finally
{
this.unlockReadLock();
}
}
public > R rejectWith(
Predicate2 super T, ? super P> predicate,
P parameter,
R targetCollection)
{
this.acquireReadLock();
try
{
return this.getDelegate().rejectWith(predicate, parameter, targetCollection);
}
finally
{
this.unlockReadLock();
}
}
public > R select(Predicate super T> predicate, R target)
{
this.acquireReadLock();
try
{
return this.getDelegate().select(predicate, target);
}
finally
{
this.unlockReadLock();
}
}
public IV injectInto(
IV injectedValue,
Function2 super IV, ? super T, ? extends IV> function)
{
this.acquireReadLock();
try
{
return this.getDelegate().injectInto(injectedValue, function);
}
finally
{
this.unlockReadLock();
}
}
public int injectInto(int injectedValue, IntObjectToIntFunction super T> function)
{
this.acquireReadLock();
try
{
return this.getDelegate().injectInto(injectedValue, function);
}
finally
{
this.unlockReadLock();
}
}
public long injectInto(long injectedValue, LongObjectToLongFunction super T> function)
{
this.acquireReadLock();
try
{
return this.getDelegate().injectInto(injectedValue, function);
}
finally
{
this.unlockReadLock();
}
}
public double injectInto(double injectedValue, DoubleObjectToDoubleFunction super T> function)
{
this.acquireReadLock();
try
{
return this.getDelegate().injectInto(injectedValue, function);
}
finally
{
this.unlockReadLock();
}
}
public float injectInto(float injectedValue, FloatObjectToFloatFunction super T> function)
{
this.acquireReadLock();
try
{
return this.getDelegate().injectInto(injectedValue, function);
}
finally
{
this.unlockReadLock();
}
}
public long sumOfInt(IntFunction super T> function)
{
this.acquireReadLock();
try
{
return this.getDelegate().sumOfInt(function);
}
finally
{
this.unlockReadLock();
}
}
public double sumOfFloat(FloatFunction super T> function)
{
this.acquireReadLock();
try
{
return this.getDelegate().sumOfFloat(function);
}
finally
{
this.unlockReadLock();
}
}
public long sumOfLong(LongFunction super T> function)
{
this.acquireReadLock();
try
{
return this.getDelegate().sumOfLong(function);
}
finally
{
this.unlockReadLock();
}
}
public double sumOfDouble(DoubleFunction super T> function)
{
this.acquireReadLock();
try
{
return this.getDelegate().sumOfDouble(function);
}
finally
{
this.unlockReadLock();
}
}
public ObjectLongMap sumByInt(Function groupBy, IntFunction super T> function)
{
ObjectLongHashMap result = ObjectLongHashMap.newMap();
return this.injectInto(result, PrimitiveFunctions.sumByIntFunction(groupBy, function));
}
public ObjectDoubleMap sumByFloat(Function groupBy, FloatFunction super T> function)
{
ObjectDoubleHashMap result = ObjectDoubleHashMap.newMap();
return this.injectInto(result, PrimitiveFunctions.sumByFloatFunction(groupBy, function));
}
public ObjectLongMap sumByLong(Function groupBy, LongFunction super T> function)
{
ObjectLongHashMap result = ObjectLongHashMap.newMap();
return this.injectInto(result, PrimitiveFunctions.sumByLongFunction(groupBy, function));
}
public ObjectDoubleMap sumByDouble(Function groupBy, DoubleFunction super T> function)
{
ObjectDoubleHashMap result = ObjectDoubleHashMap.newMap();
return this.injectInto(result, PrimitiveFunctions.sumByDoubleFunction(groupBy, function));
}
public IV injectIntoWith(
IV injectValue,
Function3 super IV, ? super T, ? super P, ? extends IV> function,
P parameter)
{
this.acquireReadLock();
try
{
return this.getDelegate().injectIntoWith(injectValue, function, parameter);
}
finally
{
this.unlockReadLock();
}
}
public boolean removeIf(Predicate super T> predicate)
{
this.acquireWriteLock();
try
{
return this.getDelegate().removeIf(predicate);
}
finally
{
this.unlockWriteLock();
}
}
public boolean removeIfWith(
Predicate2 super T, ? super P> predicate,
P parameter)
{
this.acquireWriteLock();
try
{
return this.getDelegate().removeIfWith(predicate, parameter);
}
finally
{
this.unlockWriteLock();
}
}
public boolean add(T item)
{
this.acquireWriteLock();
try
{
return this.getDelegate().add(item);
}
finally
{
this.unlockWriteLock();
}
}
public boolean addAll(Collection extends T> collection)
{
this.acquireWriteLock();
try
{
return this.getDelegate().addAll(collection);
}
finally
{
this.unlockWriteLock();
}
}
public boolean addAllIterable(Iterable extends T> iterable)
{
this.acquireWriteLock();
try
{
return this.getDelegate().addAllIterable(iterable);
}
finally
{
this.unlockWriteLock();
}
}
public void clear()
{
this.acquireWriteLock();
try
{
this.getDelegate().clear();
}
finally
{
this.unlockWriteLock();
}
}
public boolean isEmpty()
{
this.acquireReadLock();
try
{
return this.getDelegate().isEmpty();
}
finally
{
this.unlockReadLock();
}
}
/**
* This method is not supported directly on MultiReader collections because it is not thread-safe. If you would like
* to use an iterator with a MultiReader collection, then you must do the following:
*
*
* multiReaderList.withReadLockAndDelegate(new Procedure>()
* {
* public void value(MutableList people)
* {
* Iterator it = people.iterator();
* ....
* }
* });
*
*
*
* final Collection jdkSet = new HashSet();
* final boolean containsAll = new boolean[1];
* multiReaderList.withReadLockAndDelegate(new Procedure>()
* {
* public void value(MutableList people)
* {
* set.addAll(people); // addAll uses iterator() in AbstractCollection
* containsAll[0] = set.containsAll(people); // containsAll uses iterator() in AbstractCollection
* }
* });
*
*/
public Iterator iterator()
{
throw new UnsupportedOperationException(
"Iterator is not supported directly on MultiReader collections. "
+ "If you would like to use an iterator, you must either use withReadLockAndDelegate() or withWriteLockAndDelegate().");
}
public boolean remove(Object item)
{
this.acquireWriteLock();
try
{
return this.getDelegate().remove(item);
}
finally
{
this.unlockWriteLock();
}
}
public boolean removeAll(Collection> collection)
{
this.acquireWriteLock();
try
{
return this.getDelegate().removeAll(collection);
}
finally
{
this.unlockWriteLock();
}
}
public boolean removeAllIterable(Iterable> iterable)
{
this.acquireWriteLock();
try
{
return this.getDelegate().removeAllIterable(iterable);
}
finally
{
this.unlockWriteLock();
}
}
public boolean retainAll(Collection> collection)
{
this.acquireWriteLock();
try
{
return this.getDelegate().retainAll(collection);
}
finally
{
this.unlockWriteLock();
}
}
public boolean retainAllIterable(Iterable> iterable)
{
this.acquireWriteLock();
try
{
return this.getDelegate().retainAllIterable(iterable);
}
finally
{
this.unlockWriteLock();
}
}
public int size()
{
this.acquireReadLock();
try
{
return this.getDelegate().size();
}
finally
{
this.unlockReadLock();
}
}
public Object[] toArray()
{
this.acquireReadLock();
try
{
return this.getDelegate().toArray();
}
finally
{
this.unlockReadLock();
}
}
public E[] toArray(E[] a)
{
this.acquireReadLock();
try
{
return this.getDelegate().toArray(a);
}
finally
{
this.unlockReadLock();
}
}
public void forEach(Procedure super T> procedure)
{
this.each(procedure);
}
public void each(Procedure super T> procedure)
{
this.acquireReadLock();
try
{
this.getDelegate().forEach(procedure);
}
finally
{
this.unlockReadLock();
}
}
public void forEachWith(Procedure2 super T, ? super P> procedure, P parameter)
{
this.acquireReadLock();
try
{
this.getDelegate().forEachWith(procedure, parameter);
}
finally
{
this.unlockReadLock();
}
}
public void forEachWithIndex(ObjectIntProcedure super T> objectIntProcedure)
{
this.acquireReadLock();
try
{
this.getDelegate().forEachWithIndex(objectIntProcedure);
}
finally
{
this.unlockReadLock();
}
}
@Override
public String toString()
{
this.acquireReadLock();
try
{
return this.getDelegate().toString();
}
finally
{
this.unlockReadLock();
}
}
public String makeString()
{
this.acquireReadLock();
try
{
return this.getDelegate().makeString();
}
finally
{
this.unlockReadLock();
}
}
public String makeString(String separator)
{
this.acquireReadLock();
try
{
return this.getDelegate().makeString(separator);
}
finally
{
this.unlockReadLock();
}
}
public String makeString(String start, String separator, String end)
{
this.acquireReadLock();
try
{
return this.getDelegate().makeString(start, separator, end);
}
finally
{
this.unlockReadLock();
}
}
public void appendString(Appendable appendable)
{
this.acquireReadLock();
try
{
this.getDelegate().appendString(appendable);
}
finally
{
this.unlockReadLock();
}
}
public void appendString(Appendable appendable, String separator)
{
this.acquireReadLock();
try
{
this.getDelegate().appendString(appendable, separator);
}
finally
{
this.unlockReadLock();
}
}
public void appendString(Appendable appendable, String start, String separator, String end)
{
this.acquireReadLock();
try
{
this.getDelegate().appendString(appendable, start, separator, end);
}
finally
{
this.unlockReadLock();
}
}
public > R groupBy(
Function super T, ? extends V> function,
R target)
{
this.acquireReadLock();
try
{
return this.getDelegate().groupBy(function, target);
}
finally
{
this.unlockReadLock();
}
}
public > R groupByEach(
Function super T, ? extends Iterable> function,
R target)
{
this.acquireReadLock();
try
{
return this.getDelegate().groupByEach(function, target);
}
finally
{
this.unlockReadLock();
}
}
public > R groupByUniqueKey(
Function super T, ? extends V> function,
R target)
{
this.acquireReadLock();
try
{
return this.getDelegate().groupByUniqueKey(function, target);
}
finally
{
this.unlockReadLock();
}
}
public >> R zip(Iterable that, R target)
{
this.acquireReadLock();
try
{
return this.getDelegate().zip(that, target);
}
finally
{
this.unlockReadLock();
}
}
public >> R zipWithIndex(R target)
{
this.acquireReadLock();
try
{
return this.getDelegate().zipWithIndex(target);
}
finally
{
this.unlockReadLock();
}
}
public MutableMap 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 MutableMap 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;
}
protected abstract static class UntouchableMutableCollection
implements MutableCollection
{
protected MutableCollection delegate;
public boolean allSatisfy(Predicate super T> predicate)
{
return this.delegate.allSatisfy(predicate);
}
public boolean allSatisfyWith(
Predicate2 super T, ? super P> predicate,
P parameter)
{
return this.delegate.allSatisfyWith(predicate, parameter);
}
public boolean noneSatisfy(Predicate super T> predicate)
{
return this.delegate.noneSatisfy(predicate);
}
public
boolean noneSatisfyWith(
Predicate2 super T, ? super P> predicate,
P parameter)
{
return this.delegate.noneSatisfyWith(predicate, parameter);
}
public boolean anySatisfy(Predicate super T> predicate)
{
return this.delegate.anySatisfy(predicate);
}
public
boolean anySatisfyWith(
Predicate2 super T, ? super P> predicate,
P parameter)
{
return this.delegate.anySatisfyWith(predicate, parameter);
}
public MutableList toList()
{
return this.delegate.toList();
}
public MutableMap toMap(
Function super T, ? extends NK> keyFunction,
Function super T, ? extends NV> valueFunction)
{
return this.delegate.toMap(keyFunction, valueFunction);
}
public MutableSortedMap toSortedMap(
Function super T, ? extends NK> keyFunction,
Function super T, ? extends NV> valueFunction)
{
return this.delegate.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.toSortedMap(comparator, keyFunction, valueFunction);
}
public MutableSet toSet()
{
return this.delegate.toSet();
}
public MutableBag toBag()
{
return this.delegate.toBag();
}
public MutableSortedBag toSortedBag()
{
return this.delegate.toSortedBag();
}
public MutableSortedBag toSortedBag(Comparator super T> comparator)
{
return this.delegate.toSortedBag(comparator);
}
public > MutableSortedBag toSortedBagBy(Function super T, ? extends V> function)
{
return this.delegate.toSortedBagBy(function);
}
public MutableList toSortedList()
{
return this.delegate.toSortedList();
}
public MutableList toSortedList(Comparator super T> comparator)
{
return this.delegate.toSortedList(comparator);
}
public > MutableList toSortedListBy(Function super T, ? extends V> function)
{
return this.delegate.toSortedListBy(function);
}
public MutableSortedSet toSortedSet()
{
return this.delegate.toSortedSet();
}
public MutableSortedSet toSortedSet(Comparator super T> comparator)
{
return this.delegate.toSortedSet(comparator);
}
public > MutableSortedSet toSortedSetBy(Function super T, ? extends V> function)
{
return this.delegate.toSortedSetBy(function);
}
public > R collect(
Function super T, ? extends V> function,
R target)
{
return this.delegate.collect(function, target);
}
public > R flatCollect(
Function super T, ? extends Iterable> function,
R target)
{
return this.delegate.flatCollect(function, target);
}
public > R collectIf(
Predicate super T> predicate,
Function super T, ? extends V> function,
R target)
{
return this.delegate.collectIf(predicate, function, target);
}
public > R collectWith(
Function2 super T, ? super P, ? extends V> function,
P parameter,
R targetCollection)
{
return this.delegate.collectWith(function, parameter, targetCollection);
}
public > R groupBy(
Function super T, ? extends V> function,
R target)
{
return this.delegate.groupBy(function, target);
}
public > R groupByEach(
Function super T, ? extends Iterable> function,
R target)
{
return this.delegate.groupByEach(function, target);
}
public > R groupByUniqueKey(
Function super T, ? extends V> function,
R target)
{
return this.delegate.groupByUniqueKey(function, target);
}
public int count(Predicate super T> predicate)
{
return this.delegate.count(predicate);
}
public int countWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.delegate.countWith(predicate, parameter);
}
public T detect(Predicate super T> predicate)
{
return this.delegate.detect(predicate);
}
public T min(Comparator super T> comparator)
{
return this.delegate.min(comparator);
}
public T max(Comparator super T> comparator)
{
return this.delegate.max(comparator);
}
public T min()
{
return this.delegate.min();
}
public T max()
{
return this.delegate.max();
}
public > T minBy(Function super T, ? extends V> function)
{
return this.delegate.minBy(function);
}
public > T maxBy(Function super T, ? extends V> function)
{
return this.delegate.maxBy(function);
}
public T detectIfNone(Predicate super T> predicate, Function0 extends T> function)
{
return this.delegate.detectIfNone(predicate, function);
}
public T detectWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.delegate.detectWith(predicate, parameter);
}
public
T detectWithIfNone(
Predicate2 super T, ? super P> predicate,
P parameter,
Function0 extends T> function)
{
return this.delegate.detectWithIfNone(predicate, parameter, function);
}
public T getFirst()
{
return this.delegate.getFirst();
}
public T getLast()
{
return this.delegate.getLast();
}
public IV injectInto(
IV injectedValue,
Function2 super IV, ? super T, ? extends IV> function)
{
return this.delegate.injectInto(injectedValue, function);
}
public int injectInto(int injectedValue, IntObjectToIntFunction super T> function)
{
return this.delegate.injectInto(injectedValue, function);
}
public long injectInto(long injectedValue, LongObjectToLongFunction super T> function)
{
return this.delegate.injectInto(injectedValue, function);
}
public double injectInto(double injectedValue, DoubleObjectToDoubleFunction super T> function)
{
return this.delegate.injectInto(injectedValue, function);
}
public float injectInto(float injectedValue, FloatObjectToFloatFunction super T> function)
{
return this.delegate.injectInto(injectedValue, function);
}
public long sumOfInt(IntFunction super T> function)
{
return this.delegate.sumOfInt(function);
}
public double sumOfFloat(FloatFunction super T> function)
{
return this.delegate.sumOfFloat(function);
}
public long sumOfLong(LongFunction super T> function)
{
return this.delegate.sumOfLong(function);
}
public double sumOfDouble(DoubleFunction super T> function)
{
return this.delegate.sumOfDouble(function);
}
public ObjectLongMap sumByInt(Function groupBy, IntFunction super T> function)
{
return this.delegate.sumByInt(groupBy, function);
}
public ObjectDoubleMap sumByFloat(Function groupBy, FloatFunction super T> function)
{
return this.delegate.sumByFloat(groupBy, function);
}
public ObjectLongMap sumByLong(Function groupBy, LongFunction super T> function)
{
return this.delegate.sumByLong(groupBy, function);
}
public ObjectDoubleMap sumByDouble(Function groupBy, DoubleFunction super T> function)
{
return this.delegate.sumByDouble(groupBy, function);
}
public IV injectIntoWith(
IV injectValue,
Function3 super IV, ? super T, ? super P, ? extends IV> function,
P parameter)
{
return this.delegate.injectIntoWith(injectValue, function, parameter);
}
public boolean notEmpty()
{
return this.delegate.notEmpty();
}
public > R reject(Predicate super T> predicate, R target)
{
return this.delegate.reject(predicate, target);
}
public > R rejectWith(
Predicate2 super T, ? super P> predicate,
P parameter,
R targetCollection)
{
return this.delegate.rejectWith(predicate, parameter, targetCollection);
}
public boolean removeIf(Predicate super T> predicate)
{
return this.delegate.removeIf(predicate);
}
public
boolean removeIfWith(
Predicate2 super T, ? super P> predicate,
P parameter)
{
return this.delegate.removeIfWith(predicate, parameter);
}
public > R select(Predicate super T> predicate, R target)
{
return this.delegate.select(predicate, target);
}
public Twin> selectAndRejectWith(
Predicate2 super T, ? super P> predicate,
P parameter)
{
return this.delegate.selectAndRejectWith(predicate, parameter);
}
public > R selectWith(
Predicate2 super T, ? super P> predicate,
P parameter,
R targetCollection)
{
return this.delegate.selectWith(predicate, parameter, targetCollection);
}
public boolean add(T o)
{
return this.delegate.add(o);
}
public boolean addAll(Collection extends T> collection)
{
return this.delegate.addAll(collection);
}
public boolean addAllIterable(Iterable extends T> iterable)
{
return this.delegate.addAllIterable(iterable);
}
public void clear()
{
this.delegate.clear();
}
public boolean contains(Object o)
{
return this.delegate.contains(o);
}
public boolean containsAll(Collection> collection)
{
return this.delegate.containsAll(collection);
}
public boolean containsAllIterable(Iterable> source)
{
return this.delegate.containsAllIterable(source);
}
public boolean containsAllArguments(Object... elements)
{
return this.delegate.containsAllArguments(elements);
}
@Override
public boolean equals(Object o)
{
return this.delegate.equals(o);
}
@Override
public int hashCode()
{
return this.delegate.hashCode();
}
public boolean isEmpty()
{
return this.delegate.isEmpty();
}
public boolean remove(Object o)
{
return this.delegate.remove(o);
}
public boolean removeAll(Collection> collection)
{
return this.delegate.removeAll(collection);
}
public boolean removeAllIterable(Iterable> iterable)
{
return this.delegate.removeAllIterable(iterable);
}
public boolean retainAll(Collection> collection)
{
return this.delegate.retainAll(collection);
}
public boolean retainAllIterable(Iterable> iterable)
{
return this.delegate.retainAllIterable(iterable);
}
public int size()
{
return this.delegate.size();
}
public Object[] toArray()
{
return this.delegate.toArray();
}
public T[] toArray(T[] a)
{
return this.delegate.toArray(a);
}
public void forEach(Procedure super T> procedure)
{
this.each(procedure);
}
public void each(Procedure super T> procedure)
{
this.delegate.forEach(procedure);
}
public void forEachWith(Procedure2 super T, ? super P> procedure, P parameter)
{
this.delegate.forEachWith(procedure, parameter);
}
public void forEachWithIndex(ObjectIntProcedure super T> objectIntProcedure)
{
this.delegate.forEachWithIndex(objectIntProcedure);
}
@Override
public String toString()
{
return this.delegate.toString();
}
public String makeString()
{
return this.delegate.makeString();
}
public String makeString(String separator)
{
return this.delegate.makeString(separator);
}
public String makeString(String start, String separator, String end)
{
return this.delegate.makeString(start, separator, end);
}
public void appendString(Appendable appendable)
{
this.delegate.appendString(appendable);
}
public void appendString(Appendable appendable, String separator)
{
this.delegate.appendString(appendable, separator);
}
public void appendString(Appendable appendable, String start, String separator, String end)
{
this.delegate.appendString(appendable, start, separator, end);
}
public >> R zip(Iterable that, R target)
{
return this.delegate.zip(that, target);
}
public >> R zipWithIndex(R target)
{
return this.delegate.zipWithIndex(target);
}
public RichIterable> chunk(int size)
{
return this.delegate.chunk(size);
}
public MutableMap aggregateInPlaceBy(
final Function super T, ? extends K> groupBy,
final Function0 extends V> zeroValueFactory,
final Procedure2 super V, ? super T> mutatingAggregator)
{
final MutableMap map = UnifiedMap.newMap();
this.forEach(new Procedure()
{
public void value(T each)
{
K key = groupBy.valueOf(each);
V value = map.getIfAbsentPut(key, zeroValueFactory);
mutatingAggregator.value(value, each);
}
});
return map;
}
public MutableMap aggregateBy(
final Function super T, ? extends K> groupBy,
final Function0 extends V> zeroValueFactory,
final Function2 super V, ? super T, ? extends V> nonMutatingAggregator)
{
final MutableMap map = UnifiedMap.newMap();
this.forEach(new Procedure()
{
public void value(T each)
{
K key = groupBy.valueOf(each);
V value = map.getIfAbsentPut(key, zeroValueFactory);
map.put(key, nonMutatingAggregator.value(value, each));
}
});
return map;
}
}
}