You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package com.alibaba.excel.util;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Int utils
|
|
|
|
*
|
|
|
|
* @author Jiaju Zhuang
|
|
|
|
**/
|
|
|
|
public class IntUtils {
|
|
|
|
private IntUtils() {}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The largest power of two that can be represented as an {@code int}.
|
|
|
|
*
|
|
|
|
* @since 10.0
|
|
|
|
*/
|
|
|
|
public static final int MAX_POWER_OF_TWO = 1 << (Integer.SIZE - 2);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the {@code int} nearest in value to {@code value}.
|
|
|
|
*
|
|
|
|
* @param value any {@code long} value
|
|
|
|
* @return the same value cast to {@code int} if it is in the range of the {@code int} type,
|
|
|
|
* {@link Integer#MAX_VALUE} if it is too large, or {@link Integer#MIN_VALUE} if it is too
|
|
|
|
* small
|
|
|
|
*/
|
|
|
|
public static int saturatedCast(long value) {
|
|
|
|
if (value > Integer.MAX_VALUE) {
|
|
|
|
return Integer.MAX_VALUE;
|
|
|
|
}
|
|
|
|
if (value < Integer.MIN_VALUE) {
|
|
|
|
return Integer.MIN_VALUE;
|
|
|
|
}
|
|
|
|
return (int) value;
|
|
|
|
}
|
|
|
|
}
|