复制代码代码如下:
Package com.happyelements.athene.game.util;
import static com.google.common.base.precondition.Checknotnull;
import java.util.collection;
import com.google.common.collect.lists;
/ **
* Math 工具类
*
* @version 1.0
* @Since 1.0
* /
classe publique Mathutil {
/ **
* @see mathutil # min (collection)
* @param ts
* @retour
* /
Le public statique <T étend comparable <T>> T min (t ... ts) {
return min (lists.newArrayList (TS));
}
/ **
* 取最小值
* valeurs @param
* @throws nullpointerException if (valeurs == null || valeurs.Contain (null))
* @retour
* /
Le public statique <T étend comparable <T>> T min (collection <T> VALEURS) {
checkNotNull (valeurs);
T min = null;
pour (t t: valeurs) {
Vérifiernotnull (t);
if (min == null) {
min = t;
} autre {
min = min.compareto (t) <0? min: t;
}
}
retourne min;
}
/ **
* @see mathutil # max (collection)
* @param ts
* @retour
* /
Le public statique <T étend comparable <T>> T Max (t ... ts) {
return max (lists.newArrayList (ts));
}
/ **
* 取最大值
* valeurs @param
* @throws nullpointerException if (valeurs == null || valeurs.Contain (null))
* @retour
* /
Le public statique <T étend comparable <T>> T Max (collection <T> VALEURS) {
checkNotNull (valeurs);
T max = null;
pour (t t: valeurs) {
Vérifiernotnull (t);
if (max == null) {
max = t;
} autre {
max = max.compareto (t)> 0? Max: T;
}
}
retourner max;
}
/ **
* 求和
* valeurs @param
* @throws nullpointerException if (valeurs == null || valeurs.Contain (null))
* @retour
* /
Somme publique entier statique (collection <Integer> valeurs) {
checkNotNull (valeurs);
int sum = 0;
pour (entier entier: valeurs) {
CheckNotNull (entier);
sum + = entier;
}
somme de retour;
}
/ **
* @see mathutil # sum (collection)
* @param ts
* @retour
* /
Somme publique en entier statique (entier ... TS) {
return sum (lists.newArrayList (TS));
}
}