package org.eclipse.collections.impl.stack.mutable.primitive;
import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
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.BooleanIntToObjectFunction;
import org.eclipse.collections.api.block.function.primitive.BooleanToObjectFunction;
import org.eclipse.collections.api.block.function.primitive.ObjectBooleanToObjectFunction;
import org.eclipse.collections.api.block.function.primitive.ObjectBooleanIntToObjectFunction;
import org.eclipse.collections.api.block.predicate.primitive.BooleanPredicate;
import org.eclipse.collections.api.block.procedure.primitive.BooleanIntProcedure;
import org.eclipse.collections.api.block.procedure.primitive.BooleanProcedure;
import org.eclipse.collections.api.iterator.BooleanIterator;
import org.eclipse.collections.api.list.primitive.BooleanList;
import org.eclipse.collections.api.list.primitive.MutableBooleanList;
import org.eclipse.collections.api.set.primitive.MutableBooleanSet;
import org.eclipse.collections.api.stack.MutableStack;
import org.eclipse.collections.api.stack.primitive.ImmutableBooleanStack;
import org.eclipse.collections.api.stack.primitive.MutableBooleanStack;
import org.eclipse.collections.impl.factory.primitive.BooleanStacks;
import org.eclipse.collections.impl.iterator.UnmodifiableBooleanIterator;
import org.eclipse.collections.impl.lazy.primitive.LazyBooleanIterableAdapter;
public class SynchronizedBooleanStack
implements MutableBooleanStack, Serializable
{
private static final long serialVersionUID = 1L;
private final Object lock;
private final MutableBooleanStack stack;
public SynchronizedBooleanStack(MutableBooleanStack stack)
{
this(stack, null);
}
public SynchronizedBooleanStack(MutableBooleanStack stack, Object newLock)
{
this.stack = stack;
this.lock = newLock == null ? this : newLock;
}
@Override
public void push(boolean item)
{
synchronized (this.lock)
{
this.stack.push(item);
}
}
@Override
public boolean pop()
{
synchronized (this.lock)
{
return this.stack.pop();
}
}
@Override
public BooleanList pop(int count)
{
synchronized (this.lock)
{
return this.stack.pop(count);
}
}
@Override
public boolean peek()
{
synchronized (this.lock)
{
return this.stack.peek();
}
}
@Override
public BooleanList peek(int count)
{
synchronized (this.lock)
{
return this.stack.peek(count);
}
}
@Override
public boolean peekAt(int index)
{
synchronized (this.lock)
{
return this.stack.peekAt(index);
}
}
@Override
public int size()
{
synchronized (this.lock)
{
return this.stack.size();
}
}
@Override
public boolean isEmpty()
{
synchronized (this.lock)
{
return this.stack.isEmpty();
}
}
@Override
public boolean notEmpty()
{
synchronized (this.lock)
{
return this.stack.notEmpty();
}
}
@Override
public void clear()
{
synchronized (this.lock)
{
this.stack.clear();
}
}
@Override
public boolean contains(boolean value)
{
synchronized (this.lock)
{
return this.stack.contains(value);
}
}
@Override
public boolean containsAll(boolean... source)
{
synchronized (this.lock)
{
return this.stack.containsAll(source);
}
}
@Override
public boolean containsAll(BooleanIterable source)
{
synchronized (this.lock)
{
return this.stack.containsAll(source);
}
}
@Override
public BooleanIterator booleanIterator()
{
return new UnmodifiableBooleanIterator(this.stack.booleanIterator());
}
@Override
public void forEach(BooleanProcedure procedure)
{
this.each(procedure);
}
@Override
public void each(BooleanProcedure procedure)
{
synchronized (this.lock)
{
this.stack.forEach(procedure);
}
}
@Override
public int count(BooleanPredicate predicate)
{
synchronized (this.lock)
{
return this.stack.count(predicate);
}
}
@Override
public boolean anySatisfy(BooleanPredicate predicate)
{
synchronized (this.lock)
{
return this.stack.anySatisfy(predicate);
}
}
@Override
public boolean allSatisfy(BooleanPredicate predicate)
{
synchronized (this.lock)
{
return this.stack.allSatisfy(predicate);
}
}
@Override
public boolean noneSatisfy(BooleanPredicate predicate)
{
synchronized (this.lock)
{
return this.stack.noneSatisfy(predicate);
}
}
@Override
public boolean detectIfNone(BooleanPredicate predicate, boolean ifNone)
{
synchronized (this.lock)
{
return this.stack.detectIfNone(predicate, ifNone);
}
}
@Override
public MutableBooleanStack select(BooleanPredicate predicate)
{
synchronized (this.lock)
{
return this.stack.select(predicate);
}
}
@Override
public MutableBooleanStack reject(BooleanPredicate predicate)
{
synchronized (this.lock)
{
return this.stack.reject(predicate);
}
}
@Override
public <V> MutableStack<V> collect(BooleanToObjectFunction<? extends V> function)
{
synchronized (this.lock)
{
return this.stack.collect(function);
}
}
@Override
public boolean[] toArray()
{
synchronized (this.lock)
{
return this.stack.toArray();
}
}
@Override
public String toString()
{
synchronized (this.lock)
{
return this.stack.toString();
}
}
@Override
public String makeString()
{
synchronized (this.lock)
{
return this.stack.makeString();
}
}
@Override
public String makeString(String separator)
{
synchronized (this.lock)
{
return this.stack.makeString(separator);
}
}
@Override
public String makeString(String start, String separator, String end)
{
synchronized (this.lock)
{
return this.stack.makeString(start, separator, end);
}
}
@Override
public void appendString(Appendable appendable)
{
synchronized (this.lock)
{
this.stack.appendString(appendable);
}
}
@Override
public void appendString(Appendable appendable, String separator)
{
synchronized (this.lock)
{
this.stack.appendString(appendable, separator);
}
}
@Override
public void appendString(
Appendable appendable,
String start,
String separator,
String end)
{
synchronized (this.lock)
{
this.stack.appendString(appendable, start, separator, end);
}
}
@Override
public MutableBooleanList toList()
{
synchronized (this.lock)
{
return this.stack.toList();
}
}
@Override
public MutableBooleanSet toSet()
{
synchronized (this.lock)
{
return this.stack.toSet();
}
}
@Override
public MutableBooleanBag toBag()
{
synchronized (this.lock)
{
return this.stack.toBag();
}
}
@Override
public boolean equals(Object otherStack)
{
synchronized (this.lock)
{
return this.stack.equals(otherStack);
}
}
@Override
public int hashCode()
{
synchronized (this.lock)
{
return this.stack.hashCode();
}
}
@Override
public LazyBooleanIterable asLazy()
{
synchronized (this.lock)
{
return new LazyBooleanIterableAdapter(this);
}
}
@Override
public MutableBooleanStack asUnmodifiable()
{
synchronized (this.lock)
{
return new UnmodifiableBooleanStack(this);
}
}
@Override
public MutableBooleanStack asSynchronized()
{
return this;
}
@Override
public ImmutableBooleanStack toImmutable()
{
synchronized (this.lock)
{
return BooleanStacks.immutable.withAllReversed(this);
}
}
public MutableBooleanStack newEmpty()
{
synchronized (this.lock)
{
return this.stack.newEmpty();
}
}
@Override
public <T> T injectInto(T injectedValue, ObjectBooleanToObjectFunction<? super T, ? extends T> function)
{
synchronized (this.lock)
{
return this.stack.injectInto(injectedValue, function);
}
}
@Override
public RichIterable<BooleanIterable> chunk(int size)
{
synchronized (this.lock)
{
return this.stack.chunk(size);
}
}
@Override
public boolean getFirst()
{
synchronized (this.lock)
{
return this.stack.getFirst();
}
}
@Override
public int indexOf(boolean value)
{
synchronized (this.lock)
{
return this.stack.indexOf(value);
}
}
@Override
public <T> T injectIntoWithIndex(T injectedValue, ObjectBooleanIntToObjectFunction<? super T, ? extends T> function)
{
synchronized (this.lock)
{
return this.stack.injectIntoWithIndex(injectedValue, function);
}
}
@Override
public void forEachWithIndex(BooleanIntProcedure procedure)
{
synchronized (this.lock)
{
this.stack.forEachWithIndex(procedure);
}
}
@Override
public <V> MutableStack<V> collectWithIndex(BooleanIntToObjectFunction<? extends V> function)
{
synchronized (this.lock)
{
return this.stack.collectWithIndex(function);
}
}
public <V, R extends Collection<V>> R collectWithIndex(BooleanIntToObjectFunction<? extends V> function, R target)
{
synchronized (this.lock)
{
return this.stack.collectWithIndex(function, target);
}
}
}