com.gs.collections.impl.lazy.parallel.set.ParallelFlatCollectIterable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gs-collections Show documentation
Show all versions of gs-collections Show documentation
GS Collections is a collections framework for Java. It has JDK-compatible List, Set and Map
implementations with a rich API and set of utility classes that work with any JDK compatible Collections,
Arrays, Maps or Strings. The iteration protocol was inspired by the Smalltalk collection framework.
/*
* Copyright 2015 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.lazy.parallel.set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference;
import com.gs.collections.api.LazyIterable;
import com.gs.collections.api.annotation.Beta;
import com.gs.collections.api.block.function.Function;
import com.gs.collections.api.block.predicate.Predicate;
import com.gs.collections.api.block.procedure.Procedure;
import com.gs.collections.api.map.MapIterable;
import com.gs.collections.api.multimap.bag.UnsortedBagMultimap;
import com.gs.collections.impl.lazy.parallel.AbstractParallelIterable;
import com.gs.collections.impl.lazy.parallel.AbstractParallelIterableImpl;
import com.gs.collections.impl.lazy.parallel.Batch;
import com.gs.collections.impl.utility.Iterate;
@Beta
public class ParallelFlatCollectIterable extends AbstractParallelIterableImpl>
{
private final AbstractParallelIterable> delegate;
private final Function super T, ? extends Iterable> function;
public ParallelFlatCollectIterable(AbstractParallelIterable> delegate, Function super T, ? extends Iterable> function)
{
this.delegate = delegate;
this.function = function;
}
@Override
public ExecutorService getExecutorService()
{
return this.delegate.getExecutorService();
}
@Override
public int getBatchSize()
{
return this.delegate.getBatchSize();
}
@Override
public LazyIterable> split()
{
return this.delegate.split().collect(new Function, Batch>()
{
public Batch valueOf(Batch batch)
{
return batch.flatCollect(ParallelFlatCollectIterable.this.function);
}
});
}
public void forEach(final Procedure super V> procedure)
{
this.delegate.forEach(new Procedure()
{
public void value(T each)
{
Iterate.forEach(ParallelFlatCollectIterable.this.function.valueOf(each), procedure);
}
});
}
public V detect(final Predicate super V> predicate)
{
final AtomicReference result = new AtomicReference();
this.delegate.anySatisfy(new Predicate()
{
public boolean accept(T each)
{
return Iterate.anySatisfy(ParallelFlatCollectIterable.this.function.valueOf(each), new Predicate()
{
public boolean accept(V each)
{
if (predicate.accept(each))
{
result.compareAndSet(null, each);
return true;
}
return false;
}
});
}
});
return result.get();
}
public boolean anySatisfy(final Predicate super V> predicate)
{
return this.delegate.anySatisfy(new Predicate()
{
public boolean accept(T each)
{
return Iterate.anySatisfy(ParallelFlatCollectIterable.this.function.valueOf(each), predicate);
}
});
}
public boolean allSatisfy(final Predicate super V> predicate)
{
return this.delegate.allSatisfy(new Predicate()
{
public boolean accept(T each)
{
return Iterate.allSatisfy(ParallelFlatCollectIterable.this.function.valueOf(each), predicate);
}
});
}
@Override
public Object[] toArray()
{
// TODO: Implement in parallel
return this.delegate.toList().flatCollect(this.function).toArray();
}
@Override
public E[] toArray(E[] array)
{
// TODO: Implement in parallel
return this.delegate.toList().flatCollect(this.function).toArray(array);
}
@Override
public UnsortedBagMultimap groupBy(Function super V, ? extends V1> function)
{
// TODO: Implement in parallel
return this.delegate.toBag().flatCollect(this.function).groupBy(function);
}
@Override
public UnsortedBagMultimap groupByEach(Function super V, ? extends Iterable> function)
{
// TODO: Implement in parallel
return this.delegate.toBag().flatCollect(this.function).groupByEach(function);
}
@Override
public MapIterable groupByUniqueKey(Function super V, ? extends V1> function)
{
// TODO: Implement in parallel
return this.delegate.toBag().flatCollect(this.function).groupByUniqueKey(function);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy