複製代碼代碼如下:
包com.happylements.Athene.game.util;
導入靜態com.google.common.base.base.preconditions.checknotnull;
導入Java.util.Collection;
導入com.google.common.collect.lists;
/**
*數學工具類
*
* @version 1.0
* @since 1.0
*/
公共類Mathutil {
/**
* @See Mathutil#min(收集)
* @param TS
* @返回
*/
公共靜態<t擴展可比<t >> t min(t ... ts){
返回最低(lists.newarraylist(ts));
}
/**
*取最小值
* @param值
* @throws nullpoInterException if(values == null || values.contain(null))
* @返回
*/
public static <t擴展可比<t>> t min(collection <t> value){
checknotnull(values);
t min = null;
for(t t:values){
checknotnull(t);
如果(min == null){
min = t;
} 別的 {
min = min.com.pareto(t)<0?最小:t;
}
}
返回最小;
}
/**
* @See Mathutil#max(收集)
* @param TS
* @返回
*/
公共靜態<t擴展可比<t >> t max(t ... ts){
返回max(lists.newarraylist(ts));
}
/**
*取最大值
* @param值
* @throws nullpoInterException if(values == null || values.contain(null))
* @返回
*/
public static <t擴展可比<t>> t max(collection <t> value){
checknotnull(values);
t max = null;
for(t t:values){
checknotnull(t);
if(max == null){
max = t;
} 別的 {
max = max.compareto(t)> 0?最大:T;
}
}
返回最大;
}
/**
*求和
* @param值
* @throws nullpoInterException if(values == null || values.contain(null))
* @返回
*/
public static Integer sum(collection <integer> values){
checknotnull(values);
int sum = 0;
for(整數整數:values){
checknotnull(整數);
sum +=整數;
}
返回總和;
}
/**
* @See Mathutil#sum(集合)
* @param TS
* @返回
*/
公共靜態整數總和(Integer ... ts){
返回sum(lists.newarraylist(ts));
}
}