mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-17 09:14:07 +02:00
Modify the method getting the biggest int / long of a collection to using streams instead of doing it manually.
The reason for it is to adjust it to the other methods in the same class
This commit is contained in:
parent
4399f8aecc
commit
31b432d01e
@ -3,6 +3,8 @@ package main.java.com.djrapitops.plan.utilities.analysis;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.OptionalLong;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
@ -124,13 +126,13 @@ public class MathUtils {
|
||||
* @return
|
||||
*/
|
||||
public static int getBiggest(Collection<Integer> values) {
|
||||
int biggest = 1;
|
||||
for (Integer value : values) {
|
||||
if (value > biggest) {
|
||||
biggest = value;
|
||||
}
|
||||
OptionalInt biggest = values.stream().mapToInt(i -> i).max();
|
||||
|
||||
if (biggest.isPresent()) {
|
||||
return biggest.getAsInt();
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
return biggest;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,12 +141,12 @@ public class MathUtils {
|
||||
* @return
|
||||
*/
|
||||
public static long getBiggestLong(Collection<Long> values) {
|
||||
long biggest = 1;
|
||||
for (Long value : values) {
|
||||
if (value > biggest) {
|
||||
biggest = value;
|
||||
}
|
||||
OptionalLong biggest = values.stream().mapToLong(i -> i).max();
|
||||
|
||||
if (biggest.isPresent()) {
|
||||
return biggest.getAsLong();
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
return biggest;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user