com.gs.collections.impl.set.mutable.UnmodifiableMutableSet 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;
import java.io.Serializable;
import java.util.Collection;
import java.util.Set;
import com.gs.collections.api.LazyIterable;
import com.gs.collections.api.block.function.Function;
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.FloatFunction;
import com.gs.collections.api.block.function.primitive.IntFunction;
import com.gs.collections.api.block.function.primitive.LongFunction;
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.multimap.set.MutableSetMultimap;
import com.gs.collections.api.partition.set.PartitionMutableSet;
import com.gs.collections.api.set.ImmutableSet;
import com.gs.collections.api.set.MutableSet;
import com.gs.collections.api.set.SetIterable;
import com.gs.collections.api.set.UnsortedSetIterable;
import com.gs.collections.api.set.primitive.MutableBooleanSet;
import com.gs.collections.api.set.primitive.MutableByteSet;
import com.gs.collections.api.set.primitive.MutableCharSet;
import com.gs.collections.api.set.primitive.MutableDoubleSet;
import com.gs.collections.api.set.primitive.MutableFloatSet;
import com.gs.collections.api.set.primitive.MutableIntSet;
import com.gs.collections.api.set.primitive.MutableLongSet;
import com.gs.collections.api.set.primitive.MutableShortSet;
import com.gs.collections.api.tuple.Pair;
import com.gs.collections.impl.collection.mutable.AbstractUnmodifiableMutableCollection;
import com.gs.collections.impl.collection.mutable.UnmodifiableCollectionSerializationProxy;
import com.gs.collections.impl.factory.Sets;
/**
* An unmodifiable view of a list.
*
* @see MutableSet#asUnmodifiable()
*/
public class UnmodifiableMutableSet
extends AbstractUnmodifiableMutableCollection
implements MutableSet, Serializable
{
UnmodifiableMutableSet(MutableSet extends T> mutableSet)
{
super(mutableSet);
}
/**
* This method will take a MutableSet and wrap it directly in a UnmodifiableMutableSet. It will
* take any other non-GS-set and first adapt it will a SetAdapter, and then return a
* UnmodifiableMutableSet that wraps the adapter.
*/
public static > UnmodifiableMutableSet of(S set)
{
if (set == null)
{
throw new IllegalArgumentException("cannot create an UnmodifiableMutableSet for null");
}
return new UnmodifiableMutableSet(SetAdapter.adapt(set));
}
protected MutableSet getMutableSet()
{
return (MutableSet) this.getMutableCollection();
}
@Override
public MutableSet asUnmodifiable()
{
return this;
}
@Override
public MutableSet asSynchronized()
{
return SynchronizedMutableSet.of(this);
}
@Override
public ImmutableSet toImmutable()
{
return Sets.immutable.ofAll(this.getMutableSet());
}
@Override
public boolean equals(Object obj)
{
return this.getMutableSet().equals(obj);
}
@Override
public int hashCode()
{
return this.getMutableSet().hashCode();
}
@Override
public UnmodifiableMutableSet clone()
{
return this;
}
@Override
public MutableSet newEmpty()
{
return this.getMutableSet().newEmpty();
}
@Override
public MutableSet select(Predicate super T> predicate)
{
return this.getMutableSet().select(predicate);
}
@Override
public MutableSet selectWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.getMutableSet().selectWith(predicate, parameter);
}
@Override
public MutableSet reject(Predicate super T> predicate)
{
return this.getMutableSet().reject(predicate);
}
@Override
public MutableSet rejectWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.getMutableSet().rejectWith(predicate, parameter);
}
@Override
public PartitionMutableSet partition(Predicate super T> predicate)
{
return this.getMutableSet().partition(predicate);
}
@Override
public PartitionMutableSet partitionWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.getMutableSet().partitionWith(predicate, parameter);
}
@Override
public MutableSet selectInstancesOf(Class clazz)
{
return this.getMutableSet().selectInstancesOf(clazz);
}
@Override
public MutableSet collect(Function super T, ? extends V> function)
{
return this.getMutableSet().collect(function);
}
@Override
public MutableBooleanSet collectBoolean(BooleanFunction super T> booleanFunction)
{
return this.getMutableSet().collectBoolean(booleanFunction);
}
@Override
public MutableByteSet collectByte(ByteFunction super T> byteFunction)
{
return this.getMutableSet().collectByte(byteFunction);
}
@Override
public MutableCharSet collectChar(CharFunction super T> charFunction)
{
return this.getMutableSet().collectChar(charFunction);
}
@Override
public MutableDoubleSet collectDouble(DoubleFunction super T> doubleFunction)
{
return this.getMutableSet().collectDouble(doubleFunction);
}
@Override
public MutableFloatSet collectFloat(FloatFunction super T> floatFunction)
{
return this.getMutableSet().collectFloat(floatFunction);
}
@Override
public MutableIntSet collectInt(IntFunction super T> intFunction)
{
return this.getMutableSet().collectInt(intFunction);
}
@Override
public MutableLongSet collectLong(LongFunction super T> longFunction)
{
return this.getMutableSet().collectLong(longFunction);
}
@Override
public MutableShortSet collectShort(ShortFunction super T> shortFunction)
{
return this.getMutableSet().collectShort(shortFunction);
}
@Override
public MutableSet flatCollect(Function super T, ? extends Iterable> function)
{
return this.getMutableSet().flatCollect(function);
}
@Override
public