For example, the following code caused an NPE this morning because result didn't have a "data" child:
Element data = result.getChild("data"); int count = new Integer(Strings.noNull(data.getAttributeValue("count"), "0")).intValue();
If a picker were used then the code would have returned zero, the default value.
int count = picker(result,"data","count",0);
The key aspect of the picker is that it checks every working value before using it. For the example above, the picker would be implemented as
int picker(Element tree, String elementName, String attributeName, int defaultValue) { if (tree == null) { return defaultValue; } Element element = tree.getChild(elementName); if (element == null) { return defaultValue; } String attributeValue = element.getAttributeValue(attributeName); if (attributeValue == null) { return defaultValue; } try { return Integer.parseInt(attributeValue); } catch (NumberFormatException e) { return defaultValue; } }