学习apache commons lang3的源代码 (1):前言和R
本系列主要是针对lang3的3.7版本的源代码进行学习,并适当举例。一共大概150多个java文件,争取30天内学习完毕。
26个英文字母 争取每天学习1个字母开头的类们。
今天,就学习R开头的吧。
第一个:RandomUtils。
这个类,是对Random类 (java.util) 的补充。
这个类,的代码不算复杂。因为是Random的helper。因此,在其内部,首先声明一个:
private static final Random RANDOM = new Random();
1)有些方法,实际上就是直接调用Random的方法。比如:nextBoolean();
public static boolean nextBoolean() {
return RANDOM.nextBoolean();
}
2)有些方法,实际上就是做一些校验,然后,增强型的直接调用Random的方法。比如:nextBytes。
public static byte[] nextBytes(final int count) {
Validate.isTrue(count >= 0, "Count cannot be negative.");
final byte[] result = new byte[count];
RANDOM.nextBytes(result);
return result;
}
3)有些方法,是Random没有直接提供的。比如:nextInt,是返回两个整数之间的随机值。
public static int nextInt(final int startInclusive, final int endExclusive) {
Validate.isTrue(endExclusive >= startInclusive,
"Start value must be smaller or equal to end value.");
Validate.isTrue(startInclusive >= 0, "Both range values must be non-negative.");
if (startInclusive == endExclusive) {
return startInclusive;
}
return startInclusive + RANDOM.nextInt(endExclusive - startInclusive);
}
至于nextLong,则和nextInt类似。
4)
最新文章
- 第一个移动前端开源项目-dailog
- testng教程之testng.xml的配置和使用,以及参数传递
- IBatis.Net使用总结(三)-- IBatis实现分页返回数据和总数
- HDU 3090 (贪心)
- zabbix告警“Zabbix poller processes more than 75% busy”
- Spring中Bean的生命中期与InitializingBean和DisposableBean接口
- android项目实战 --ListView 头部ViewPager广告轮询图效果
- Beanstalkd
- Openresty 操作Cookie
- [2017BUAA软工助教]个人项目准备工作
- C# 属性(Property)和字段(Field)的区别
- html对a标签的运用以及属性,img图像标签的属性及应用
- Vue系列之 =>; 组件切换
- create view in view
- go语言基础之指针做函数参数
- [AS3.0] 解决Number类型计算不精确问题
- Sound.loadCompressedDataFromByteArray
- 玲珑oj 1117 线段树+离线+离散化,laz大法
- 5G信令(就是用户身份信息)风暴——就是客户端通过公钥加密的消息(携带手机IMSI号)发给服务端,服务器需用私钥解密,这个解密比较消耗资源,如果短时间大量请求到来就会触发信令风暴
- egrep及扩展正则
热门文章
- C++常用STL
- lintcode-111-爬楼梯
- iOS-登录发送验证码时60秒倒计时,直接用
- 搭建springmvc项目没扫描到mapper和service
- [洛谷P1640][SCOI2010]连续攻击游戏
- AOJ.800 热身之开关灯
- 【BZOJ 1485】[HNOI2009]有趣的数列 卡特兰数
- bulk_insert_buffer_size and InnoDB
- 理解PHP链式调用
- c++(类) this指针