复制代码代码如下:
包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));
}
}