org.eclipse.collections.impl.bag.mutable.UnmodifiableBag Maven / Gradle / Ivy
Show all versions of eclipse-collections Show documentation
/*
* Copyright (c) 2022 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.collections.impl.bag.mutable;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;
import java.util.Collection;
import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.bag.ImmutableBag;
import org.eclipse.collections.api.bag.MutableBag;
import org.eclipse.collections.api.bag.primitive.MutableBooleanBag;
import org.eclipse.collections.api.bag.primitive.MutableByteBag;
import org.eclipse.collections.api.bag.primitive.MutableCharBag;
import org.eclipse.collections.api.bag.primitive.MutableDoubleBag;
import org.eclipse.collections.api.bag.primitive.MutableFloatBag;
import org.eclipse.collections.api.bag.primitive.MutableIntBag;
import org.eclipse.collections.api.bag.primitive.MutableLongBag;
import org.eclipse.collections.api.bag.primitive.MutableShortBag;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.Function2;
import org.eclipse.collections.api.block.function.primitive.BooleanFunction;
import org.eclipse.collections.api.block.function.primitive.ByteFunction;
import org.eclipse.collections.api.block.function.primitive.CharFunction;
import org.eclipse.collections.api.block.function.primitive.DoubleFunction;
import org.eclipse.collections.api.block.function.primitive.FloatFunction;
import org.eclipse.collections.api.block.function.primitive.IntFunction;
import org.eclipse.collections.api.block.function.primitive.LongFunction;
import org.eclipse.collections.api.block.function.primitive.ObjectIntToObjectFunction;
import org.eclipse.collections.api.block.function.primitive.ShortFunction;
import org.eclipse.collections.api.block.predicate.Predicate;
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.block.predicate.primitive.IntPredicate;
import org.eclipse.collections.api.block.predicate.primitive.ObjectIntPredicate;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure;
import org.eclipse.collections.api.factory.Bags;
import org.eclipse.collections.api.factory.primitive.ObjectLongMaps;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.map.primitive.MutableObjectLongMap;
import org.eclipse.collections.api.multimap.bag.MutableBagMultimap;
import org.eclipse.collections.api.ordered.OrderedIterable;
import org.eclipse.collections.api.partition.bag.PartitionMutableBag;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.api.tuple.Pair;
import org.eclipse.collections.api.tuple.primitive.ObjectIntPair;
import org.eclipse.collections.impl.collection.mutable.AbstractUnmodifiableMutableCollection;
/**
* An unmodifiable view of a bag.
*
* @see MutableBag#asUnmodifiable()
* @since 1.0
*/
public class UnmodifiableBag
extends AbstractUnmodifiableMutableCollection
implements MutableBag, Serializable
{
UnmodifiableBag(MutableBag extends T> mutableBag)
{
super(mutableBag);
}
/**
* This method will take a MutableBag and wrap it directly in a UnmodifiableBag.
*/
public static > UnmodifiableBag of(B bag)
{
if (bag == null)
{
throw new IllegalArgumentException("cannot create an UnmodifiableBag for null");
}
return new UnmodifiableBag<>(bag);
}
protected MutableBag getMutableBag()
{
return (MutableBag) this.getMutableCollection();
}
@Override
public MutableBag asUnmodifiable()
{
return this;
}
@Override
public MutableBag asSynchronized()
{
return SynchronizedBag.of(this);
}
@Override
public ImmutableBag toImmutable()
{
return Bags.immutable.withAll(this);
}
@Override
public boolean equals(Object obj)
{
return this.getMutableBag().equals(obj);
}
@Override
public int hashCode()
{
return this.getMutableBag().hashCode();
}
@Override
public String toStringOfItemToCount()
{
return this.getMutableBag().toStringOfItemToCount();
}
@Override
public MutableBag newEmpty()
{
return this.getMutableBag().newEmpty();
}
@Override
public MutableBag selectByOccurrences(IntPredicate predicate)
{
return this.getMutableBag().selectByOccurrences(predicate);
}
@Override
public MutableBag tap(Procedure super T> procedure)
{
this.forEach(procedure);
return this;
}
@Override
public MutableBag select(Predicate super T> predicate)
{
return this.getMutableBag().select(predicate);
}
@Override
public MutableBag selectWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.getMutableBag().selectWith(predicate, parameter);
}
@Override
public MutableBag reject(Predicate super T> predicate)
{
return this.getMutableBag().reject(predicate);
}
@Override
public MutableBag rejectWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.getMutableBag().rejectWith(predicate, parameter);
}
@Override
public PartitionMutableBag partition(Predicate super T> predicate)
{
return this.getMutableBag().partition(predicate);
}
@Override
public PartitionMutableBag partitionWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.getMutableBag().partitionWith(predicate, parameter);
}
@Override
public MutableBag selectInstancesOf(Class clazz)
{
return this.getMutableBag().selectInstancesOf(clazz);
}
@Override
public MutableBag collect(Function super T, ? extends V> function)
{
return this.getMutableBag().collect(function);
}
@Override
public MutableBooleanBag collectBoolean(BooleanFunction super T> booleanFunction)
{
return this.getMutableBag().collectBoolean(booleanFunction);
}
@Override
public MutableByteBag collectByte(ByteFunction super T> byteFunction)
{
return this.getMutableBag().collectByte(byteFunction);
}
@Override
public MutableCharBag collectChar(CharFunction super T> charFunction)
{
return this.getMutableBag().collectChar(charFunction);
}
@Override
public MutableDoubleBag collectDouble(DoubleFunction super T> doubleFunction)
{
return this.getMutableBag().collectDouble(doubleFunction);
}
@Override
public MutableFloatBag collectFloat(FloatFunction super T> floatFunction)
{
return this.getMutableBag().collectFloat(floatFunction);
}
@Override
public MutableIntBag collectInt(IntFunction super T> intFunction)
{
return this.getMutableBag().collectInt(intFunction);
}
@Override
public MutableLongBag collectLong(LongFunction super T> longFunction)
{
return this.getMutableBag().collectLong(longFunction);
}
@Override
public MutableShortBag collectShort(ShortFunction super T> shortFunction)
{
return this.getMutableBag().collectShort(shortFunction);
}
@Override
public MutableBag flatCollect(Function super T, ? extends Iterable> function)
{
return this.getMutableBag().flatCollect(function);
}
@Override
public MutableList> topOccurrences(int count)
{
return this.getMutableBag().topOccurrences(count);
}
@Override
public MutableList> bottomOccurrences(int count)
{
return this.getMutableBag().bottomOccurrences(count);
}
@Override
public MutableBag collectWithOccurrences(ObjectIntToObjectFunction super T, ? extends V> function)
{
return this.getMutableBag().collectWithOccurrences(function, Bags.mutable.empty());
}
@Override
public