学习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)
学习apache commons lang3的源代码 (1):前言和R的更多相关文章
- 学习apache commons lang3的源代码 (2):RandomStringUtils
本文,主要是分析类;RandomStringUtils. 下面这个方法的:count:表示要生成的数量(比如4个字符组成的字符串等) start,end,表示限定的范围,比如生成ascii码的随机等. ...
- org.apache.commons.lang3.ArrayUtils 学习笔记
package com.nihaorz.model; /** * @作者 王睿 * @时间 2016-5-17 上午10:05:17 * */ public class Person { privat ...
- Hadoop java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils
.jar 学习好友推荐案例的时候,提交运行时报错找不到StringUtils java.lang.ClassNotFoundException: org.apache.commons.lang3.St ...
- 【java】org.apache.commons.lang3功能示例
org.apache.commons.lang3功能示例 package com.simple.test; import java.util.Date; import java.util.Iterat ...
- spring异常记录-----java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
今天在练习怎样SSH中进行单元測试的时候出现下列异常: SEVERE: Exception starting filter Struts2 java.lang.NoClassDefFoundError ...
- Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils
1.错误叙述性说明 2014-7-10 23:12:23 org.apache.catalina.core.StandardContext filterStart 严重: Exception star ...
- org.apache.commons.lang3 的随机数生成
apache org.apache.commons.lang3 的随机数生成工具,方便使用. String a12 = RandomStringUtils.random(4, "012345 ...
- org.apache.commons.lang3.tuple.Pair 作为更新参数,XML 中的 Sql 取不到值、报错
项目用的 Mybatis,今天改一个需求,落地实现是批量更新,且只需要根据主键(id)来更新一个字段(name). 于是,没有犹豫,像下面这样设计了数据结构: 既然是批量更新,那外层肯定是 List ...
- NoClassDefFoundError: org/apache/commons/lang3/StringUtils
出错信息: 2014-2-5 21:38:05 org.apache.catalina.core.StandardContext filterStart严重: Exception starting f ...
随机推荐
- PhpStorm 配置数据库
点击软件右边的 Database
- c# 复选下拉框
引用dll: http://pan.baidu.com/s/1qXa97UO 自定义类: namespace TMI_S { /// <summary> /// 功能描述:自定义多选下拉框 ...
- $this是什么意思-成员变量和局部变量的调用
关键字$this代表其所在的当前对象 使用当前对象的属性和方法 $this->取值 方法内的局部变量 不能用$this 关键字取值 /* 和java,c++相比 方法体内想访问调用者的属性,必须 ...
- 《学习OpenCV》课后习题解答8
题目:(P126) 本章完整讲述了基本的输入/输出编程以及OpenCV的数据结构.下面的练习是基于前面的知识做一些应用,为后面大程序的实现提供帮助. a.创建一个程序实现以下功能:(1)从视频文件中读 ...
- 解决Linux下启动Tomcat遇到Neither the JAVA_HOME ...报错
解决Linux下启动Tomcat遇到Neither the JAVA_HOME ...报错 Neither the JAVA_HOME nor the JRE_HOME environment var ...
- Struts2-part1
作者:禅楼望月(http://www.cnblogs.com/yaoyinglong) 1. Struts2应用的开发步骤: ① 在web.xml中配置核心的Filter来拦截用户的请求. <w ...
- 【Python】Python中子类怎样调用父类方法
python中类的初始化方法是__init__(),因此父类子类的初始化方法都是这个,如果子类不实现这个函数,初始化时调用父类的初始化函数,如果子类实现这个函数,就覆盖了父类的这个函数,既然继承父类, ...
- P2168 [NOI2015]荷马史诗
题目描述 追逐影子的人,自己就是影子 ——荷马 Allison 最近迷上了文学.她喜欢在一个慵懒的午后,细细地品上一杯卡布奇诺,静静地阅读她爱不释手的<荷马史诗>.但是由<奥德赛&g ...
- 对web开发从业者的发展方向的思考
最近在读子柳的<淘宝技术这十年>,“牛P列传”这一章中介绍了很多淘宝技术发展史上做出重要贡献的“牛P人物”(阿里的技术岗按能力分级,从P1~P10). 读到采访小马的这一段: 子柳:畅想一 ...
- How to turn off the binary log for mysqld_multi instances?
Q: MySQL supports running multiple mysqld on the same server. One of the ways is to use mysqld_multi ...