com.gs.collections.impl.stack.mutable.primitive.SynchronizedDoubleStack Maven / Gradle / Ivy
Show all versions of gs-collections Show documentation
/*
* Copyright 2014 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.stack.mutable.primitive;
import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import com.gs.collections.api.DoubleIterable;
import com.gs.collections.api.LazyDoubleIterable;
import com.gs.collections.api.bag.primitive.MutableDoubleBag;
import com.gs.collections.api.block.function.primitive.DoubleToObjectFunction;
import com.gs.collections.api.block.function.primitive.ObjectDoubleToObjectFunction;
import com.gs.collections.api.block.predicate.primitive.DoublePredicate;
import com.gs.collections.api.block.procedure.primitive.DoubleProcedure;
import com.gs.collections.api.iterator.DoubleIterator;
import com.gs.collections.api.list.primitive.DoubleList;
import com.gs.collections.api.list.primitive.MutableDoubleList;
import com.gs.collections.api.set.primitive.MutableDoubleSet;
import com.gs.collections.api.stack.MutableStack;
import com.gs.collections.api.stack.primitive.ImmutableDoubleStack;
import com.gs.collections.api.stack.primitive.MutableDoubleStack;
import com.gs.collections.impl.factory.primitive.DoubleStacks;
import com.gs.collections.impl.iterator.UnmodifiableDoubleIterator;
import com.gs.collections.impl.lazy.primitive.LazyDoubleIterableAdapter;
import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.ThreadSafe;
/**
* A synchronized view of a {@link MutableDoubleStack}. It is imperative that the user manually synchronize on the collection when iterating over it using the
* {@link DoubleIterator}, as per {@link Collections#synchronizedCollection(Collection)}.
*
* This file was automatically generated from template file synchronizedPrimitiveStack.stg.
*
* @see MutableDoubleStack#asSynchronized()
* @see MutableStack#asSynchronized()
* @since 3.1.
*/
@ThreadSafe
public final class SynchronizedDoubleStack
implements MutableDoubleStack, Serializable
{
private static final long serialVersionUID = 1L;
private final Object lock;
@GuardedBy("this.lock")
private final MutableDoubleStack stack;
SynchronizedDoubleStack(MutableDoubleStack stack)
{
this(stack, null);
}
SynchronizedDoubleStack(MutableDoubleStack stack, Object newLock)
{
this.stack = stack;
this.lock = newLock == null ? this : newLock;
}
public void push(double item)
{
synchronized (this.lock)
{
this.stack.push(item);
}
}
public double pop()
{
synchronized (this.lock)
{
return this.stack.pop();
}
}
public DoubleList pop(int count)
{
synchronized (this.lock)
{
return this.stack.pop(count);
}
}
public double peek()
{
synchronized (this.lock)
{
return this.stack.peek();
}
}
public DoubleList peek(int count)
{
synchronized (this.lock)
{
return this.stack.peek(count);
}
}
public double peekAt(int index)
{
synchronized (this.lock)
{
return this.stack.peekAt(index);
}
}
public int size()
{
synchronized (this.lock)
{
return this.stack.size();
}
}
public boolean isEmpty()
{
synchronized (this.lock)
{
return this.stack.isEmpty();
}
}
public boolean notEmpty()
{
synchronized (this.lock)
{
return this.stack.notEmpty();
}
}
public void clear()
{
synchronized (this.lock)
{
this.stack.clear();
}
}
public boolean contains(double value)
{
synchronized (this.lock)
{
return this.stack.contains(value);
}
}
public boolean containsAll(double... source)
{
synchronized (this.lock)
{
return this.stack.containsAll(source);
}
}
public boolean containsAll(DoubleIterable source)
{
synchronized (this.lock)
{
return this.stack.containsAll(source);
}
}
/**
* Must be called in a synchronized block.
*/
public DoubleIterator doubleIterator()
{
return new UnmodifiableDoubleIterator(this.stack.doubleIterator());
}
public void forEach(DoubleProcedure procedure)
{
this.each(procedure);
}
/**
* @since 7.0.
*/
public void each(DoubleProcedure procedure)
{
synchronized (this.lock)
{
this.stack.forEach(procedure);
}
}
public int count(DoublePredicate predicate)
{
synchronized (this.lock)
{
return this.stack.count(predicate);
}
}
public boolean anySatisfy(DoublePredicate predicate)
{
synchronized (this.lock)
{
return this.stack.anySatisfy(predicate);
}
}
public boolean allSatisfy(DoublePredicate predicate)
{
synchronized (this.lock)
{
return this.stack.allSatisfy(predicate);
}
}
public boolean noneSatisfy(DoublePredicate predicate)
{
synchronized (this.lock)
{
return this.stack.noneSatisfy(predicate);
}
}
public double detectIfNone(DoublePredicate predicate, double ifNone)
{
synchronized (this.lock)
{
return this.stack.detectIfNone(predicate, ifNone);
}
}
public MutableDoubleStack select(DoublePredicate predicate)
{
synchronized (this.lock)
{
return this.stack.select(predicate);
}
}
public MutableDoubleStack reject(DoublePredicate predicate)
{
synchronized (this.lock)
{
return this.stack.reject(predicate);
}
}
public MutableStack collect(DoubleToObjectFunction extends V> function)
{
synchronized (this.lock)
{
return this.stack.collect(function);
}
}
public double sum()
{
synchronized (this.lock)
{
return this.stack.sum();
}
}
public double max()
{
synchronized (this.lock)
{
return this.stack.max();
}
}
public double min()
{
synchronized (this.lock)
{
return this.stack.min();
}
}
public double minIfEmpty(double defaultValue)
{
synchronized (this.lock)
{
return this.stack.minIfEmpty(defaultValue);
}
}
public double maxIfEmpty(double defaultValue)
{
synchronized (this.lock)
{
return this.stack.maxIfEmpty(defaultValue);
}
}
public double average()
{
synchronized (this.lock)
{
return this.stack.average();
}
}
public double median()
{
synchronized (this.lock)
{
return this.stack.median();
}
}
public MutableDoubleList toSortedList()
{
synchronized (this.lock)
{
return this.stack.toSortedList();
}
}
public double[] toSortedArray()
{
synchronized (this.lock)
{
return this.stack.toSortedArray();
}
}
public double[] toArray()
{
synchronized (this.lock)
{
return this.stack.toArray();
}
}
@Override
public String toString()
{
synchronized (this.lock)
{
return this.stack.toString();
}
}
public String makeString()
{
synchronized (this.lock)
{
return this.stack.makeString();
}
}
public String makeString(String separator)
{
synchronized (this.lock)
{
return this.stack.makeString(separator);
}
}
public String makeString(String start, String separator, String end)
{
synchronized (this.lock)
{
return this.stack.makeString(start, separator, end);
}
}
public void appendString(Appendable appendable)
{
synchronized (this.lock)
{
this.stack.appendString(appendable);
}
}
public void appendString(Appendable appendable, String separator)
{
synchronized (this.lock)
{
this.stack.appendString(appendable, separator);
}
}
public void appendString(
Appendable appendable,
String start,
String separator,
String end)
{
synchronized (this.lock)
{
this.stack.appendString(appendable, start, separator, end);
}
}
public MutableDoubleList toList()
{
synchronized (this.lock)
{
return this.stack.toList();
}
}
public MutableDoubleSet toSet()
{
synchronized (this.lock)
{
return this.stack.toSet();
}
}
public MutableDoubleBag 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();
}
}
public LazyDoubleIterable asLazy()
{
synchronized (this.lock)
{
return new LazyDoubleIterableAdapter(this);
}
}
public MutableDoubleStack asUnmodifiable()
{
return new UnmodifiableDoubleStack(this);
}
public MutableDoubleStack asSynchronized()
{
return this;
}
public ImmutableDoubleStack toImmutable()
{
return DoubleStacks.immutable.withAllReversed(this);
}
public T injectInto(T injectedValue, ObjectDoubleToObjectFunction super T, ? extends T> function)
{
synchronized (this.lock)
{
return this.stack.injectInto(injectedValue, function);
}
}
}