//This code for mapping the elements inside xml tag
public static String getLeukemiaInvolvement(String val) {
BiMap<String, String> map = HashBiMap.create();
map.put("01", "6");
map.put("02", "7");
map.put("03", "8");
map.put("04", "9");
map.put("05", "3");
return map.inverse().get(val);
}
for (String data : getListStringValForElementTag(element, "organ-involvement1")) {
if(data != null) {
sectionAmlAllMds.getOrganInvolvement1().add(Pris3BMdmMapper.getLeukemiaInvolvement(data));
}
}
如何确保我的输出不包含null元素?我已经检查过null元素了,但是不起作用。我的输出是:
"organInvolvement1": ["01", "04", null, null, "05"]
此代码将读取XML标签“ organ-involvement1”内的元素数组列表:
getListStringValForElementTag(element, "organ-involvement1")
谢谢
答案 0 :(得分:0)
在这种情况下,data
不为空,但其值为null
。
试试这个:-
if(data != null && Pris3BMdmMapper.getLeukemiaInvolvement(data) != null) {
...
}
答案 1 :(得分:0)
您还可以覆盖add
方法。但这可能是过度设计:
List<String> list = new ArrayList<String>() {
@Override
public boolean add(String e) {
if (e == null) return false;
return super.add(e);
}
};
答案 2 :(得分:0)
您可以编写一个实用程序方法以从集合中排除空值:
pymongo: [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions
然后,在需要从集合中删除排除元素时调用它:
static void removeNulls(Collection<?> c) {
while(c.remove(null)) {
// Do Nothing
}
}