Guava migration - Remove Functions dependency

This commit is contained in:
Jetz
2024-09-02 12:29:50 -04:00
parent bb520b1a60
commit fb16a46389
4 changed files with 37 additions and 15 deletions

View File

@@ -1,10 +1,6 @@
package forge.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.Map.Entry;
import com.google.common.base.Function;
@@ -29,6 +25,16 @@ public class Aggregates {
return max;
}
public static Integer max(final Iterable<Integer> source) {
if (source == null) return null;
int max = Integer.MIN_VALUE;
for (int value : source) {
if (value > max)
max = value;
}
return max;
}
public static final <T> Integer min(final Iterable<T> source, final Function<T, Integer> valueAccessor) {
if (source == null) { return null; }
int max = Integer.MAX_VALUE;
@@ -41,6 +47,16 @@ public class Aggregates {
return max;
}
public static Integer min(final Iterable<Integer> source) {
if (source == null) return null;
int min = Integer.MAX_VALUE;
for (int value : source) {
if (value < min)
min = value;
}
return min;
}
public static final <T> T itemWithMax(final Iterable<T> source, final Function<T, Integer> valueAccessor) {
if (source == null) { return null; }
int max = Integer.MIN_VALUE;
@@ -83,6 +99,16 @@ public class Aggregates {
return result;
}
public static int sum(final Iterable<Integer> source) {
int result = 0;
if(source != null) {
for(final Integer value : source) {
result += value;
}
}
return result;
}
public static final <T> T random(final T[] source) {
if (source == null) { return null; }