Suggest the following Java class:
/** Utility class for working with DOM nodes.
*/
public class DomNodes {
public static boolean isElement(Node pNode, String pElementName, String... pAttributes) {
if (pNode.getNodeType() == Node.ELEMENT_NODE) {
final Element e = (Element) pNode;
final String uri = e.getNamespaceURI();
if (uri == null || uri.length() == 0) {
if (pElementName.equals(e.getLocalPart())) {
if (pAttributes == null || areAttributesMatching(pNode, pAttributes)) {
return true;
}
}
}
}
}
}
Now, suggest the following two uses of that class:
isElement(node, "foo");
isElement(node, "foo", "attribute0", value0, "attribute1", value1, "attribute2", value2);
It is obvious to me, that the second invocation depends on the construction of a string array. In other words, there is a small performance penalty for the construction of that array.
The first invocation, however, isn't obvious: The compiler could implement this by passing a newly constructed array with no elements. However, it might just as well pass the value null, or a constant array.
In the former case, I could help the compiler by adding a method
isElement(Node pNode, String pElementName)
. Question: Would you recommend that?