复制代码代码如下:
pacote com.happyElements.athene.game.util;
importar com.google.common.base.preconditions.checknotnull;
importar java.util.Collection;
importar com.google.common.collect.lists;
/**
* MATH 工具类
*
* @version 1.0
* @since 1.0
*/
classe pública Mathutil {
/**
* @see Mathutil#min (coleção)
* @param ts
* @retornar
*/
public static <t estende comparável <t>> t min (t ... ts) {
retornar min (lists.newArrayList (TS));
}
/**
* 取最小值
* valores @param
* @throws NullPointerException if (valores == null || valores.contain (null))
* @retornar
*/
public static <t estende comparável <t>> t min (Coleção <t> valores) {
checkNotNull (valores);
T min = nulo;
para (t t: valores) {
VerifiqueNOTNULL (T);
if (min == null) {
min = t;
} outro {
min = min.compareto (t) <0? min: t;
}
}
retornar min;
}
/**
* @see Mathutil#max (coleção)
* @param ts
* @retornar
*/
public static <t estende comparável <t>> t max (t ... ts) {
retornar max (lists.newArrayList (TS));
}
/**
* 取最大值
* valores @param
* @throws NullPointerException if (valores == null || valores.contain (null))
* @retornar
*/
public static <t estende comparável <t>> t max (coleção <t> valores) {
checkNotNull (valores);
T max = null;
para (t t: valores) {
VerifiqueNOTNULL (T);
if (max == null) {
max = t;
} outro {
max = max.compareto (t)> 0? max: t;
}
}
retornar max;
}
/**
* 求和
* valores @param
* @throws NullPointerException if (valores == null || valores.contain (null))
* @retornar
*/
Public Static Integer Sum (Coleção <Integer> valores) {
checkNotNull (valores);
int sum = 0;
para (número inteiro inteiro: valores) {
checkNotNull (número inteiro);
soma += número inteiro;
}
soma de retorno;
}
/**
* @See Mathutil#SUM (Coleção)
* @param ts
* @retornar
*/
Public Static Integer Sum (Inteiro ... TS) {
soma de retorno (lists.newArrayList (ts));
}
}