Number 常用工具类


 

数值型包括

  • byte、short、int、long、float、double及对应的包装类型
  • BigInteger、BigDecimal
     

commons-lang3的NumberUtils

常用常量
//给数值型的包装类型 Byte、Short、Integer、Long、Float、Double 都提供了 0、1、-1 三个值的常量
Long longZero = NumberUtils.LONG_ZERO;
Long longOne = NumberUtils.LONG_ONE;
Long longMinusOne = NumberUtils.LONG_MINUS_ONE;

//Integer类型还提供常用的常量2
Integer integerTwo = NumberUtils.INTEGER_TWO;

 

常用方法
//计算各类数值型的最值,参数数值类型相同、个数不定
int min = NumberUtils.min(1, 2, 3);
int max = NumberUtils.max(1, 2, 3);


//检查字符串中的字符是否都为unicode数字,digit 数字
boolean isDigits = NumberUtils.isDigits(str);
//检查str能否被转换为unicode数字
boolean isParsable = NumberUtils.isParsable(str);
//注意此处是unicode数字:除了阿拉伯数字0~9,१२३之类的梵文数字、全角数字也属于unicode数字。null、空串返回false


//从String创建各类数值型的包装类型、BigInteger、BigDecimal,null返回null,转换失败会抛出异常
Integer integer = NumberUtils.createInteger(str);
BigInteger bigInteger = NumberUtils.createBigInteger(str);
BigDecimal bigDecimal = NumberUtils.createBigDecimal(str);


//将String转换为各类数值型的基本类型,null、转换失败时返回默认值
int i1 = NumberUtils.toInt(str, defaultValue);
//缺省默认值时,整型默认取0,浮点型默认取0.0
int i2 = NumberUtils.toInt(str);

 

spring的NumberUtils

//数值型的class对象集合
Set<Class<?>> standardNumberTypes = NumberUtils.STANDARD_NUMBER_TYPES;

//将String转换为指定的数值包装类型,转换失败会抛出异常
Integer integer1 = NumberUtils.parseNumber(str, Integer.class);
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android系统下载管理DownloadManager增强方法,可用于包括获取下载相关信息,如: getStatusById(long) 得到下载状态 getDownloadBytes(long) 得到下载进度信息 getBytesAndStatus(long) 得到下载进度信息和状态 getFileName(long) 得到下载文件路径 getUri(long) 得到下载uri getReason(long) 得到下载失败或暂停原因 getPausedReason(long) 得到下载暂停原因 getErrorCode(long) 得到下载错误码 =================================================================== package cn.trinea.android.common.util; import java.lang.reflect.Method; import android.app.DownloadManager; import android.app.DownloadManager.Request; import android.database.Cursor; import android.net.Uri; import android.os.Build; /** * DownloadManagerPro * * Get download info * {@link #getStatusById(long)} get download status * {@link #getDownloadBytes(long)} get downloaded byte, total byte * {@link #getBytesAndStatus(long)} get downloaded byte, total byte and download status * {@link #getFileName(long)} get download file name * {@link #getUri(long)} get download uri * {@link #getReason(long)} get failed code or paused reason * {@link #getPausedReason(long)} get paused reason * {@link #getErrorCode(long)} get failed error code * * * Operate download * {@link #isExistPauseAndResumeMethod()} whether exist pauseDownload and resumeDownload method in * {@link DownloadManager} * {@link #pauseDownload(long...)} pause download. need pauseDownload(long...) method in {@link DownloadManager} * {@link #resumeDownload(long...)} resume download. need resumeDownload(long...) method in {@link DownloadManager} * * * RequestPro * {@link RequestPro#setNotiClass(String)} set noti class * {@link RequestPro#setNotiExtras(String)} set noti extras * * * @author Trinea 2013-5-4 */ public class DownloadManagerPro { public static final Uri CONTENT_URI

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值