package org.eclipse.collections.impl.primitive;
import java.io.Serializable;
import org.eclipse.collections.api.BooleanIterable;
import org.eclipse.collections.api.LazyBooleanIterable;
import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.bag.primitive.MutableBooleanBag;
import org.eclipse.collections.api.block.function.primitive.BooleanBooleanToBooleanFunction;
import org.eclipse.collections.api.block.function.primitive.BooleanToObjectFunction;
import org.eclipse.collections.api.block.function.primitive.ObjectBooleanToObjectFunction;
import org.eclipse.collections.api.block.predicate.primitive.BooleanPredicate;
import org.eclipse.collections.api.block.procedure.primitive.BooleanProcedure;
import org.eclipse.collections.api.iterator.BooleanIterator;
import org.eclipse.collections.api.list.primitive.MutableBooleanList;
import org.eclipse.collections.api.set.primitive.MutableBooleanSet;
public class SynchronizedBooleanIterable implements BooleanIterable, Serializable
{
private static final long serialVersionUID = 1L;
private final Object lock;
private final BooleanIterable iterable;
protected SynchronizedBooleanIterable(BooleanIterable iterable)
{
this(iterable, null);
}
protected SynchronizedBooleanIterable(BooleanIterable iterable, Object newLock)
{
if (iterable == null)
{
throw new IllegalArgumentException("Cannot create a SynchronizedBooleanIterable on a null collection");
}
this.iterable = iterable;
this.lock = newLock == null ? this : newLock;
}
public static SynchronizedBooleanIterable of(BooleanIterable iterable)
{
return new SynchronizedBooleanIterable(iterable);
}
public static SynchronizedBooleanIterable of(BooleanIterable iterable, Object lock)
{
return new SynchronizedBooleanIterable(iterable, lock);
}
@Override
public boolean[] toArray()
{
synchronized (this.lock)
{
return this.iterable.toArray();
}
}
@Override
public boolean[] toArray(boolean[] target)
{
synchronized (this.lock)
{
return this.iterable.toArray(target);
}
}
@Override
public boolean contains(boolean value)
{
synchronized (this.lock)
{
return this.iterable.contains(value);
}
}
@Override
public boolean containsAll(boolean... source)
{
synchronized (this.lock)
{
return this.iterable.containsAll(source);
}
}
@Override
public boolean containsAll(BooleanIterable source)
{
synchronized (this.lock)
{
return this.iterable.containsAll(source);
}
}
@Override
public void forEach(BooleanProcedure procedure)
{
this.each(procedure);
}
@Override
public void each(BooleanProcedure procedure)
{
synchronized (this.lock)
{
this.iterable.forEach(procedure);
}
}
@Override
public BooleanIterable select(BooleanPredicate predicate)
{
synchronized (this.lock)
{
return this.iterable.select(predicate);
}
}
@Override
public BooleanIterable reject(BooleanPredicate predicate)
{
synchronized (this.lock)
{
return this.iterable.reject(predicate);
}
}
@Override
public <V> RichIterable<V> collect(BooleanToObjectFunction<? extends V> function)
{
synchronized (this.lock)
{
return this.iterable.collect(function);
}
}
@Override
public boolean detectIfNone(BooleanPredicate predicate, boolean ifNone)
{
synchronized (this.lock)
{
return this.iterable.detectIfNone(predicate, ifNone);
}
}
@Override
public int count(BooleanPredicate predicate)
{
synchronized (this.lock)
{
return this.iterable.count(predicate);
}
}
@Override
public boolean anySatisfy(BooleanPredicate predicate)
{
synchronized (this.lock)
{
return this.iterable.anySatisfy(predicate);
}
}
@Override
public boolean allSatisfy(BooleanPredicate predicate)
{
synchronized (this.lock)
{
return this.iterable.allSatisfy(predicate);
}
}
@Override
public boolean noneSatisfy(BooleanPredicate predicate)
{
synchronized (this.lock)
{
return this.iterable.noneSatisfy(predicate);
}
}
@Override
public MutableBooleanList toList()
{
synchronized (this.lock)
{
return this.iterable.toList();
}
}
@Override
public MutableBooleanSet toSet()
{
synchronized (this.lock)
{
return this.iterable.toSet();
}
}
@Override
public MutableBooleanBag toBag()
{
synchronized (this.lock)
{
return this.iterable.toBag();
}
}
@Override
public LazyBooleanIterable asLazy()
{
synchronized (this.lock)
{
return this.iterable.asLazy();
}
}
@Override
public int size()
{
synchronized (this.lock)
{
return this.iterable.size();
}
}
@Override
public boolean isEmpty()
{
synchronized (this.lock)
{
return this.iterable.isEmpty();
}
}
@Override
public boolean notEmpty()
{
synchronized (this.lock)
{
return this.iterable.notEmpty();
}
}
@Override
public <T> T injectInto(T injectedValue, ObjectBooleanToObjectFunction<? super T, ? extends T> function)
{
synchronized (this.lock)
{
return this.iterable.injectInto(injectedValue, function);
}
}
@Override
public boolean reduce(BooleanBooleanToBooleanFunction accumulator)
{
synchronized (this.lock)
{
return this.iterable.reduce(accumulator);
}
}
@Override
public boolean reduceIfEmpty(BooleanBooleanToBooleanFunction accumulator, boolean defaultValue)
{
synchronized (this.lock)
{
return this.iterable.reduceIfEmpty(accumulator, defaultValue);
}
}
@Override
public RichIterable<BooleanIterable> chunk(int size)
{
synchronized (this.lock)
{
return this.iterable.chunk(size);
}
}
@Override
public String toString()
{
synchronized (this.lock)
{
return this.iterable.toString();
}
}
@Override
public String makeString()
{
synchronized (this.lock)
{
return this.iterable.makeString();
}
}
@Override
public String makeString(String separator)
{
synchronized (this.lock)
{
return this.iterable.makeString(separator);
}
}
@Override
public String makeString(String start, String separator, String end)
{
synchronized (this.lock)
{
return this.iterable.makeString(start, separator, end);
}
}
@Override
public void appendString(Appendable appendable)
{
synchronized (this.lock)
{
this.iterable.appendString(appendable);
}
}
@Override
public void appendString(Appendable appendable, String separator)
{
synchronized (this.lock)
{
this.iterable.appendString(appendable, separator);
}
}
@Override
public void appendString(Appendable appendable, String start, String separator, String end)
{
synchronized (this.lock)
{
this.iterable.appendString(appendable, start, separator, end);
}
}
@Override
public BooleanIterator booleanIterator()
{
return this.iterable.booleanIterator();
}
}