com.thoughtworks.webstub.utils.CollectionUtils Maven / Gradle / Ivy
package com.thoughtworks.webstub.utils;
import org.apache.commons.collections.Predicate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class CollectionUtils {
public static PredicatedPartition partition(Collection collection, Predicate predicate) {
List pre = new ArrayList();
List post = new ArrayList();
for (T t : collection) {
(predicate.evaluate(t) ? pre : post).add(t);
}
return new PredicatedPartition(pre, post);
}
public static Collection map(Collection inputs, Mapper mapper) {
List outputs = new ArrayList();
for (S input : inputs) {
outputs.add(mapper.map(input));
}
return outputs;
}
public static boolean exists(Collection collection, com.thoughtworks.webstub.utils.Predicate predicate) {
for (T t : collection) {
if (predicate.satisfies(t))
return true;
}
return false;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy