2
* Copyright 2014 Goldman Sachs.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
package com.gs.collections.impl.lazy.parallel.set;
19
import java.util.concurrent.ExecutorService;
21
import com.gs.collections.api.LazyIterable;
22
import com.gs.collections.api.annotation.Beta;
23
import com.gs.collections.api.block.function.Function;
24
import com.gs.collections.api.block.predicate.Predicate;
25
import com.gs.collections.api.block.procedure.Procedure;
26
import com.gs.collections.impl.block.factory.Functions;
27
import com.gs.collections.impl.block.factory.Predicates;
28
import com.gs.collections.impl.lazy.parallel.AbstractParallelIterable;
29
import com.gs.collections.impl.lazy.parallel.AbstractParallelIterableImpl;
30
import com.gs.collections.impl.lazy.parallel.Batch;
33
public class ParallelCollectIterable<T, V> extends AbstractParallelIterableImpl<V, Batch<V>>
35
private final AbstractParallelIterable<T, ? extends Batch<T>> parallelIterable;
36
private final Function<? super T, ? extends V> function;
38
public ParallelCollectIterable(AbstractParallelIterable<T, ? extends Batch<T>> parallelIterable, Function<? super T, ? extends V> function)
40
this.parallelIterable = parallelIterable;
41
this.function = function;
45
public ExecutorService getExecutorService()
47
return this.parallelIterable.getExecutorService();
51
public LazyIterable<Batch<V>> split()
53
return this.parallelIterable.split().collect(new Function<Batch<T>, Batch<V>>()
55
public Batch<V> valueOf(Batch<T> eachBatch)
57
return eachBatch.collect(ParallelCollectIterable.this.function);
62
public void forEach(Procedure<? super V> procedure)
64
this.parallelIterable.forEach(Functions.bind(procedure, this.function));
67
public boolean anySatisfy(Predicate<? super V> predicate)
69
return this.parallelIterable.anySatisfy(Predicates.attributePredicate(this.function, predicate));
72
public boolean allSatisfy(Predicate<? super V> predicate)
74
return this.parallelIterable.allSatisfy(Predicates.attributePredicate(this.function, predicate));
77
public V detect(Predicate<? super V> predicate)
79
T resultItem = this.parallelIterable.detect(Predicates.attributePredicate(this.function, predicate));
80
return resultItem == null ? null : this.function.valueOf(resultItem);