I think something is more complete than necessary if you need to do
getLD().get(cam.getName()).getAGS().get(aG.getName())
If you need to check if the second collection or the result is null, you can do something like:
Map<?,?> firstList= getLD(); Object value = null; if (firstList!=null && !firstList.isEmpty() && fistList.containsKey(cam.getName())){ Map<?,?> secondList = firstList.get(cam.getName()); if (secondList!=null && !secondList.isEmpty() && secondList.containsKey(aG.getName())){ value = secondList.get(aG.getName()); } } if(value != null){
With this code, I checked if the first set is not null, is not empty, and has content. I get the second collection, and I repeated this process in the second collection.
Also, to create this operation, a method can be created:
private Map<?,?> getItem(Map<?,?> map,Object key){ if (map!=null && !map.isEmpty() && map.containsKey(key)){ return map.get(key); } return null; }
and in your code:
Object value = getItem(getItem(getLD(),cam.getName()),aG.getName()); if(value != null){ // Do the required operations if the value is not null }else{ // Do the required operations if the value is null }
source share