复制代码代码如下::
Paket com.happyElements.athee.game.util;
Import static com.google.common.base.preconditions.Checknotnull;
Import Java.util.Collection;
import com.google.common.collect.lists;
/**
* Math 工具类
*
* @Version 1.0
* @Since 1.0
*/
öffentliche Klasse Mathutil {
/**
* @see mathutil#min (Sammlung)
* @param ts
* @zurückkehren
*/
public static <t erweitert vergleichbar <t >> t min (t ... ts) {
return min (lists.NewarrayList (ts));
}
/**
* 取最小值
* @Param -Werte
* @throw nullPoIterException if (values == null || values.contain (null)))
* @zurückkehren
*/
public static <t erweitert vergleichbar <t >> t min (Sammlung <T> Werte) {
checknotnull (Werte);
T min = null;
für (t t: Werte) {
checknotnull (t);
if (min == null) {
min = t;
} anders {
min = min.comPareto (t) <0? min: t;
}
}
Rückkehr min;
}
/**
* @see mathutil#max (Sammlung)
* @param ts
* @zurückkehren
*/
public static <t erweitert vergleichbar <t >> t max (t ... ts) {
return max (lists.NewarrayList (ts));
}
/**
* 取最大值
* @Param -Werte
* @throw nullPoIterException if (values == null || values.contain (null)))
* @zurückkehren
*/
public static <t erweitert vergleichbar <t >> t max (Sammlung <t> Werte) {{
checknotnull (Werte);
T max = null;
für (t t: Werte) {
checknotnull (t);
if (max == null) {
max = t;
} anders {
max = max.comPareto (t)> 0? Max: t;
}
}
MAX zurückgeben;
}
/**
* 求和
* @Param -Werte
* @throw nullPoIterException if (values == null || values.contain (null)))
* @zurückkehren
*/
öffentliche statische Ganzzahlsumme (Sammlung <Ganzzahl> Werte) {
checknotnull (Werte);
int sum = 0;
für (Ganzzahl Integer: Werte) {
checknotnull (Integer);
Summe += Ganzzahl;
}
Rückgabesumme;
}
/**
* @see mathutil#sum (Sammlung)
* @param ts
* @zurückkehren
*/
öffentliche statische Ganzzahlsumme (Ganzzahl ... ts) {
Rückgabesumme (lists.NewarrayList (ts));
}
}