org.eclipse.collections.impl.bag.mutable.MultiReaderHashBag 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.util.Collection;
import java.util.Iterator;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.bag.ImmutableBag;
import org.eclipse.collections.api.bag.MultiReaderBag;
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.AbstractMultiReaderMutableCollection;
import org.eclipse.collections.impl.factory.Iterables;
/**
* MultiReaderHashBag provides a thread-safe wrapper around a HashBag, using a ReentrantReadWriteLock. In order to
* provide true thread-safety, MultiReaderHashBag does not implement {@code iterator()} as this method requires an external lock
* to be taken to provide thread-safe iteration. All of these methods are available however, if you use the
* {@code withReadLockAndDelegate()} or {@code withWriteLockAndDelegate()} methods. Both of these methods take a parameter of type
* {@code Procedure}, and a wrapped version of the underlying HashBag is returned. This wrapper guarantees that
* no external pointer can ever reference the underlying HashBag outside a locked procedure. In the case of the
* read lock method, an Unmodifiable version of the collection is offered, which will throw UnsupportedOperationExceptions
* on any write methods like add or remove.
*/
public final class MultiReaderHashBag
extends AbstractMultiReaderMutableCollection
implements Externalizable, MultiReaderBag
{
private static final long serialVersionUID = 1L;
private MutableBag delegate;
/**
* @deprecated Empty default constructor used for serialization.
*/
@SuppressWarnings("UnusedDeclaration")
@Deprecated
public MultiReaderHashBag()
{
// For Externalizable use only
}
private MultiReaderHashBag(MutableBag newDelegate)
{
this(newDelegate, new ReentrantReadWriteLock());
}
private MultiReaderHashBag(MutableBag newDelegate, ReadWriteLock newLock)
{
this.lock = newLock;
this.lockWrapper = new ReadWriteLockWrapper(newLock);
this.delegate = newDelegate;
}
public static MultiReaderHashBag newBag()
{
return new MultiReaderHashBag<>(HashBag.newBag());
}
public static MultiReaderHashBag newBag(int capacity)
{
return new MultiReaderHashBag<>(HashBag.newBag(capacity));
}
public static MultiReaderHashBag newBag(Iterable iterable)
{
return new MultiReaderHashBag<>(HashBag.newBag(iterable));
}
public static MultiReaderHashBag newBagWith(T... elements)
{
return new MultiReaderHashBag<>(HashBag.newBagWith(elements));
}
@Override
protected MutableBag getDelegate()
{
return this.delegate;
}
UntouchableMutableBag asReadUntouchable()
{
return new UntouchableMutableBag<>(this.delegate.asUnmodifiable());
}
UntouchableMutableBag asWriteUntouchable()
{
return new UntouchableMutableBag<>(this.delegate);
}
@Override
public void withReadLockAndDelegate(Procedure super MutableBag> procedure)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
UntouchableMutableBag bag = this.asReadUntouchable();
procedure.value(bag);
bag.becomeUseless();
}
}
@Override
public void withWriteLockAndDelegate(Procedure super MutableBag> procedure)
{
try (LockWrapper wrapper = this.lockWrapper.acquireWriteLock())
{
UntouchableMutableBag bag = this.asWriteUntouchable();
procedure.value(bag);
bag.becomeUseless();
}
}
@Override
public MutableBag asSynchronized()
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return SynchronizedBag.of(this);
}
}
@Override
public MutableBag asUnmodifiable()
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return UnmodifiableBag.of(this);
}
}
@Override
public ImmutableBag toImmutable()
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return Bags.immutable.withAll(this.delegate);
}
}
@Override
public int addOccurrences(T item, int occurrences)
{
try (LockWrapper wrapper = this.lockWrapper.acquireWriteLock())
{
return this.delegate.addOccurrences(item, occurrences);
}
}
@Override
public boolean removeOccurrences(Object item, int occurrences)
{
try (LockWrapper wrapper = this.lockWrapper.acquireWriteLock())
{
return this.delegate.removeOccurrences(item, occurrences);
}
}
@Override
public boolean setOccurrences(T item, int occurrences)
{
try (LockWrapper wrapper = this.lockWrapper.acquireWriteLock())
{
return this.delegate.setOccurrences(item, occurrences);
}
}
@Override
public int occurrencesOf(Object item)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.occurrencesOf(item);
}
}
@Override
public int sizeDistinct()
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.sizeDistinct();
}
}
@Override
public MutableBag collect(Function super T, ? extends V> function)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.collect(function);
}
}
@Override
public MutableBooleanBag collectBoolean(BooleanFunction super T> booleanFunction)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.collectBoolean(booleanFunction);
}
}
@Override
public MutableByteBag collectByte(ByteFunction super T> byteFunction)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.collectByte(byteFunction);
}
}
@Override
public MutableCharBag collectChar(CharFunction super T> charFunction)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.collectChar(charFunction);
}
}
@Override
public MutableDoubleBag collectDouble(DoubleFunction super T> doubleFunction)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.collectDouble(doubleFunction);
}
}
@Override
public MutableFloatBag collectFloat(FloatFunction super T> floatFunction)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.collectFloat(floatFunction);
}
}
@Override
public MutableIntBag collectInt(IntFunction super T> intFunction)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.collectInt(intFunction);
}
}
@Override
public MutableLongBag collectLong(LongFunction super T> longFunction)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.collectLong(longFunction);
}
}
@Override
public MutableShortBag collectShort(ShortFunction super T> shortFunction)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.collectShort(shortFunction);
}
}
@Override
public MutableBag flatCollect(
Function super T, ? extends Iterable> function)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.flatCollect(function);
}
}
@Override
public MutableList> topOccurrences(int count)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.topOccurrences(count);
}
}
@Override
public MutableList> bottomOccurrences(int count)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.bottomOccurrences(count);
}
}
@Override
public MutableBag collectIf(
Predicate super T> predicate,
Function super T, ? extends V> function)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.collectIf(predicate, function);
}
}
@Override
public MutableBag collectWithOccurrences(ObjectIntToObjectFunction super T, ? extends V> function)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.collectWithOccurrences(function, Bags.mutable.empty());
}
}
@Override
public > R collectWithOccurrences(
ObjectIntToObjectFunction super T, ? extends V> function,
R target)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
this.forEachWithOccurrences((each, occurrences) -> target.add(function.valueOf(each, occurrences)));
return target;
}
}
@Override
public MutableBag collectWith(
Function2 super T, ? super P, ? extends V> function,
P parameter)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.collectWith(function, parameter);
}
}
@Override
public MutableBag newEmpty()
{
return MultiReaderHashBag.newBag();
}
@Override
public MutableBag reject(Predicate super T> predicate)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.reject(predicate);
}
}
@Override
public MutableBag rejectWith(
Predicate2 super T, ? super P> predicate,
P parameter)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.rejectWith(predicate, parameter);
}
}
@Override
public MutableBag tap(Procedure super T> procedure)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
this.forEach(procedure);
return this;
}
}
@Override
public MutableBag select(Predicate super T> predicate)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.select(predicate);
}
}
@Override
public MutableBag selectWith(
Predicate2 super T, ? super P> predicate,
P parameter)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.selectWith(predicate, parameter);
}
}
@Override
public MutableBag selectByOccurrences(IntPredicate predicate)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.selectByOccurrences(predicate);
}
}
@Override
public MutableBag selectInstancesOf(Class clazz)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.selectInstancesOf(clazz);
}
}
@Override
public PartitionMutableBag partition(Predicate super T> predicate)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.partition(predicate);
}
}
@Override
public PartitionMutableBag partitionWith(Predicate2 super T, ? super P> predicate, P parameter)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.partitionWith(predicate, parameter);
}
}
@Override
public MutableMap toMapOfItemToCount()
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.toMapOfItemToCount();
}
}
@Override
public String toStringOfItemToCount()
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.toStringOfItemToCount();
}
}
@Override
public MutableBagMultimap groupBy(Function super T, ? extends V> function)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.groupBy(function);
}
}
@Override
public MutableBagMultimap groupByEach(Function super T, ? extends Iterable> function)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.groupByEach(function);
}
}
@Override
public MutableMap groupByUniqueKey(Function super T, ? extends V> function)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.groupByUniqueKey(function);
}
}
/**
* @deprecated in 6.0. Use {@link OrderedIterable#zip(Iterable)} instead.
*/
@Override
@Deprecated
public MutableBag> zip(Iterable that)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.zip(that);
}
}
/**
* @deprecated in 6.0. Use {@link OrderedIterable#zipWithIndex()} instead.
*/
@Override
@Deprecated
public MutableSet> zipWithIndex()
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.zipWithIndex();
}
}
@Override
public RichIterable> chunk(int size)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.chunk(size);
}
}
@Override
public boolean anySatisfyWithOccurrences(ObjectIntPredicate super T> predicate)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.anySatisfyWithOccurrences(predicate);
}
}
@Override
public boolean allSatisfyWithOccurrences(ObjectIntPredicate super T> predicate)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.allSatisfyWithOccurrences(predicate);
}
}
@Override
public boolean noneSatisfyWithOccurrences(ObjectIntPredicate super T> predicate)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.noneSatisfyWithOccurrences(predicate);
}
}
@Override
public T detectWithOccurrences(ObjectIntPredicate super T> predicate)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.detectWithOccurrences(predicate);
}
}
@Override
public MutableObjectLongMap sumByInt(Function super T, ? extends V> groupBy, IntFunction super T> function)
{
MutableObjectLongMap result = ObjectLongMaps.mutable.empty();
this.forEachWithOccurrences((each, occurrences) -> result.addToValue(
groupBy.valueOf(each),
function.intValueOf(each) * (long) occurrences));
return result;
}
@Override
public MutableObjectLongMap sumByLong(Function super T, ? extends V> groupBy, LongFunction super T> function)
{
MutableObjectLongMap result = ObjectLongMaps.mutable.empty();
this.forEachWithOccurrences((each, occurrences) -> result.addToValue(
groupBy.valueOf(each),
function.longValueOf(each) * (long) occurrences));
return result;
}
@Override
public void forEachWithOccurrences(ObjectIntProcedure super T> procedure)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
this.delegate.forEachWithOccurrences(procedure);
}
}
@Override
public boolean equals(Object o)
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.equals(o);
}
}
@Override
public int hashCode()
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.delegate.hashCode();
}
}
@Override
public void writeExternal(ObjectOutput out) throws IOException
{
out.writeObject(this.delegate);
}
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
this.delegate = (MutableBag) in.readObject();
this.lock = new ReentrantReadWriteLock();
this.lockWrapper = new ReadWriteLockWrapper(this.lock);
}
@Override
public MutableSet selectUnique()
{
try (LockWrapper wrapper = this.lockWrapper.acquireReadLock())
{
return this.getDelegate().selectUnique();
}
}
@Override
public RichIterable distinctView()
{
throw new UnsupportedOperationException(
"distinctView is not supported directly on MultiReader collections. "
+ "If you would like to use such as view, you must either use withReadLockAndDelegate() or withWriteLockAndDelegate().");
}
//Exposed for testing
static final class UntouchableMutableBag
extends UntouchableMutableCollection
implements MutableBag
{
private final MutableList> requestedIterators = Iterables.mList();
private UntouchableMutableBag(MutableBag newDelegate)
{
super(newDelegate);
}
@Override
protected MutableBag getDelegate()
{
return (MutableBag) this.delegate;
}
public void becomeUseless()
{
this.delegate = null;
this.requestedIterators.each(UntouchableIterator::becomeUseless);
}
@Override
public MutableBag with(T element)
{
this.add(element);
return this;
}
@Override
public MutableBag without(T element)
{
this.remove(element);
return this;
}
@Override
public MutableBag withAll(Iterable extends T> elements)
{
this.addAllIterable(elements);
return this;
}
@Override
public MutableBag withoutAll(Iterable extends T> elements)
{
this.removeAllIterable(elements);
return this;
}
@Override
public MutableBag asSynchronized()
{
throw new UnsupportedOperationException("cannot wrap an UntouchableMutableBag");
}
@Override
public MutableBag asUnmodifiable()
{
throw new UnsupportedOperationException("cannot wrap an UntouchableMutableBag");
}
@Override
public RichIterable distinctView()
{
throw new UnsupportedOperationException("cannot wrap an UntouchableMutableBag");
}
@Override
public ImmutableBag toImmutable()
{
return Bags.immutable.withAll(this.getDelegate());
}
@Override
public Iterator iterator()
{
UntouchableIterator iterator = new UntouchableIterator<>(this.delegate.iterator());
this.requestedIterators.add(iterator);
return iterator;
}
@Override
public int addOccurrences(T item, int occurrences)
{
return this.getDelegate().addOccurrences(item, occurrences);
}
@Override
public boolean removeOccurrences(Object item, int occurrences)
{
return this.getDelegate().removeOccurrences(item, occurrences);
}
@Override
public boolean setOccurrences(T item, int occurrences)
{
return this.getDelegate().setOccurrences(item, occurrences);
}
@Override
public int occurrencesOf(Object item)
{
return this.getDelegate().occurrencesOf(item);
}
@Override
public int sizeDistinct()
{
return this.getDelegate().sizeDistinct();
}
@Override
public MutableBag collect(Function super T, ? extends V> function)
{
return this.getDelegate().collect(function);
}
@Override
public MutableBooleanBag collectBoolean(BooleanFunction super T> booleanFunction)
{
return this.getDelegate().collectBoolean(booleanFunction);
}
@Override
public boolean anySatisfyWithOccurrences(ObjectIntPredicate super T> predicate)
{
return this.getDelegate().anySatisfyWithOccurrences(predicate);
}
@Override
public boolean allSatisfyWithOccurrences(ObjectIntPredicate super T> predicate)
{
return this.getDelegate().allSatisfyWithOccurrences(predicate);
}
@Override
public boolean noneSatisfyWithOccurrences(ObjectIntPredicate super T> predicate)
{
return this.getDelegate().noneSatisfyWithOccurrences(predicate);
}
@Override
public T detectWithOccurrences(ObjectIntPredicate super T> predicate)
{
return this.getDelegate().detectWithOccurrences(predicate);
}
@Override
public MutableByteBag collectByte(ByteFunction super T> byteFunction)
{
return this.getDelegate().collectByte(byteFunction);
}
@Override
public MutableCharBag collectChar(CharFunction super T> charFunction)
{
return this.getDelegate().collectChar(charFunction);
}
@Override
public MutableDoubleBag collectDouble(DoubleFunction super T> doubleFunction)
{
return this.getDelegate().collectDouble(doubleFunction);
}
@Override
public MutableFloatBag collectFloat(FloatFunction super T> floatFunction)
{
return this.getDelegate().collectFloat(floatFunction);
}
@Override
public MutableIntBag collectInt(IntFunction super T> intFunction)
{
return this.getDelegate().collectInt(intFunction);
}
@Override
public MutableLongBag collectLong(LongFunction super T> longFunction)
{
return this.getDelegate().collectLong(longFunction);
}
@Override
public MutableShortBag collectShort(ShortFunction super T> shortFunction)
{
return this.getDelegate().collectShort(shortFunction);
}
@Override
public MutableBag flatCollect(Function super T, ? extends Iterable> function)
{
return this.getDelegate().flatCollect(function);
}
@Override
public MutableList> topOccurrences(int count)
{
return this.getDelegate().topOccurrences(count);
}
@Override
public MutableList> bottomOccurrences(int count)
{
return this.getDelegate().bottomOccurrences(count);
}
@Override
public MutableBag collectIf(
Predicate super T> predicate,
Function super T, ? extends V> function)
{
return this.getDelegate().collectIf(predicate, function);
}
@Override
public MutableBag collectWithOccurrences(ObjectIntToObjectFunction super T, ? extends V> function)
{
return this.getDelegate().collectWithOccurrences(function);
}
@Override
public > R collectWithOccurrences(
ObjectIntToObjectFunction super T, ? extends V> function,
R target)
{
return this.getDelegate().collectWithOccurrences(function, target);
}
@Override
public MutableBag collectWith(
Function2 super T, ? super P, ? extends V> function,
P parameter)
{
return this.getDelegate().collectWith(function, parameter);
}
@Override
public MutableBagMultimap groupBy(Function super T, ? extends V> function)
{
return this.getDelegate().groupBy(function);
}
@Override
public MutableBagMultimap groupByEach(Function super T, ? extends Iterable> function)
{
return this.getDelegate().groupByEach(function);
}
@Override
public MutableBag newEmpty()
{
return this.getDelegate().newEmpty();
}
@Override
public MutableBag reject(Predicate super T> predicate)
{
return this.getDelegate().reject(predicate);
}
@Override
public MutableBag rejectWith(
Predicate2 super T, ? super P> predicate,
P parameter)
{
return this.getDelegate().rejectWith(predicate, parameter);
}
@Override
public MutableBag tap(Procedure super T> procedure)
{
this.forEach(procedure);
return this;
}
@Override
public MutableBag select(Predicate super T> predicate)
{
return this.getDelegate().select(predicate);
}
@Override
public MutableBag selectWith(
Predicate2 super T, ? super P> predicate,
P parameter)
{
return this.getDelegate().selectWith(predicate, parameter);
}
@Override
public MutableBag selectByOccurrences(IntPredicate predicate)
{
return this.getDelegate().selectByOccurrences(predicate);
}
@Override
public MutableBag selectInstancesOf(Class clazz)
{
return this.getDelegate().selectInstancesOf(clazz);
}
@Override
public void forEachWithOccurrences(ObjectIntProcedure super T> procedure)
{
this.getDelegate().forEachWithOccurrences(procedure);
}
@Override
public PartitionMutableBag partition(Predicate super T> predicate)
{
return this.getDelegate().partition(predicate);
}
@Override
public PartitionMutableBag partitionWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this.getDelegate().partitionWith(predicate, parameter);
}
/**
* @deprecated in 6.0. Use {@link OrderedIterable#zip(Iterable)} instead.
*/
@Override
@Deprecated
public MutableBag> zip(Iterable that)
{
return this.getDelegate().zip(that);
}
/**
* @deprecated in 6.0. Use {@link OrderedIterable#zipWithIndex()} instead.
*/
@Override
@Deprecated
public MutableSet> zipWithIndex()
{
return this.getDelegate().zipWithIndex();
}
@Override
public MutableMap toMapOfItemToCount()
{
return this.getDelegate().toMapOfItemToCount();
}
@Override
public String toStringOfItemToCount()
{
return this.getDelegate().toStringOfItemToCount();
}
@Override
public MutableSet selectUnique()
{
return this.getDelegate().selectUnique();
}
}
private static final class UntouchableIterator
implements Iterator
{
private Iterator delegate;
private UntouchableIterator(Iterator newDelegate)
{
this.delegate = newDelegate;
}
@Override
public boolean hasNext()
{
return this.delegate.hasNext();
}
@Override
public T next()
{
return this.delegate.next();
}
@Override
public void remove()
{
this.delegate.remove();
}
public void becomeUseless()
{
this.delegate = null;
}
}
}