Copy Code code as follows:
Package com.happyelements.athene.game.util;
Import static com.google.common.base.Preconditions.checkNotNull;
Import java.util.Collection;
Import com.google.common.collect.Lists;
/**
* Math Tool Class
*
* @version 1.0
* @since 1.0
*/
public class Mathutil {
/**
* @see Mathutil#min (Collection)
* @param ts
* @return
*/
public static <t extends comparable<t>> t min (t ... ts) {
return min (lists.newarraylist (ts));
}
/**
* Take the minimum value
* @param values
* @throws nullpointerexception if (values = null | | values.contain (NULL))
* @return
*/
public static <t extends comparable<t>> T min (collection<t> values) {
Checknotnull (values);
T min = null;
for (T t:values) {
Checknotnull (t);
if (min = null) {
min = t;
} else {
min = Min.compareto (t) < 0? Min:t;
}
}
return min;
}
/**
* @see Mathutil#max (Collection)
* @param ts
* @return
*/
public static <t extends comparable<t>> t max (t.. ts) {
Return Max (lists.newarraylist (TS));
}
/**
* Take the maximum value
* @param values
* @throws nullpointerexception if (values = null | | values.contain (NULL))
* @return
*/
public static <t extends comparable<t>> T max (collection<t> values) {
Checknotnull (values);
T max = null;
for (T t:values) {
Checknotnull (t);
if (max = null) {
max = t;
} else {
max = Max.compareto (t) > 0? Max:t;
}
}
return Max;
}
/**
* Sum
* @param values
* @throws nullpointerexception if (values = null | | values.contain (NULL))
* @return
*/
public static Integer sum (collection<integer> values) {
Checknotnull (values);
int sum = 0;
for (Integer integer:values) {
Checknotnull (integer);
sum = integer;
}
return sum;
}
/**
* @see Mathutil#sum (Collection)
* @param ts
* @return
*/
public static integer sum (integer ... ts) {
return sum (lists.newarraylist (TS));
}
}