Permalink
Browse files

Add mechanism to get number of attributes on an Element

  • Loading branch information...
1 parent 4521c3b commit c67fdb20d1e2892633d9d2ca7103f44ebe71247f @rolfl rolfl committed Jan 7, 2013
Showing with 13 additions and 0 deletions.
  1. +13 −0 core/src/java/org/jdom2/Element.java
@@ -1095,16 +1095,29 @@ AttributeList getAttributeList() {
* This returns the complete set of attributes for this element, as a
* <code>List</code> of <code>Attribute</code> objects in no particular
* order, or an empty list if there are none.
+ * </p>
* The returned list is "live" and changes to it affect the
* element's actual attributes.
* </p>
+ * Use the methods {@link #hasAttributes()} or {@link #getAttributesSize()}
+ * if you just want to see whether there are attributes. Calling this method
+ * may be inefficient if there are no Attributes.
*
* @return attributes for the element
*/
public List<Attribute> getAttributes() {
return getAttributeList();
}
+
+ /**
+ * Get the number of Attributes currently attached to this Element.
+ * @return the number of Attributes attached.
+ */
+ public int getAttributesSize() {
+ return attributes == null ? 0 : attributes.size();
+ }
+
/**
* <p>
* This returns the attribute for this element with the given name

0 comments on commit c67fdb2

Please sign in to comment.