All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.collections.impl.lazy.parallel.AbstractMultiReaderParallelIterable Maven / Gradle / Ivy

There is a newer version: 12.0.0.M3
Show newest version
/*
 * Copyright (c) 2016 Goldman Sachs.
 * 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.lazy.parallel;

import java.util.Comparator;
import java.util.concurrent.locks.ReadWriteLock;

import org.eclipse.collections.api.ParallelIterable;
import org.eclipse.collections.api.bag.MutableBag;
import org.eclipse.collections.api.bag.sorted.MutableSortedBag;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.Function0;
import org.eclipse.collections.api.block.function.Function2;
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.predicate.Predicate;
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.list.ParallelListIterable;
import org.eclipse.collections.api.map.MapIterable;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.map.sorted.MutableSortedMap;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.api.set.ParallelUnsortedSetIterable;
import org.eclipse.collections.api.set.sorted.MutableSortedSet;
import org.eclipse.collections.impl.lazy.parallel.list.MultiReaderParallelListIterable;
import org.eclipse.collections.impl.lazy.parallel.set.MultiReaderParallelUnsortedSetIterable;

public abstract class AbstractMultiReaderParallelIterable> implements ParallelIterable
{
    protected final PI delegate;
    protected final ReadWriteLock lock;

    protected AbstractMultiReaderParallelIterable(PI delegate, ReadWriteLock lock)
    {
        this.delegate = delegate;
        this.lock = lock;
    }

    protected  ParallelListIterable wrap(ParallelListIterable wrapped)
    {
        return new MultiReaderParallelListIterable<>(wrapped, this.lock);
    }

    protected  ParallelUnsortedSetIterable wrap(ParallelUnsortedSetIterable wrapped)
    {
        return new MultiReaderParallelUnsortedSetIterable<>(wrapped, this.lock);
    }

    protected  ParallelIterable wrap(ParallelIterable wrapped)
    {
        return new MultiReaderParallelIterable<>(wrapped, this.lock);
    }

    @Override
    public void forEach(Procedure procedure)
    {
        this.lock.readLock().lock();
        try
        {
            this.delegate.forEach(procedure);
        }
        finally
        {
            this.lock.readLock().unlock();
        }
    }

    @Override
    public 

void forEachWith(Procedure2 procedure, P parameter) { this.lock.readLock().lock(); try { this.delegate.forEachWith(procedure, parameter); } finally { this.lock.readLock().unlock(); } } @Override public T detect(Predicate predicate) { this.lock.readLock().lock(); try { return this.delegate.detect(predicate); } finally { this.lock.readLock().unlock(); } } @Override public

T detectWith(Predicate2 predicate, P parameter) { this.lock.readLock().lock(); try { return this.delegate.detectWith(predicate, parameter); } finally { this.lock.readLock().unlock(); } } @Override public T detectIfNone(Predicate predicate, Function0 function) { this.lock.readLock().lock(); try { return this.delegate.detectIfNone(predicate, function); } finally { this.lock.readLock().unlock(); } } @Override public

T detectWithIfNone(Predicate2 predicate, P parameter, Function0 function) { this.lock.readLock().lock(); try { return this.delegate.detectWithIfNone(predicate, parameter, function); } finally { this.lock.readLock().unlock(); } } @Override public int count(Predicate predicate) { this.lock.readLock().lock(); try { return this.delegate.count(predicate); } finally { this.lock.readLock().unlock(); } } @Override public

int countWith(Predicate2 predicate, P parameter) { this.lock.readLock().lock(); try { return this.delegate.countWith(predicate, parameter); } finally { this.lock.readLock().unlock(); } } @Override public boolean anySatisfy(Predicate predicate) { this.lock.readLock().lock(); try { return this.delegate.anySatisfy(predicate); } finally { this.lock.readLock().unlock(); } } @Override public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { this.lock.readLock().lock(); try { return this.delegate.anySatisfyWith(predicate, parameter); } finally { this.lock.readLock().unlock(); } } @Override public boolean allSatisfy(Predicate predicate) { this.lock.readLock().lock(); try { return this.delegate.allSatisfy(predicate); } finally { this.lock.readLock().unlock(); } } @Override public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { this.lock.readLock().lock(); try { return this.delegate.allSatisfyWith(predicate, parameter); } finally { this.lock.readLock().unlock(); } } @Override public boolean noneSatisfy(Predicate predicate) { this.lock.readLock().lock(); try { return this.delegate.noneSatisfy(predicate); } finally { this.lock.readLock().unlock(); } } @Override public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { this.lock.readLock().lock(); try { return this.delegate.noneSatisfyWith(predicate, parameter); } finally { this.lock.readLock().unlock(); } } @Override public MutableList toList() { this.lock.readLock().lock(); try { return this.delegate.toList(); } finally { this.lock.readLock().unlock(); } } @Override public MutableList toSortedList() { this.lock.readLock().lock(); try { return this.delegate.toSortedList(); } finally { this.lock.readLock().unlock(); } } @Override public MutableList toSortedList(Comparator comparator) { this.lock.readLock().lock(); try { return this.delegate.toSortedList(comparator); } finally { this.lock.readLock().unlock(); } } @Override public > MutableList toSortedListBy(Function function) { this.lock.readLock().lock(); try { return this.delegate.toSortedListBy(function); } finally { this.lock.readLock().unlock(); } } @Override public MutableSet toSet() { this.lock.readLock().lock(); try { return this.delegate.toSet(); } finally { this.lock.readLock().unlock(); } } @Override public MutableSortedSet toSortedSet() { this.lock.readLock().lock(); try { return this.delegate.toSortedSet(); } finally { this.lock.readLock().unlock(); } } @Override public MutableSortedSet toSortedSet(Comparator comparator) { this.lock.readLock().lock(); try { return this.delegate.toSortedSet(comparator); } finally { this.lock.readLock().unlock(); } } @Override public > MutableSortedSet toSortedSetBy(Function function) { this.lock.readLock().lock(); try { return this.delegate.toSortedSetBy(function); } finally { this.lock.readLock().unlock(); } } @Override public MutableBag toBag() { this.lock.readLock().lock(); try { return this.delegate.toBag(); } finally { this.lock.readLock().unlock(); } } @Override public MutableSortedBag toSortedBag() { this.lock.readLock().lock(); try { return this.delegate.toSortedBag(); } finally { this.lock.readLock().unlock(); } } @Override public MutableSortedBag toSortedBag(Comparator comparator) { this.lock.readLock().lock(); try { return this.delegate.toSortedBag(comparator); } finally { this.lock.readLock().unlock(); } } @Override public > MutableSortedBag toSortedBagBy(Function function) { this.lock.readLock().lock(); try { return this.delegate.toSortedBagBy(function); } finally { this.lock.readLock().unlock(); } } @Override public MutableMap toMap(Function keyFunction, Function valueFunction) { this.lock.readLock().lock(); try { return this.delegate.toMap(keyFunction, valueFunction); } finally { this.lock.readLock().unlock(); } } @Override public MutableSortedMap toSortedMap(Function keyFunction, Function valueFunction) { this.lock.readLock().lock(); try { return this.delegate.toSortedMap(keyFunction, valueFunction); } finally { this.lock.readLock().unlock(); } } @Override public MutableSortedMap toSortedMap(Comparator comparator, Function keyFunction, Function valueFunction) { this.lock.readLock().lock(); try { return this.delegate.toSortedMap(comparator, keyFunction, valueFunction); } finally { this.lock.readLock().unlock(); } } @Override public Object[] toArray() { this.lock.readLock().lock(); try { return this.delegate.toArray(); } finally { this.lock.readLock().unlock(); } } @Override public T1[] toArray(T1[] target) { this.lock.readLock().lock(); try { return this.delegate.toArray(target); } finally { this.lock.readLock().unlock(); } } @Override public T min(Comparator comparator) { this.lock.readLock().lock(); try { return this.delegate.min(comparator); } finally { this.lock.readLock().unlock(); } } @Override public T max(Comparator comparator) { this.lock.readLock().lock(); try { return this.delegate.max(comparator); } finally { this.lock.readLock().unlock(); } } @Override public T min() { this.lock.readLock().lock(); try { return this.delegate.min(); } finally { this.lock.readLock().unlock(); } } @Override public T max() { this.lock.readLock().lock(); try { return this.delegate.max(); } finally { this.lock.readLock().unlock(); } } @Override public > T minBy(Function function) { this.lock.readLock().lock(); try { return this.delegate.minBy(function); } finally { this.lock.readLock().unlock(); } } @Override public > T maxBy(Function function) { this.lock.readLock().lock(); try { return this.delegate.maxBy(function); } finally { this.lock.readLock().unlock(); } } @Override public long sumOfInt(IntFunction function) { this.lock.readLock().lock(); try { return this.delegate.sumOfInt(function); } finally { this.lock.readLock().unlock(); } } @Override public double sumOfFloat(FloatFunction function) { this.lock.readLock().lock(); try { return this.delegate.sumOfFloat(function); } finally { this.lock.readLock().unlock(); } } @Override public long sumOfLong(LongFunction function) { this.lock.readLock().lock(); try { return this.delegate.sumOfLong(function); } finally { this.lock.readLock().unlock(); } } @Override public double sumOfDouble(DoubleFunction function) { this.lock.readLock().lock(); try { return this.delegate.sumOfDouble(function); } finally { this.lock.readLock().unlock(); } } @Override public String makeString() { this.lock.readLock().lock(); try { return this.delegate.makeString(); } finally { this.lock.readLock().unlock(); } } @Override public String makeString(String separator) { this.lock.readLock().lock(); try { return this.delegate.makeString(separator); } finally { this.lock.readLock().unlock(); } } @Override public String makeString(String start, String separator, String end) { this.lock.readLock().lock(); try { return this.delegate.makeString(start, separator, end); } finally { this.lock.readLock().unlock(); } } @Override public void appendString(Appendable appendable) { this.lock.readLock().lock(); try { this.delegate.appendString(appendable); } finally { this.lock.readLock().unlock(); } } @Override public void appendString(Appendable appendable, String separator) { this.lock.readLock().lock(); try { this.delegate.appendString(appendable, separator); } finally { this.lock.readLock().unlock(); } } @Override public void appendString(Appendable appendable, String start, String separator, String end) { this.lock.readLock().lock(); try { this.delegate.appendString(appendable, start, separator, end); } finally { this.lock.readLock().unlock(); } } @Override public MapIterable groupByUniqueKey(Function function) { this.lock.readLock().lock(); try { return this.delegate.groupByUniqueKey(function); } finally { this.lock.readLock().unlock(); } } @Override public MapIterable aggregateInPlaceBy(Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator) { this.lock.readLock().lock(); try { return this.delegate.aggregateInPlaceBy(groupBy, zeroValueFactory, mutatingAggregator); } finally { this.lock.readLock().unlock(); } } @Override public MapIterable aggregateBy(Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { this.lock.readLock().lock(); try { return this.delegate.aggregateBy(groupBy, zeroValueFactory, nonMutatingAggregator); } finally { this.lock.readLock().unlock(); } } @Override public String toString() { this.lock.readLock().lock(); try { return this.delegate.toString(); } finally { this.lock.readLock().unlock(); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy