首页 > 其他分享 >commons-lang3工具类学习(二)

commons-lang3工具类学习(二)

时间:2023-02-01 14:35:46浏览次数:42  
标签:false commons boolean toBoolean lang3 trueBooleanUtils true 工具 BooleanUtils


三、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.

标签:false,commons,boolean,toBoolean,lang3,trueBooleanUtils,true,工具,BooleanUtils
From: https://blog.51cto.com/u_15950441/6031559

相关文章

  • commons-lang3工具类学习(三)
    六、ObjectUtilsObject工具类allNotNull(Object...values) 检查所有元素是否为空,返回一个boolean如果有一个元素为空返回false,所有元素不为空或元素为empty返回trueObjec......
  • commons-lang3工具类学习(一)
    一、ArchUtilsjava运行环境的系统信息工具类getArch();//获取电脑处理器体系结构32bit、64bit、unknowngetType();//返回处理器类型x86、ia64、ppc、unknownis32Bit()......
  • 五彩斑斓的 Black —— Python 代码格式化工具
      https://muzing.top/posts/a29e4743/#  良好的Python代码应有良好的格式规范(不止于遵守 PEP8 ),使用一个更强大更专业的代码格式化工具,来替代编辑器自带的......
  • 使用dayjs制作倒计时工具
    引入脚本<scriptsrc="https://cdn.bootcdn.net/ajax/libs/dayjs/1.11.7/dayjs.min.js"></script><scriptsrc="https://cdn.bootcdn.net/ajax/libs/dayjs/1.11.7/plug......
  • 使用AS的NDK工具开发JNI
    从集成NDK至AndroidStudio中到实现简单案例​​CtrlAltShiftS​​快捷键打开如下窗口,点击DownloadAndroidNDK.如下图,NDK会自动下载安装好NDK下载好后配置下系统环境......
  • pyqt5 简单工具类
    fromPyQt5.QtWidgetsimportQPushButton,QLabel,QLineEdit,QTextEdit,QPlainTextEdit,QCheckBoxfromPyQt5.QtWidgetsimportQComboBox,QRadioButtonclassMYWIDGET():......
  • 00- 工具类
    一.登陆前置1.中间件#中间件介绍#1.在中间件的process_request方法:#如果方法中没有返回值(返回None),继续向后走#如果方法中有返回值HttpResponse......
  • 【FFH】 gn项目构建工具学习记录
    gn项目构建工具学习我们为何要使用构建工具?对于一个新手入门简单的helloworld程序而言,我们可以直接使用gcc命令对其进行编译。对于OpenHarmony系统而言,代码规模庞大,再想要......
  • Guava:google公司开发的一款Java类库扩展工具包
    Guava是google公司开发的一款Java类库扩展工具包文档https://github.com/google/guavahttps://github.com/google/guava/wikihttps://guava.dev/releases/snapshot-jre......
  • 爬虫工具(tkinter+scrapy+pyinstaller)
    需求介绍输入:关键字文件,每一行数据为一爬取单元。若一行存在多个and关系的关键字,则用|隔开处理:爬取访问6个网站的推送,获取推送内容的标题,发布时间,来源,正文第一段(不是图片......