java - 如何结合这两个地图条件
问题描述
有没有办法将这两个条件组合在一个变量中?
boolean notNullMappingPresent1 = !isNullOrEmpty(map1) && (isNotNullOrEmpty(map1.get("Value"));
boolean nullMappingPresent1 = (!isNullOrEmpty(map1) && isNullOrEmpty(map1.get("Value")));
boolean notNullMappingPresent2 = !isNullOrEmpty(map2) && (isNotNullOrEmpty(map2.get("Value"));
boolean nullMappingPresent2 = (!isNullOrEmpty(map2) && isNullOrEmpty(map2.get("Value")));
if(notNullMappingPresent1){
//lines of code
}
if(notNullMappingPresent2){
//lines of code
}
if(nullMappingPresent1 && nullMappingPresent2){
//lines of code
}
我需要结合notNullMappingPresent1
并nullMappingPresent1
结合notNullMappingPresent2
and nullMappingPresent2
。我们可以组合创建 2 个而不是创建 4 个布尔变量吗?
解决方案
看来,应该提取空检查map1
和map2
应该提取,然后可以使用这两个表达式:
if (!isNullOrEmpty(map1) && !isNullOrEmpty(map2)) {
boolean nullMapping1 = isNullOrEmpty(map1.get("Value"));
boolean nullMapping2 = isNullOrEmpty(map2.get("Value"));
if (nullMapping1 && nullMapping2) {
// lines of code
} else {
if (!nullMapping1) {
// lines of code
}
if (!nullMapping2) {
// lines of code
}
}
}
推荐阅读
- r - 闪亮的应用程序 - 多个同时用户访问
- java - 使用 Spring Web Sockets 和 STOMP 的自定义 Jetty WebSocketPolicy
- regex - awk 在cmder windows 上返回“指定的路径无效”错误
- lua - 为什么这个类中的这个函数在lua中不能正常工作?
- xslt - 如何为索引提取关系 XML 的所有变体
- docker - Docker 托管的 redis 丢失数据
- php - 无法从 SQL 创建变量
- python - 使用权重时,Tensorflow 为“tf.keras”模型计算不正确的损失
- android - 主/详细布局未呈现
- mime-types - 我应该为 CSV ZIP 文件使用什么 mime 类型?