com.gs.collections.impl.lazy.parallel.AbstractBatch 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 2014 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;
import java.util.Comparator;
import com.gs.collections.api.block.function.Function;
import com.gs.collections.api.block.function.primitive.DoubleFunction;
import com.gs.collections.api.block.function.primitive.FloatFunction;
import com.gs.collections.api.block.function.primitive.IntFunction;
import com.gs.collections.api.block.function.primitive.LongFunction;
import com.gs.collections.api.block.predicate.Predicate;
import com.gs.collections.api.block.procedure.Procedure;
import com.gs.collections.impl.block.procedure.CountProcedure;
import com.gs.collections.impl.block.procedure.DoubleSumResultHolder;
import com.gs.collections.impl.block.procedure.MaxByProcedure;
import com.gs.collections.impl.block.procedure.MaxComparatorProcedure;
import com.gs.collections.impl.block.procedure.MinByProcedure;
import com.gs.collections.impl.block.procedure.MinComparatorProcedure;
import com.gs.collections.impl.block.procedure.SumOfDoubleProcedure;
import com.gs.collections.impl.block.procedure.SumOfFloatProcedure;
import com.gs.collections.impl.block.procedure.SumOfIntProcedure;
import com.gs.collections.impl.block.procedure.SumOfLongProcedure;
public abstract class AbstractBatch implements Batch
{
public int count(Predicate super T> predicate)
{
CountProcedure procedure = new CountProcedure(predicate);
this.forEach(procedure);
return procedure.getCount();
}
public String makeString(final String separator)
{
final StringBuilder stringBuilder = new StringBuilder();
this.forEach(new Procedure()
{
public void value(T each)
{
if (stringBuilder.length() != 0)
{
stringBuilder.append(separator);
}
stringBuilder.append(each);
}
});
return stringBuilder.toString();
}
public T min(Comparator super T> comparator)
{
MinComparatorProcedure procedure = new MinComparatorProcedure(comparator);
this.forEach(procedure);
return procedure.isVisitedAtLeastOnce() ? procedure.getResult() : null;
}
public T max(Comparator super T> comparator)
{
MaxComparatorProcedure procedure = new MaxComparatorProcedure(comparator);
this.forEach(procedure);
return procedure.isVisitedAtLeastOnce() ? procedure.getResult() : null;
}
public > T minBy(Function super T, ? extends V> function)
{
MinByProcedure procedure = new MinByProcedure(function);
this.forEach(procedure);
return procedure.isVisitedAtLeastOnce() ? procedure.getResult() : null;
}
public > T maxBy(Function super T, ? extends V> function)
{
MaxByProcedure procedure = new MaxByProcedure(function);
this.forEach(procedure);
return procedure.isVisitedAtLeastOnce() ? procedure.getResult() : null;
}
public long sumOfInt(IntFunction super T> function)
{
SumOfIntProcedure procedure = new SumOfIntProcedure(function);
this.forEach(procedure);
return procedure.getResult();
}
public DoubleSumResultHolder sumOfFloat(FloatFunction super T> function)
{
SumOfFloatProcedure procedure = new SumOfFloatProcedure(function);
this.forEach(procedure);
return procedure;
}
public long sumOfLong(LongFunction super T> function)
{
SumOfLongProcedure procedure = new SumOfLongProcedure(function);
this.forEach(procedure);
return procedure.getResult();
}
public DoubleSumResultHolder sumOfDouble(DoubleFunction super T> function)
{
SumOfDoubleProcedure procedure = new SumOfDoubleProcedure(function);
this.forEach(procedure);
return procedure;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy