com.gs.collections.impl.set.mutable.primitive.SynchronizedByteSet 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.set.mutable.primitive;
import java.util.Collection;
import java.util.Collections;
import com.gs.collections.api.ByteIterable;
import com.gs.collections.api.LazyByteIterable;
import com.gs.collections.api.block.function.primitive.ByteToObjectFunction;
import com.gs.collections.api.block.predicate.primitive.BytePredicate;
import com.gs.collections.api.iterator.ByteIterator;
import com.gs.collections.api.set.MutableSet;
import com.gs.collections.api.set.primitive.ImmutableByteSet;
import com.gs.collections.api.set.primitive.ByteSet;
import com.gs.collections.api.set.primitive.MutableByteSet;
import com.gs.collections.impl.collection.mutable.primitive.AbstractSynchronizedByteCollection;
import com.gs.collections.impl.lazy.primitive.LazyByteIterableAdapter;
import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.ThreadSafe;
/**
* A synchronized view of a {@link MutableByteSet}. It is imperative that the user manually synchronize on the collection when iterating over it using the
* {@link ByteIterator}, as per {@link Collections#synchronizedCollection(Collection)}.
*
* This file was automatically generated from template file synchronizedPrimitiveSet.stg.
*
* @see MutableByteSet#asSynchronized()
* @see MutableSet#asSynchronized()
* @since 3.1.
*/
@ThreadSafe
public final class SynchronizedByteSet
extends AbstractSynchronizedByteCollection
implements MutableByteSet
{
private static final long serialVersionUID = 1L;
SynchronizedByteSet(MutableByteSet set)
{
super(set);
}
SynchronizedByteSet(MutableByteSet set, Object newLock)
{
super(set, newLock);
}
/**
* This method will take a MutableByteSet and wrap it directly in a SynchronizedByteSet.
*/
public static SynchronizedByteSet of(MutableByteSet set)
{
return new SynchronizedByteSet(set);
}
/**
* This method will take a MutableByteSet and wrap it directly in a SynchronizedByteSet.
* Additionally, a developer specifies which lock to use with the collection.
*/
public static SynchronizedByteSet of(MutableByteSet set, Object lock)
{
return new SynchronizedByteSet(set, lock);
}
@GuardedBy("getLock()")
private MutableByteSet getMutableByteSet()
{
return (MutableByteSet) this.getByteCollection();
}
@Override
public SynchronizedByteSet without(byte element)
{
synchronized (this.getLock())
{
this.getMutableByteSet().remove(element);
}
return this;
}
@Override
public SynchronizedByteSet with(byte element)
{
synchronized (this.getLock())
{
this.getMutableByteSet().add(element);
}
return this;
}
@Override
public SynchronizedByteSet withAll(ByteIterable elements)
{
synchronized (this.getLock())
{
this.getMutableByteSet().addAll(elements.toArray());
}
return this;
}
@Override
public SynchronizedByteSet withoutAll(ByteIterable elements)
{
synchronized (this.getLock())
{
this.getMutableByteSet().removeAll(elements);
}
return this;
}
@Override
public MutableByteSet select(BytePredicate predicate)
{
synchronized (this.getLock())
{
return this.getMutableByteSet().select(predicate);
}
}
@Override
public MutableByteSet reject(BytePredicate predicate)
{
synchronized (this.getLock())
{
return this.getMutableByteSet().reject(predicate);
}
}
@Override
public MutableSet collect(ByteToObjectFunction extends V> function)
{
synchronized (this.getLock())
{
return this.getMutableByteSet().collect(function);
}
}
@Override
public boolean equals(Object otherSet)
{
synchronized (this.getLock())
{
return this.getMutableByteSet().equals(otherSet);
}
}
@Override
public int hashCode()
{
synchronized (this.getLock())
{
return this.getMutableByteSet().hashCode();
}
}
@Override
public LazyByteIterable asLazy()
{
synchronized (this.getLock())
{
return new LazyByteIterableAdapter(this);
}
}
@Override
public MutableByteSet asUnmodifiable()
{
return new UnmodifiableByteSet(this);
}
@Override
public MutableByteSet asSynchronized()
{
return this;
}
public ByteSet freeze()
{
synchronized (this.getLock())
{
return this.getMutableByteSet().freeze();
}
}
@Override
public ImmutableByteSet toImmutable()
{
synchronized (this.getLock())
{
return this.getMutableByteSet().toImmutable();
}
}
}