move definition of x-axis to the aggregate handlers
This commit is contained in:
@@ -5,6 +5,7 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
@@ -12,6 +13,30 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class CollectionUtils {
|
||||
|
||||
public interface Compare<T> {
|
||||
|
||||
public boolean test(T valueA);
|
||||
|
||||
public static <T, V> Compare<T> compare(Function<? super T, ? extends V> keyExtractor, V value) {
|
||||
Objects.requireNonNull(keyExtractor);
|
||||
return t -> Objects.equals(keyExtractor.apply(t), value);
|
||||
}
|
||||
|
||||
default Compare<T> thenCompare(Compare<? super T> other) {
|
||||
Objects.requireNonNull(other);
|
||||
return t -> {
|
||||
final boolean res = test(t);
|
||||
return res ? other.test(t) : false;
|
||||
};
|
||||
}
|
||||
|
||||
default <V> Compare<T> thenCompare(Function<T, ? extends V> keyExtractor, V value) {
|
||||
return thenCompare(compare(keyExtractor, value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static <T, R extends T> void mapInPlace(final List<T> list, final Function<T, R> mapper) {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
final T value = list.get(i);
|
||||
@@ -82,6 +107,16 @@ public class CollectionUtils {
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static <T> boolean contains(Collection<T> collection, final Compare<T> compare) {
|
||||
for (T t : collection) {
|
||||
boolean found = compare.test(t);
|
||||
if (found ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static <V, T extends Collection<V>> T removeAll(final T collection, final T remove,
|
||||
final Supplier<T> generator) {
|
||||
|
||||
Reference in New Issue
Block a user