public class DataUtils extends Object
限定符和类型 | 字段和说明 |
---|---|
static String[] |
CN_CHARS
汉字
|
static String[] |
CN_UNITS
单位
|
static double |
DOUBLE_MIN_VALUE
双精度最小值
|
static float |
FLOAT_MIN_VALUE
单精度最小值
|
static int |
UNIT_STEP
单位进位,中文默认为4位即(万、亿)
|
构造器和说明 |
---|
DataUtils() |
限定符和类型 | 方法和说明 |
---|---|
static boolean |
approxEquals(double d1,
double d2)
以默认公差0.00001为标准,判断两个数是否接近
|
static boolean |
approximate(double d1,
double d2,
double p)
判断两个数是否近似,以指定的公差为标准
|
static boolean |
approxZero(double d)
判断是否约等于0,以默认公差0.00001为标准
|
static String[] |
convert(long num,
boolean isColloquial)
将数值转换为中文
|
static String |
convert2Cn(long num)
数值转换为中文字符串,如:2转化为二
|
static String |
convert2Cn(long num,
boolean isColloquial)
数值转换为中文字符串
|
static String |
convert2Cn(String num,
boolean isColloquial)
数值转换为中文字符串(口语化)
|
static String |
convert2CnNum(int srcNum)
将阿拉伯数字转换为中文数字,比如:123 -》一二三
|
static String |
double2String(double d,
int p)
将 double转为string,没有","分割,并且不采用科学计数法
|
static int |
doubleToInt(double d)
按照四舍五入计算方式执行双精度转整型
|
static double |
floatToDouble(float value)
单精度转换成双精度会出现精度丢失,该方法是为了防止精度丢失
|
static int |
floatToInt(float f)
按照四舍五入计算方式执行单精度转整型
|
static String |
formatDouble2String(double d,
int p)
格式化double数值为对应字符串,严格设置小数点位数为指定位数,若小数位数不足,则补0
|
static long |
geneId(long primitiveId,
long factor)
根据基因因子生成基因id
|
static boolean |
getBoolean(String str)
获取布尔值
|
static double |
getDouble(String str)
获取double值
|
static float |
getFloat(String str)
获取float值
|
static int |
getInteger(String str)
获取int值
|
static long |
getLong(String str)
获取long值
|
static long |
getRandomData(int length)
生成指定位数的随机数字
|
static int |
getRandomData(int min,
int max)
返回指定范围内的随机数,包含两边端点
|
static ArrayList<Integer> |
getRandomNum(int num,
int min,
int max)
获取指定范围内指定数量的随机数
|
static int |
hammingDistance(int x,
int y)
计算两个数的海明距离
|
static boolean |
isBadFormat(String numStr)
检测该字符串是否是不良的数值格式,指该字符串能够被数值类解析为对应数值,但是格式不良好 该方法主要用于数值输入组件的数值验证上
|
static boolean |
isNegativeInteger(String original)
是否是负整数
|
static boolean |
isNumber(String text)
判断字符串是否能转换成数值
|
static boolean |
isPositiveInteger(String original)
是否是正整数
|
static boolean |
isPrimes(int n)
判断一个整数是否属于质数
|
static Number |
max(Number... numbs)
获取数字集合中的最大值
|
static int |
millimetre2Pixel(int millimetre)
毫米转像素
|
static Number |
min(Number... numbs)
获取数字集合中的最小值
|
static float |
parsePercent(String percent)
将百分数解析为对应的float型小数
|
static double |
pixel2Millimetre(int pixel)
像素转毫米
|
static long |
restoreId(long uid,
long factor)
基因id还原为原始ID
|
static double |
round(double d,
int p)
提供精确的小数位四舍五入处理。
|
static double |
round(double d,
int p,
int roundingMode)
同上,可采取不同的小数位处理方式
|
static float |
round(float f,
int p)
提供精确的小数位四舍五入处理。
|
static double |
truncate(double value,
double min,
double max)
取值在指定的最小值与最大值之间,若超出,则取边界值
|
public static int UNIT_STEP
public static String[] CN_UNITS
public static String[] CN_CHARS
public static final float FLOAT_MIN_VALUE
public static final double DOUBLE_MIN_VALUE
public static boolean approxZero(double d)
d
- 待判断数值public static boolean approxEquals(double d1, double d2)
d1
- 待比较数值1d2
- 待比较数值2public static boolean approximate(double d1, double d2, double p)
d1
- 待比较数值1d2
- 待比较数值2p
- 两个数之差是否小于ppublic static String double2String(double d, int p)
d
- 需要四舍五入的数字p
- 最多保留几位小数,默认采取四舍五入的方式public static String formatDouble2String(double d, int p)
d
- 需要四舍五入的数字p
- 保留几位小数public static float round(float f, int p)
f
- 需要四舍五入的数字p
- 小数点后保留几位public static double round(double d, int p)
d
- 需要四舍五入的数字p
- 小数点后保留几位public static double round(double d, int p, int roundingMode)
d
- 需要四舍五入的数字p
- 小数点后保留几位roundingMode
- 四舍五入方式public static double truncate(double value, double min, double max)
value
- 期望值min
- 最小值max
- 最大值public static long getRandomData(int length) throws Exception
length
- 数字位数Exception
- 非法参数导致的异常public static int getRandomData(int min, int max)
min
- 最小值max
- 最大值public static ArrayList<Integer> getRandomNum(int num, int min, int max)
num
- 随机数数量min
- 最小值max
- 最大值public static int floatToInt(float f)
f
- 待处理数值public static int doubleToInt(double d)
d
- 待处理数值public static double floatToDouble(float value)
value
- 待处理数值public static float parsePercent(String percent) throws Exception
percent
- 百分数Exception
- 参数错误时抛出异常public static boolean getBoolean(String str)
str
- 待处理字符串public static float getFloat(String str)
str
- 待处理字符串public static double getDouble(String str)
str
- 待处理字符串public static int getInteger(String str)
str
- 待处理字符串public static long getLong(String str)
str
- 待处理字符串public static boolean isBadFormat(String numStr)
numStr
- 待判断字符串public static boolean isNumber(String text)
text
- 待判断字符串public static boolean isPositiveInteger(String original)
original
- 待判断字符串public static boolean isNegativeInteger(String original)
original
- 待判断字符串public static boolean isPrimes(int n)
n
- 待判断整数public static double pixel2Millimetre(int pixel)
pixel
- 像素值public static int millimetre2Pixel(int millimetre)
millimetre
- 毫米值public static int hammingDistance(int x, int y)
x
- 数值1y
- 数值2public static String convert2CnNum(int srcNum)
srcNum
- 阿拉伯数字public static String convert2Cn(String num, boolean isColloquial)
num
- 需要转换的数值isColloquial
- 是否口语化。例如12转换为'十二'而不是'一十二'。public static String convert2Cn(long num)
num
- 需要转换的数值public static String convert2Cn(long num, boolean isColloquial)
num
- 需要转换的数值isColloquial
- 是否口语化,例如:12转换为'十二'而不是'一十二'。public static String[] convert(long num, boolean isColloquial)
num
- 需要转换的数值isColloquial
- 是否口语化,例如:12转换为'十二'而不是'一十二'。public static long geneId(long primitiveId, long factor)
primitiveId
- 原始IDfactor
- 基因因子public static long restoreId(long uid, long factor)
uid
- 基因混淆后的IDfactor
- 基因因子