monniasza.collects.CollectionOps Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of multimachinebuilder Show documentation
Show all versions of multimachinebuilder Show documentation
Dependency for the MultiMachineBuilder, a voxel game about building an industrial empire in a finite world.
THIS RELEASE IS NOT PLAYABLE. To play the game, donwload from >ITCH.IO LINK HERE< or >GH releases link here<
/**
*
*/
package monniasza.collects;
import java.util.function.Predicate;
/**
* Functional-style operations on collections
* @author oskar
*/
public class CollectionOps {
private CollectionOps() {}
//Collection to boolean
/**
* Checks if all values meet a predicate
* @param type of values
* @param collection collection to test
* @param predicate condition
* @return do all items meet a criterion?
*/
public static boolean isAll(Iterable extends T> collection, Predicate predicate) {
for(T value: collection)
if(!predicate.test(value)) return false;
return true;
}
/**
* Checks if any value meets a predicate
* @param type of values
* @param collection collection to test
* @param predicate condition
* @return does any items meet a criterion?
*/
public static boolean isAny(Iterable extends T> collection, Predicate predicate) {
for(T value: collection)
if(predicate.test(value)) return true;
return false;
}
}