本系列主要是针对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的更多相关文章

  1. 学习apache commons lang3的源代码 (2):RandomStringUtils

    本文,主要是分析类;RandomStringUtils. 下面这个方法的:count:表示要生成的数量(比如4个字符组成的字符串等) start,end,表示限定的范围,比如生成ascii码的随机等. ...

  2. org.apache.commons.lang3.ArrayUtils 学习笔记

    package com.nihaorz.model; /** * @作者 王睿 * @时间 2016-5-17 上午10:05:17 * */ public class Person { privat ...

  3. Hadoop java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils

    .jar 学习好友推荐案例的时候,提交运行时报错找不到StringUtils java.lang.ClassNotFoundException: org.apache.commons.lang3.St ...

  4. 【java】org.apache.commons.lang3功能示例

    org.apache.commons.lang3功能示例 package com.simple.test; import java.util.Date; import java.util.Iterat ...

  5. spring异常记录-----java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils

    今天在练习怎样SSH中进行单元測试的时候出现下列异常: SEVERE: Exception starting filter Struts2 java.lang.NoClassDefFoundError ...

  6. 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 ...

  7. org.apache.commons.lang3 的随机数生成

    apache org.apache.commons.lang3 的随机数生成工具,方便使用. String a12 = RandomStringUtils.random(4, "012345 ...

  8. org.apache.commons.lang3.tuple.Pair 作为更新参数,XML 中的 Sql 取不到值、报错

    项目用的 Mybatis,今天改一个需求,落地实现是批量更新,且只需要根据主键(id)来更新一个字段(name). 于是,没有犹豫,像下面这样设计了数据结构: 既然是批量更新,那外层肯定是 List ...

  9. NoClassDefFoundError: org/apache/commons/lang3/StringUtils

    出错信息: 2014-2-5 21:38:05 org.apache.catalina.core.StandardContext filterStart严重: Exception starting f ...

随机推荐

  1. valgrind使用

    参数配置 gcc -g: 增加调试信息,供valgrind精确定位. -O0:关闭gcc优化:优化产生的代码可能会造成valgrind误判. valgrind --leak-check=full no ...

  2. 解析LINQ To Object

    1.解剖Linq to object   此文转载自http://www.cnblogs.com/irenebbkiss/p/4155480.html LINQ想必大家都不陌生了,它 的出现使得我们的 ...

  3. BZOJ 3876:支线剧情(有下界最小费用最大流)

    3876: [Ahoi2014]支线剧情 Description [故事背景]宅男JYY非常喜欢玩RPG游戏,比如仙剑,轩辕剑等等.不过JYY喜欢的并不是战斗场景,而是类似电视剧一般的充满恩怨情仇的剧 ...

  4. hdu 1207 汉诺塔II (DP+递推)

    汉诺塔II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  5. [CF1077C]Good Array

    题目大意:一个序列是好的当且仅当有一个数是其它所有数的和,问一个序列可以删掉哪个数变成好的序列.输出所有方案. 题解:发现等于其他数的和的那个数一定是其中最大的,只要排序一下(其实只要找到最大的两个数 ...

  6. Windows查看进程CMD命令和终止进程CMD命令

    将小米路由器3刷机成openwrt的方法,请参考上篇文章< 家庭宽带多运营商接入方案>这里介绍怎么在已经刷成openwrt系统的小米路由器3上安装私有云nextcloud openwrt开 ...

  7. 工具——SVN常用命令

    SVN一般都是团队合作做一个项目所需用到的,为了是版本的统一 ;1. Check out——从服务器端取得代码    把服务器资料库里存放的某个项目代码取出来,放到本地主机中,这个动作叫做“check ...

  8. POJ2492:A Bug's Life(种类并查集)

    A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 45757   Accepted: 14757 题 ...

  9. docker compose,link,Odoo

    1.报错: /usr/bin/docker-current: Error response from daemon: driver failed programming external connec ...

  10. vue2学习篇一 $mount()手动挂载

    $mount()手动挂载 //当Vue实例没有el属性时,则该实例尚没有挂载到某个dom中: //假如需要延迟挂载,可以在之后手动调用vm.$mount()方法来挂载.例如: new Vue({ // ...