本系列主要是针对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. 软件工程项目组Z.XML会议记录 2013/09/14

    软件工程项目组Z.XML会议记录 [例会时间]2013年9月14日星期六21:00-22:30 [例会形式]小组讨论 [例会地点]新主楼A1025 [例会主持]李孟 [会议记录]李孟 会议整体流程 一 ...

  2. Flink之状态之checkpointing

    1.前言 在Flink中,函数和操作符都可以是有状态的.在处理每个消息或者元素时,有状态的函数都会储存信息,使得状态成为精密操作中关键的组成部分. 为了使状态能够容错,Flink会checkpoint ...

  3. 51nod 1680区间求和 (dp+树状数组/线段树)

    不妨考虑已知一个区间[l,r]的k=1.k=2....k=r-l+1这些数的答案ans(只是这一个区间,不包含子区间) 那么如果加入一个新的数字a[i](i = r+1) 则新区间[l, i]的答案为 ...

  4. 【C++ troubleshooting】A case about decltype

    template <typename iter_t> bool next_permutation(iter_t beg, iter_t end) { // if (beg == end | ...

  5. (一)STM32固件库详解(转载)

    本篇博文是转载自emouse,因为不能直接转载,所以是复制过来再发布的. emouse原创文章,转载请注明出处http://www.cnblogs.com/emouse/   1.1 基于标准外设库的 ...

  6. How do I see what character set a database / table / column is in MySQL?

    Q: How do I see what the character set that a MySQL database, table and column are in? Is there some ...

  7. js 加法运算

    搜集网友的各种解决办法: 1.parseInt(),parseFloat()等字符串转换函数 2.eval(执行加法的表达式) 3.a-(-b)  因为减法只有算术运算意义 a*1+b a为字符串 a ...

  8. The NPF driver isn't running

    转自:http://blog.csdn.net/zhangkaihang/article/details/7470239 今天安装Wireshark软件时出现了如下图所示的错误,就搜索了一下解决方法, ...

  9. HDU4889 Scary Path Finding Algorithm

    Fackyyj loves the challenge phase in TwosigmaCrap(TC). One day, he meet a task asking him to find sh ...

  10. bzoj 1011 近似估计

    开始看这道题的时候没什么思路,后来忍不住看了题解,发现自己真是水啊... 自从学OI来第一次看到用约等的题 首先我们设w[i]为第i个星球的答案,g[i]为第i个星球受到1-g[i]个星球的引力 那么 ...