复制代码代码如下:
paquete com.happyelements.athene.game.util;
Importar static com.google.common.base.preconditions.checknotnull;
import java.util.collection;
import com.google.common.collect.lists;
/**
* Matemáticas 工具类
*
* @version 1.0
* @Since 1.0
*/
clase pública Mathutil {
/**
* @see Mathutil#min (colección)
* @param ts
* @devolver
*/
public static <t extiende comparable <T>> t min (t ... ts) {
return min (lists.newArrayList (TS));
}
/**
* 取最小值
* @Param Valores
* @throws nullPointerException if (valores == null || value.contain (null))
* @devolver
*/
public static <t extiende <T>> t min (colección <t> valores) {
checkNotNull (valores);
T min = nulo;
para (t t: valores) {
checkNotnull (t);
if (min == null) {
min = t;
} demás {
min = min.compareto (t) <0? min: t;
}
}
regresar min;
}
/**
* @see Mathutil#max (colección)
* @param ts
* @devolver
*/
public static <t extiende comparable <t>> t max (t ... ts) {
return max (lists.newArrayList (TS));
}
/**
* 取最大值
* @Param Valores
* @throws nullPointerException if (valores == null || value.contain (null))
* @devolver
*/
public static <t extiende <T>> t max (colección <t> valores) {
checkNotNull (valores);
T max = nulo;
para (t t: valores) {
checkNotnull (t);
if (max == null) {
max = t;
} demás {
max = max.compareto (t)> 0? max: t;
}
}
devolver max;
}
/**
* 求和
* @Param Valores
* @throws nullPointerException if (valores == null || value.contain (null))
* @devolver
*/
Public static entero suma (Collection <integer> valores) {
checkNotNull (valores);
int sum = 0;
para (Integer Integer: Values) {
checkNotNull (entero);
sum += entero;
}
suma de retorno;
}
/**
* @See Mathutil#sum (colección)
* @param ts
* @devolver
*/
Public static integer suma (entero ... ts) {
suma de retorno (lists.newArrayList (TS));
}
}