复制代码代码如下:
パッケージcom.happyelements.athene.game.util;
static com.google.common.base.preconditions.checknotnullをインポートします。
java.util.collectionをインポートします。
com.google.common.collect.listsをインポートします。
/**
*数学工具类
*
* @version 1.0
* @since 1.0
*/
パブリッククラスMathutil {
/**
* @See Mathutil#MIN(コレクション)
* @Param TS
* @戻る
*/
public static <tは同等の<t >> t min(t ... ts){
return min(lists.newArrayList(TS));
}
/**
*取最小值
* @param値
* @throws nullpointerexception if(values == null || values.contain(null)))
* @戻る
*/
public static <tは同等の<t >> t min(collection <t> values){
checknotnull(values);
t min = null;
(t t:values){
checknotnull(t);
if(min == null){
min = t;
} それ以外 {
min = min.comPareto(t)<0? min:t;
}
}
Minを返します。
}
/**
* @see Mathutil#Max(Collection)
* @Param TS
* @戻る
*/
public static <tは同等の<t >> t max(t ... ts){
return max(lists.newArrayList(TS));
}
/**
*取最大值
* @param値
* @throws nullpointerexception if(values == null || values.contain(null)))
* @戻る
*/
public static <tは同等の<t >> t max(collection <t> values){
checknotnull(values);
t max = null;
(t t:values){
checknotnull(t);
if(max == null){
max = t;
} それ以外 {
max = max.compareto(t)> 0?マックス:t;
}
}
MAXを返します。
}
/**
*求和
* @param値
* @throws nullpointerexception if(values == null || values.contain(null)))
* @戻る
*/
public static integer sum(collection <integer> values){
checknotnull(values);
int sum = 0;
for(integer integer:values){
checknotnull(integer);
sum += integer;
}
返品額;
}
/**
* @see mathutil#sum(collection)
* @Param TS
* @戻る
*/
public static Integer Sum(整数... ts){
return sum(lists.newarraylist(ts));
}
}