复制代码代码如下 :
패키지 com.happyElements.athene.game.util;
static com.google.common.base.preconditions.checknotnull 가져 오기;
java.util.collection import;
import 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) {
반환 min (lists.newarraylist (ts));
}
/**
* 取最小值
* @param 값
* @throws nullpointerexception if (values == null || value.contain (null))
* @반품
*/
public static <t는 비슷한 <t >> t min (collection <t> values) {
CheckNotNull (값);
t min = null;
for (t t : value) {
CheckNotNull (t);
if (min == null) {
최소 = t;
} 또 다른 {
min = min.compareto (t) <0? 최소 : T;
}
}
반환 최소;
}
/**
* @See Mathutil#max (컬렉션)
* @param ts
* @반품
*/
public static <t는 비슷한 <t >> t max (t ... ts) {
return max (lists.newarraylist (ts));
}
/**
* 取最大值
* @param 값
* @throws nullpointerexception if (values == null || value.contain (null))
* @반품
*/
public static <t는 비슷한 <t >> t max (collection <t> values) {
CheckNotNull (값);
t max = null;
for (t t : value) {
CheckNotNull (t);
if (max == null) {
max = t;
} 또 다른 {
max = max.compareto (t)> 0? 맥스 : T;
}
}
리턴 맥스;
}
/**
* 求和
* @param 값
* @throws nullpointerexception if (values == null || value.contain (null))
* @반품
*/
public static integer sum (collection <integer> value) {
CheckNotNull (값);
int sum = 0;
for (정수 정수 : 값) {
CheckNotNull (정수);
합계 += 정수;
}
반환 합계;
}
/**
* @See Mathutil#sum (컬렉션)
* @param ts
* @반품
*/
공개 정적 정수 합 (정수 ... TS) {
return sum (lists.newarraylist (ts));
}
}