当前位置:网站首页>internship:用于类型判断的工具类编写
internship:用于类型判断的工具类编写
2022-07-29 00:50:00 【ahyo】
把大部需要判断的数据类型整合到一个工具类里,直接调用方法即可;
/** * 对象是否不为空 */
public static boolean isNotEmpty(Object o) {
return !isEmpty(o);
}
/** * 对象是否为空 */
@SuppressWarnings("rawtypes")
public static boolean isEmpty(Object o) {
if (o == null) {
return true;
}
if (o instanceof String) {
if (o.toString().trim().equals("")) {
return true;
}
} else if (o instanceof List) {
if (((List) o).size() == 0) {
return true;
}
} else if (o instanceof Map) {
if (((Map) o).size() == 0) {
return true;
}
} else if (o instanceof Set) {
if (((Set) o).size() == 0) {
return true;
}
} else if (o instanceof Object[]) {
if (((Object[]) o).length == 0) {
return true;
}
} else if (o instanceof int[]) {
if (((int[]) o).length == 0) {
return true;
}
} else if (o instanceof long[]) {
if (((long[]) o).length == 0) {
return true;
}
}
return false;
}
/** * 是否有空对象 */
public static boolean isOneEmpty(Object... objects){
for (Object object : objects) {
boolean empty = isEmpty(object);
if(empty){
return true;
}
}
return false;
}
/** * map转list * @param map * @return */
public static List mapTransitionList(Map map) {
List list = new ArrayList();
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
list.add(entry.getKey());
list.add(entry.getValue());
}
return list;
}
边栏推荐
- [SQL's 18 dragon subduing palms] 01 - Kang long regrets: introductory 10 questions
- Docker-compose安装mysql
- T-sne降维
- Use of resttemplate and Eureka
- C语言300行代码实现扫雷(可展开+可标记+可更改困难级别)
- The new generation of public chain attacks the "Impossible Triangle"
- Canal实时解析mysql binlog数据实战
- Common functions and usage of numpy
- RHCE command practice (I)
- Redis is installed on Linux
猜你喜欢
Openpyxl library fill color
Learning summary of time complexity and space complexity
Embedded sharing collection 23
ELMO,BERT和GPT简介
BOM系列之定时器
一篇万字博文带你入坑爬虫这条不归路 【万字图文】
SQL question brushing: find the last of all employees who have been assigned departments_ Name and first_ Name and Dept_ no
[SQL's 18 dragon subduing palms] 01 - Kang long regrets: introductory 10 questions
Redis installation, cluster deployment and common tuning
Openpyxl cell center
随机推荐
els 方块移动
After understanding the composition of the URL of the website, we use the URL module, querystring module and mime module to improve the static website
Learning summary of time complexity and space complexity
560 和为 K 的子数组
围绕新市民金融聚焦差异化产品设计、智能技术提效及素养教育
How many of the top ten test tools in 2022 do you master
Canal实时解析mysql binlog数据实战
Synchronized keyword details
Django reports an error using pymsql module django.db.utils.operationalerror
Plato launched the LAAS protocol elephant swap, which allows users to earn premium income
A ten thousand word blog post takes you into the pit. Reptiles are a dead end [ten thousand word pictures]
Cloud native application comprehensive exercise
[unity project practice] synthetic watermelon
Docker compose install MySQL
[MySQL] historical cumulative de duplication of multiple indicators
uniapp movable-view表格缩放过程想保持容器高度不变的解决办法
uniapp createSelectorQuery(). Select get returns null error
我们总结了 3 大Nacos使用建议,并首次公开 Nacos 3.0 规划图 Nacos 开源 4 周年
Third party login process of flask Weibo
Ruiji takeout project actual battle day01