mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Guava migration - Remove Functions dependency
This commit is contained in:
@@ -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; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user