commons-lang3工具类学习(二)
三、BooleanUtils
布尔工具类
and(boolean... array) 逻辑与
BooleanUtils.and(true, true) = true
BooleanUtils.and(false, false) = false
BooleanUtils.and(true, false) = false
BooleanUtils.and(true, true, false) = false
BooleanUtils.and(true, true, true) = true
compare(boolean x, boolean y) 比较两个布尔值并返回int类型 如果x == y返回0, !x && y 返回小于 0 ,x && !y 返回大于0
isFalse(Boolean bool) 是否是假并返回boolean
isTrue(Boolean bool) 是否是真并返回boolean
negate(Boolean bool) 逻辑非
BooleanUtils.negate(Boolean.TRUE) = Boolean.FALSE;
BooleanUtils.negate(Boolean.FALSE) = Boolean.TRUE;
BooleanUtils.negate(null) = null;
or(boolean... array) 逻辑或
BooleanUtils.or(true, true) = true
BooleanUtils.or(false, false) = false
BooleanUtils.or(true, false) = true
BooleanUtils.or(true, true, false) = true
BooleanUtils.or(true, true, true) = true
BooleanUtils.or(false, false, false) = false
toBoolean(Boolean bool) 将对象类型转换为基本数据类型并返回
BooleanUtils.toBoolean(Boolean.TRUE) = true
BooleanUtils.toBoolean(Boolean.FALSE) = false
BooleanUtils.toBoolean(null) = false
toBoolean(int value) 将int类型转换为boolean类型并返回
BooleanUtils.toBoolean(0) = false
BooleanUtils.toBoolean(1) = true
BooleanUtils.toBoolean(2) = true
toBoolean(String str) 将string类型转换为boolean类型并返回
BooleanUtils.toBoolean(null) = false
BooleanUtils.toBoolean("true") = true
BooleanUtils.toBoolean("TRUE") = true
BooleanUtils.toBoolean("tRUe") = true
BooleanUtils.toBoolean("on") = true
BooleanUtils.toBoolean("yes") = true
BooleanUtils.toBoolean("false") = false
BooleanUtils.toBoolean("x gti") = false
BooleanUtils.toBooleanObject("y") = true
BooleanUtils.toBooleanObject("n") = false
BooleanUtils.toBooleanObject("t") = true
BooleanUtils.toBooleanObject("f") = false
toInteger(boolean bool) 将boolean类型数据转换为int类型并返回
BooleanUtils.toInteger(true) = 1
BooleanUtils.toInteger(false) = 0
toStringOnOff(boolean bool) 将boolean类型数据转换为String类型'on' or 'off'并返回
BooleanUtils.toStringOnOff(true) = "on"
BooleanUtils.toStringOnOff(false) = "off"
toStringTrueFalse(Boolean bool) 将boolean类型数据转换为String类型''true' or 'false'并返回
BooleanUtils.toStringTrueFalse(true) = "true"
BooleanUtils.toStringTrueFalse(false) = "false"
toStringYesNo(boolean bool) 将boolean类型数据转换为String类型'yes' or 'no'并返回
BooleanUtils.toStringYesNo(true) = "yes"
BooleanUtils.toStringYesNo(false) = "no"
xor(boolean... array) 异或
BooleanUtils.xor(true, true) = false
BooleanUtils.xor(false, false) = false
BooleanUtils.xor(true, false) = true
四、ClassPathUtils
class路径工具
toFullyQualifiedName(Class<?> context, String resourceName) 返回一个由class包名+resourceName拼接的字符串
ClassPathUtils.toFullyQualifiedName(StringUtils.class, "StringUtils.properties") = "org.apache.commons.lang3.StringUtils.properties"
toFullyQualifiedName(Package context, String resourceName) 返回一个由class包名+resourceName拼接的字符串
ClassPathUtils.toFullyQualifiedName(StringUtils.class.getPackage(), "StringUtils.properties") = "org.apache.commons.lang3.StringUtils.properties"
toFullyQualifiedPath(Class<?> context, String resourceName) 返回一个由class包名+resourceName拼接的字符串
ClassPathUtils.toFullyQualifiedPath(StringUtils.class, "StringUtils.properties") = "org/apache/commons/lang3/StringUtils.properties"
toFullyQualifiedPath(Package context, String resourceName) 返回一个由class包名+resourceName拼接的字符串
ClassPathUtils.toFullyQualifiedPath(StringUtils.class, "StringUtils.properties") = "org/apache/commons/lang3/StringUtils.properties"
五、EnumUtils
枚举工具类
getEnum(Class<E> enumClass, String enumName) 通过类返回一个枚举,可能返回空
getEnumList(Class<E> enumClass) 通过类返回一个枚举集合
getEnumMap(Class<E> enumClass) 通过类返回一个枚举map
isValidEnum(Class<E> enumClass, String enumName) 验证enumName是否在枚举中,返回true false
demo
枚举类
public enum EnumDemo {
AA("1"), BB("2");
private String value;
EnumDemo(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
测试
EnumDemo enumDemo = EnumUtils.getEnum(EnumDemo.class, "");
System.out.println(enumDemo);
System.out.println("-----");
List<EnumDemo> list = EnumUtils.getEnumList(EnumDemo.class);
for (EnumDemo a : list) {
System.out.println(a + ":" + a.getValue());
}
System.out.println("-----");
Map<String, EnumDemo> enumMap = EnumUtils.
commons-lang3工具类学习(二)的更多相关文章
- java中常用的工具类(二)
下面继续分享java中常用的一些工具类,希望给大家带来帮助! 1.FtpUtil Java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...
- Apache Commons 常用工具类整理
其实一直都在使用常用工具类,只是从没去整理过,今天空了把一些常用的整理一下吧 怎么使用的一看就明白,另外还有注释,最后的使用pom引入的jar包 public class ApacheCommonsT ...
- commons-lang3工具类学习(一)
一.ArchUtils java运行环境的系统信息工具类 getArch();// 获取电脑处理器体系结构 32 bit.64 bit.unknown getType();// 返回处理器类型 ...
- java日期工具类DateUtil-续二
该版本是一次较大的升级,农历相比公历复杂太多(真佩服古人的智慧),虽然有规律,但涉及到的取舍.近似的感念太多,况且本身的概念就已经很多了,我在网上也是查阅了很多的资料,虽然找到一些计算的方法,但都有些 ...
- DBUtils工具类学习一
Commons DbUtils是Apache组织提供的一个对JDBC进行简单封装的开源工具类库,使用它能够简化JDBC应用程序的开发,同时也不会影响程序的性能 1.特征 DBUtils是java编程中 ...
- Java 中待总结工具类学习(自定义注解,读取配置,字面List)
1.使用 MessageFormat 格式化文本 int planet = 7; String event = "a disturbance in the Force"; Stri ...
- Properties工具类学习
Properties类学习 1.定义 Properties,java.utils包下的一个工具类,主要用于读取Java的配置文件.各种语言都有自己所支持的配置文件,配置文件中很多变量是经常变动的. 这 ...
- java常用工具类(二)
1.FtpUtil package com.itjh.javaUtil; import java.io.File; import java.io.FileOutputStream; import ja ...
- org.apache.commons.httpclient工具类
import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; import org.apache.commons.httpcl ...
随机推荐
- select默认选中
- Python3使用AES加密的库函数PyCrypto、PyCryptodome
我们在网上查看Python爬虫教程的时候,细心的朋友会发现:很多网站为了降低服务器的请求压力都做了各式各样的反爬策略,浏览器通过http post请求服务器端数据时,传输的data字段很多都是经过加密 ...
- EF设计模式之code first
为了支持以设计为中心的开发流程,EF推出了以代码为中心的模式code first.我们称之为代码优先开发,代码优先的开发支持更加优美的开发流程,允许在不使用设计器或者定义一个XML映射文件的情况下进行 ...
- Oracle 11.2.0.4 RAC重建EM案例
环境:Oracle 11.2.0.4 RAC 重建EM 背景:客户之前的EM已经被损坏,需要重建EM 重建EM的方案有很多,其中最简单的方法是:直接使用emca重建,oracle用户下,只需一条命令搞 ...
- Qt 半模式对话框
今天看视频,学习好半模式对话框,好新奇哟,这里记录下来. 半模式对话框,介于模式对话框和飞模式对话框之间.半模式对话框会像模式对话框一样阻塞主界面的事件响应,同时,半模式对话框会像非模态对话框一样,立 ...
- C#中MemoryStream类的介绍
MemoryStream位于System.IO命名空间,为系统内存提供流式的读写操作.常作为其他流数据交换时的中间对象操作. 1.MemoryStream类封装一个字节数组,在构造实例时可以使用一个字 ...
- webstorm中使用sass
最近由原来的sublime转为使用webstorm,用的不是很熟.我们在webstorm中使用sass 1.首先sass是基于ruby的.这个时候我们需要安装ruby. 2.安装成功后.我们需要去掉原 ...
- RFM用户分层模型简介
RFM用户分层模型在实际商业活动的数据分析中运用的还是挺多的,主要用于用户.商品.门店等等的分群和细分层次,分群之后就可以进行定向精准营销和推广以及促活和留存等等的运营活动. RFM是一种用户分层模型 ...
- demo1:会下蛋的机器人
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- TLS握手、中断恢复与证书中心的原因
在双方都拿到随机数A.B.C后,将会使用这三个随机数生成一个对话密钥,然后使用该对话密钥进行对称加密通信,这种方式我们可以看到,安全性取决于随机数C的加密,前面的几个都是明文传的,这里就取决于服务器的 ...