com.gs.collections.impl.collection.AbstractSynchronizedRichIterable 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;
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.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.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.impl.block.factory.Comparators;
import com.gs.collections.impl.map.mutable.UnifiedMap;
import com.gs.collections.impl.utility.LazyIterate;
import net.jcip.annotations.GuardedBy;
public abstract class AbstractSynchronizedRichIterable implements RichIterable
{
protected final Object lock;
@GuardedBy("this.lock")
protected final RichIterable delegate;
protected AbstractSynchronizedRichIterable(RichIterable delegate, Object lock)
{
if (delegate == null)
{
throw new IllegalArgumentException("Cannot create a AbstractSynchronizedRichIterable on a null collection");
}
this.delegate = delegate;
this.lock = lock == null ? this : lock;
}
protected RichIterable getDelegate()
{
return this.delegate;
}
protected Object getLock()
{
return this.lock;
}
@Override
public boolean equals(Object obj)
{
synchronized (this.lock)
{
return this.delegate.equals(obj);
}
}
@Override
public int hashCode()
{
synchronized (this.lock)
{
return this.delegate.hashCode();
}
}
@Override
public String toString()
{
synchronized (this.lock)
{
return this.delegate.toString();
}
}
/**
* Must be called in a synchronized block.
*/
public Iterator iterator()
{
return this.delegate.iterator();
}
public void forEach(Procedure super T> procedure)
{
this.each(procedure);
}
public void forEachWithIndex(ObjectIntProcedure super T> objectIntProcedure)
{
synchronized (this.lock)
{
this.delegate.forEachWithIndex(objectIntProcedure);
}
}
public void forEachWith(Procedure2 super T, ? super P> procedure, P parameter)
{
synchronized (this.lock)
{
this.delegate.forEachWith(procedure, parameter);
}
}
public int size()
{
synchronized (this.lock)
{
return this.delegate.size();
}
}
public boolean isEmpty()
{
synchronized (this.lock)
{
return this.delegate.isEmpty();
}
}
public boolean notEmpty()
{
synchronized (this.lock)
{
return this.delegate.notEmpty();
}
}
public T getFirst()
{
synchronized (this.lock)
{
return this.delegate.getFirst();
}
}
public T getLast()
{
synchronized (this.lock)
{
return this.delegate.getLast();
}
}
public boolean contains(Object o)
{
synchronized (this.lock)
{
return this.delegate.contains(o);
}
}
public boolean containsAllIterable(Iterable> source)
{
synchronized (this.lock)
{
return this.delegate.containsAllIterable(source);
}
}
public boolean containsAll(Collection> coll)
{
synchronized (this.lock)
{
return this.delegate.containsAll(coll);
}
}
public boolean containsAllArguments(Object... elements)
{
synchronized (this.lock)
{
return this.delegate.containsAllArguments(elements);
}
}
public void each(Procedure super T> procedure)
{
synchronized (this.lock)
{
this.delegate.forEach(procedure);
}
}
public > R select(Predicate super T> predicate, R target)
{
synchronized (this.lock)
{
return this.delegate.select(predicate, target);
}
}
public > R selectWith(
Predicate2 super T, ? super P> predicate,
P parameter,
R targetCollection)
{
synchronized (this.lock)
{
return this.delegate.selectWith(predicate, parameter, targetCollection);
}
}
public > R reject(Predicate super T> predicate, R target)
{
synchronized (this.lock)
{
return this.delegate.reject(predicate, target);
}
}
public > R rejectWith(
Predicate2 super T, ? super P> predicate,
P parameter,
R targetCollection)
{
synchronized (this.lock)
{
return this.delegate.rejectWith(predicate, parameter, targetCollection);
}
}
public R collectBoolean(BooleanFunction super T> booleanFunction, R target)
{
synchronized (this.lock)
{
return this.delegate.collectBoolean(booleanFunction, target);
}
}
public R collectByte(ByteFunction super T> byteFunction, R target)
{
synchronized (this.lock)
{
return this.delegate.collectByte(byteFunction, target);
}
}
public R collectChar(CharFunction super T> charFunction, R target)
{
synchronized (this.lock)
{
return this.delegate.collectChar(charFunction, target);
}
}
public R collectDouble(DoubleFunction super T> doubleFunction, R target)
{
synchronized (this.lock)
{
return this.delegate.collectDouble(doubleFunction, target);
}
}
public R collectFloat(FloatFunction super T> floatFunction, R target)
{
synchronized (this.lock)
{
return this.delegate.collectFloat(floatFunction, target);
}
}
public R collectInt(IntFunction super T> intFunction, R target)
{
synchronized (this.lock)
{
return this.delegate.collectInt(intFunction, target);
}
}
public R collectLong(LongFunction super T> longFunction, R target)
{
synchronized (this.lock)
{
return this.delegate.collectLong(longFunction, target);
}
}
public R collectShort(ShortFunction super T> shortFunction, R target)
{
synchronized (this.lock)
{
return this.delegate.collectShort(shortFunction, target);
}
}
public > R collect(Function super T, ? extends V> function, R target)
{
synchronized (this.lock)
{
return this.delegate.collect(function, target);
}
}
public > R collectWith(
Function2 super T, ? super P, ? extends A> function,
P parameter,
R targetCollection)
{
synchronized (this.lock)
{
return this.delegate.collectWith(function, parameter, targetCollection);
}
}
public > R collectIf(
Predicate super T> predicate,
Function super T, ? extends V> function,
R target)
{
synchronized (this.lock)
{
return this.delegate.collectIf(predicate, function, target);
}
}
public > R flatCollect(Function super T, ? extends Iterable> function, R target)
{
synchronized (this.lock)
{
return this.delegate.flatCollect(function, target);
}
}
public T detect(Predicate super T> predicate)
{
synchronized (this.lock)
{
return this.delegate.detect(predicate);
}
}
public T detectWith(Predicate2 super T, ? super P> predicate, P parameter)
{
synchronized (this.lock)
{
return this.delegate.detectWith(predicate, parameter);
}
}
public T detectIfNone(Predicate super T> predicate, Function0 extends T> function)
{
synchronized (this.lock)
{
return this.delegate.detectIfNone(predicate, function);
}
}
public
T detectWithIfNone(
Predicate2 super T, ? super P> predicate,
P parameter,
Function0 extends T> function)
{
synchronized (this.lock)
{
return this.delegate.detectWithIfNone(predicate, parameter, function);
}
}
public int count(Predicate super T> predicate)
{
synchronized (this.lock)
{
return this.delegate.count(predicate);
}
}
public
int countWith(Predicate2 super T, ? super P> predicate, P parameter)
{
synchronized (this.lock)
{
return this.delegate.countWith(predicate, parameter);
}
}
public boolean anySatisfy(Predicate super T> predicate)
{
synchronized (this.lock)
{
return this.delegate.anySatisfy(predicate);
}
}
public
boolean anySatisfyWith(Predicate2 super T, ? super P> predicate, P parameter)
{
synchronized (this.lock)
{
return this.delegate.anySatisfyWith(predicate, parameter);
}
}
public boolean allSatisfy(Predicate super T> predicate)
{
synchronized (this.lock)
{
return this.delegate.allSatisfy(predicate);
}
}
public
boolean allSatisfyWith(Predicate2 super T, ? super P> predicate, P parameter)
{
synchronized (this.lock)
{
return this.delegate.allSatisfyWith(predicate, parameter);
}
}
public boolean noneSatisfy(Predicate super T> predicate)
{
synchronized (this.lock)
{
return this.delegate.noneSatisfy(predicate);
}
}
public
boolean noneSatisfyWith(Predicate2 super T, ? super P> predicate, P parameter)
{
synchronized (this.lock)
{
return this.delegate.noneSatisfyWith(predicate, parameter);
}
}
public IV injectInto(IV injectedValue, Function2 super IV, ? super T, ? extends IV> function)
{
synchronized (this.lock)
{
return this.delegate.injectInto(injectedValue, function);
}
}
public int injectInto(int injectedValue, IntObjectToIntFunction super T> function)
{
synchronized (this.lock)
{
return this.delegate.injectInto(injectedValue, function);
}
}
public long injectInto(long injectedValue, LongObjectToLongFunction super T> function)
{
synchronized (this.lock)
{
return this.delegate.injectInto(injectedValue, function);
}
}
public float injectInto(float injectedValue, FloatObjectToFloatFunction super T> function)
{
synchronized (this.lock)
{
return this.delegate.injectInto(injectedValue, function);
}
}
public double injectInto(double injectedValue, DoubleObjectToDoubleFunction super T> function)
{
synchronized (this.lock)
{
return this.delegate.injectInto(injectedValue, function);
}
}
public MutableList toList()
{
synchronized (this.lock)
{
return this.delegate.toList();
}
}
public MutableList toSortedList()
{
synchronized (this.lock)
{
return this.delegate.toSortedList();
}
}
public MutableList toSortedList(Comparator super T> comparator)
{
synchronized (this.lock)
{
return this.delegate.toSortedList(comparator);
}
}
public > MutableList toSortedListBy(Function super T, ? extends V> function)
{
synchronized (this.lock)
{
return this.delegate.toSortedList(Comparators.byFunction(function));
}
}
public MutableSet toSet()
{
synchronized (this.lock)
{
return this.delegate.toSet();
}
}
public MutableSortedSet toSortedSet()
{
synchronized (this.lock)
{
return this.delegate.toSortedSet();
}
}
public MutableSortedSet toSortedSet(Comparator super T> comparator)
{
synchronized (this.lock)
{
return this.delegate.toSortedSet(comparator);
}
}
public > MutableSortedSet toSortedSetBy(Function super T, ? extends V> function)
{
synchronized (this.lock)
{
return this.delegate.toSortedSetBy(function);
}
}
public MutableBag toBag()
{
synchronized (this.lock)
{
return this.delegate.toBag();
}
}
public MutableSortedBag toSortedBag()
{
synchronized (this.lock)
{
return this.delegate.toSortedBag();
}
}
public MutableSortedBag toSortedBag(Comparator super T> comparator)
{
synchronized (this.lock)
{
return this.delegate.toSortedBag(comparator);
}
}
public > MutableSortedBag toSortedBagBy(Function super T, ? extends V> function)
{
synchronized (this.lock)
{
return this.delegate.toSortedBag(Comparators.byFunction(function));
}
}
public MutableMap toMap(
Function super T, ? extends NK> keyFunction,
Function super T, ? extends NV> valueFunction)
{
synchronized (this.lock)
{
return this.delegate.toMap(keyFunction, valueFunction);
}
}
public MutableSortedMap toSortedMap(
Function super T, ? extends NK> keyFunction,
Function super T, ? extends NV> valueFunction)
{
synchronized (this.lock)
{
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)
{
synchronized (this.lock)
{
return this.delegate.toSortedMap(comparator, keyFunction, valueFunction);
}
}
public LazyIterable asLazy()
{
return LazyIterate.adapt(this);
}
public Object[] toArray()
{
synchronized (this.lock)
{
return this.delegate.toArray();
}
}
public T[] toArray(T[] a)
{
synchronized (this.lock)
{
return this.delegate.toArray(a);
}
}
public T min(Comparator super T> comparator)
{
synchronized (this.lock)
{
return this.delegate.min(comparator);
}
}
public T max(Comparator super T> comparator)
{
synchronized (this.lock)
{
return this.delegate.max(comparator);
}
}
public T min()
{
synchronized (this.lock)
{
return this.delegate.min();
}
}
public T max()
{
synchronized (this.lock)
{
return this.delegate.max();
}
}
public > T minBy(Function super T, ? extends V> function)
{
synchronized (this.lock)
{
return this.delegate.minBy(function);
}
}
public > T maxBy(Function super T, ? extends V> function)
{
synchronized (this.lock)
{
return this.delegate.maxBy(function);
}
}
public long sumOfInt(IntFunction super T> function)
{
synchronized (this.lock)
{
return this.delegate.sumOfInt(function);
}
}
public double sumOfFloat(FloatFunction super T> function)
{
synchronized (this.lock)
{
return this.delegate.sumOfFloat(function);
}
}
public long sumOfLong(LongFunction super T> function)
{
synchronized (this.lock)
{
return this.delegate.sumOfLong(function);
}
}
public double sumOfDouble(DoubleFunction super T> function)
{
synchronized (this.lock)
{
return this.delegate.sumOfDouble(function);
}
}
public ObjectLongMap sumByInt(Function groupBy, IntFunction super T> function)
{
synchronized (this.lock)
{
return this.delegate.sumByInt(groupBy, function);
}
}
public ObjectDoubleMap sumByFloat(Function groupBy, FloatFunction super T> function)
{
synchronized (this.lock)
{
return this.delegate.sumByFloat(groupBy, function);
}
}
public ObjectLongMap sumByLong(Function groupBy, LongFunction super T> function)
{
synchronized (this.lock)
{
return this.delegate.sumByLong(groupBy, function);
}
}
public ObjectDoubleMap sumByDouble(Function groupBy, DoubleFunction super T> function)
{
synchronized (this.lock)
{
return this.delegate.sumByDouble(groupBy, function);
}
}
public String makeString()
{
synchronized (this.lock)
{
return this.delegate.makeString();
}
}
public String makeString(String separator)
{
synchronized (this.lock)
{
return this.delegate.makeString(separator);
}
}
public String makeString(String start, String separator, String end)
{
synchronized (this.lock)
{
return this.delegate.makeString(start, separator, end);
}
}
public void appendString(Appendable appendable)
{
synchronized (this.lock)
{
this.delegate.appendString(appendable);
}
}
public void appendString(Appendable appendable, String separator)
{
synchronized (this.lock)
{
this.delegate.appendString(appendable, separator);
}
}
public void appendString(Appendable appendable, String start, String separator, String end)
{
synchronized (this.lock)
{
this.delegate.appendString(appendable, start, separator, end);
}
}
public > R groupBy(
Function super T, ? extends V> function,
R target)
{
synchronized (this.lock)
{
return this.delegate.groupBy(function, target);
}
}
public > R groupByEach(
Function super T, ? extends Iterable> function,
R target)
{
synchronized (this.lock)
{
return this.delegate.groupByEach(function, target);
}
}
public MutableMap groupByUniqueKey(Function super T, ? extends V> function)
{
synchronized (this.lock)
{
return this.delegate.groupByUniqueKey(function, UnifiedMap.newMap());
}
}
public > R groupByUniqueKey(
Function super T, ? extends V> function,
R target)
{
synchronized (this.lock)
{
return this.delegate.groupByUniqueKey(function, target);
}
}
public >> R zip(Iterable that, R target)
{
synchronized (this.lock)
{
return this.delegate.zip(that, target);
}
}
public >> R zipWithIndex(R target)
{
synchronized (this.lock)
{
return this.delegate.zipWithIndex(target);
}
}
public RichIterable> chunk(int size)
{
synchronized (this.lock)
{
return this.delegate.chunk(size);
}
}
}