commons-lang3工具类学习(二)
来源:互联网 发布:比价软件哪个好 编辑:程序博客网 时间:2024/05/22 17:02
摘自http://commons.apache.org/proper/commons-lang/javadocs/api-release/org/apache/commons/lang3/官方文档,借此整理一遍,方便自己记忆
三、BooleanUtils
布尔工具类
and(boolean… array) 逻辑与
BooleanUtils.and(true, true) = trueBooleanUtils.and(false, false) = falseBooleanUtils.and(true, false) = falseBooleanUtils.and(true, true, false) = falseBooleanUtils.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) = trueBooleanUtils.or(false, false) = falseBooleanUtils.or(true, false) = trueBooleanUtils.or(true, true, false) = trueBooleanUtils.or(true, true, true) = trueBooleanUtils.or(false, false, false) = false
toBoolean(Boolean bool) 将对象类型转换为基本数据类型并返回
BooleanUtils.toBoolean(Boolean.TRUE) = trueBooleanUtils.toBoolean(Boolean.FALSE) = falseBooleanUtils.toBoolean(null) = false
toBoolean(int value) 将int类型转换为boolean类型并返回
BooleanUtils.toBoolean(0) = falseBooleanUtils.toBoolean(1) = trueBooleanUtils.toBoolean(2) = true
toBoolean(String str) 将string类型转换为boolean类型并返回
BooleanUtils.toBoolean(null) = falseBooleanUtils.toBoolean("true") = trueBooleanUtils.toBoolean("TRUE") = trueBooleanUtils.toBoolean("tRUe") = trueBooleanUtils.toBoolean("on") = trueBooleanUtils.toBoolean("yes") = trueBooleanUtils.toBoolean("false") = falseBooleanUtils.toBoolean("x gti") = falseBooleanUtils.toBooleanObject("y") = trueBooleanUtils.toBooleanObject("n") = falseBooleanUtils.toBooleanObject("t") = trueBooleanUtils.toBooleanObject("f") = false
toInteger(boolean bool) 将boolean类型数据转换为int类型并返回
BooleanUtils.toInteger(true) = 1BooleanUtils.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) = falseBooleanUtils.xor(false, false) = falseBooleanUtils.xor(true, false) = true
四、ClassPathUtils
class路径工具
toFullyQualifiedName 返回一个由class包名+resourceName拼接的字符串
toFullyQualifiedName(Class<?> context, String 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包名+resourceName拼接的字符串
toFullyQualifiedPath(Class<?> context, String 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 enumClass, String enumName) 通过类返回一个枚举,可能返回空
getEnumList(Class enumClass) 通过类返回一个枚举集合
getEnumMap(Class enumClass) 通过类返回一个枚举map
isValidEnum(Class 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.getEnumMap(EnumDemo.class);for (Map.Entry<String, EnumDemo> entry : enumMap.entrySet()) { Object key = entry.getKey(); EnumDemo value = entry.getValue(); System.out.println(key + ":" + value.getValue());}System.out.println("-----");System.out.println(EnumUtils.isValidEnum(EnumDemo.class, "aa"));输出AA-----AA:1BB:2-----AA:1BB:2-----false
- commons-lang3工具类学习(二)
- commons-lang3工具类学习(一)
- commons-lang3工具类学习(三)
- 字符串工具类, 继承org.apache.commons.lang3.StringUtils类
- org.apache.commons.lang3.StringUtils工具类常用方法
- apache.commons.lang3.StringUtils工具类的使用
- commons-lang3
- Apache 工具类 StringUtils 源码,使用的是commons-lang3-3.1包。
- Commons lang3 包ArrayUtils类使用
- Commons lang3 包ArrayUtils类使用
- apache commons组件学习系列记录之lang3
- apache-comnons系列之commons-lang3 学习笔记1
- jeesite中org.apache.commons.lang3.time学习总结
- 日期处理类 org.apache.commons.lang3.time.DateUtils
- 【常用类库之一—org.apache.commons.lang3】
- Apache Commons工具集简介(二)
- Apache-commons-lang3方法应用
- org.apache.commons.lang3.StringUtils
- Ubuntu16.04 xampp php5.6编译mongodb
- commons-lang3工具类学习(一)
- Recycleview 在头布局里嵌套Listview
- C语言中mktime函数功能及用法
- tensorflow学习笔记(2)-feed_dict
- commons-lang3工具类学习(二)
- Redis_基础
- 【约瑟夫环】Java实现:指定人数开始从1开始报数,每当报数到m,报数m的人离开,求最后留下来人的位置
- CSS清除浮动
- leetcode 329. Longest Increasing Path in a Matrix
- 小程序在数据绑定中取整
- elasticsearch6.x.x logstash6.x.x kibana6.x.x Filebeat6.x 配置及安装 CentOS7.3或更高
- css常用效果总结
- ELK部署笔记