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 ...
随机推荐
- python框架之Django(4)-视图&路由
视图 负责接收请求和返回响应 FBV和CBV FBV FBV(function base views) 就是在视图里使用函数处理请求. from django.conf.urls import url ...
- 图片居中table-cell
- 面向对象编程之OC
面向对象概述 面向对象是一种符合人类思想习惯的编程思想.现实生活中存在各种形态不同的事物,这些事物之间存在着各种各样的联系,在程序中使用对象来映射现实中的事物,使用对象的关系来描述事物之间的联系,这种 ...
- vue的一些感想
如今vue2.0是主流,但是它的路由确实直接从1.0过来的,其中包括组件包括全局组件和局部组件,写好组件之后,我们就需要 使用路由,将组件关联起来,关联起来之后,然后我们才可以将组件的内容通过hash ...
- mybatis源码解析11---ParameterHandler解析
ParameterHandler接口是参数处理器,位于mybatis包的org.apache.ibatis.executor.parameter下,源码如下: public interface Par ...
- Hdu2033 人见人爱A+B (贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2033 人见人爱A+B Time Limit: 2000/1000 MS (Java/Others) ...
- BIOS备忘录之IIC(touchpad)设备
简述BIOS中对IIC device的支持,以touchpad为例. 信息收集 收集平台的硬件信息: 1. IIC controller number(PCH一般包含多个controller,我们使用 ...
- Linux 网络管理、软件包安装
1.fdisk -l 查看处系统磁盘设备,打boot“*”的是系统启动的磁盘块. (1)查看磁盘Disk /dev/sdb:5368MB(总大小),5368709120bytes(比特位) (2)25 ...
- 【题解】JSOIWC2019 Round2
题面: 题解: T1: 毕竟是tg膜你,不会太难 就是一道简单贪心 首先,对于a<=b的所有物品,一定是贪心的按照a从小到大放入. 先假设剩下的物品可以按照某种顺序放进去,那么可以得到一个最终空 ...
- 模块——Getopt::Long接收客户命令行参数和Smart::Comments输出获得的命令行参数内容
我们在linux常常用到一个程序需要加入参数,现在了解一下 perl 中的有关控制参数的模块 Getopt::Long ,比直接使用 @ARGV 的数组强大多了.我想大家知道在 Linux 中有的参 ...