@@ -274,9 +274,11 @@ public StyleElement getStyleElement(final String name) {
274274 */
275275 public StyleElement getStyleElementCaseInSensitive (final String name ) {
276276 final Map <String , StyleElement > map = getStyleMap ();
277- for (final Map .Entry <String , StyleElement > entry : map .entrySet ()) {
278- if (entry .getKey ().equalsIgnoreCase (name )) {
279- return entry .getValue ();
277+ if (map != null ) {
278+ for (final Map .Entry <String , StyleElement > entry : map .entrySet ()) {
279+ if (entry .getKey ().equalsIgnoreCase (name )) {
280+ return entry .getValue ();
281+ }
280282 }
281283 }
282284 return null ;
@@ -620,16 +622,17 @@ public void writeStyleToElement(final Map<String, StyleElement> styleMap) {
620622 return ;
621623 }
622624
623- final StringBuilder builder = new StringBuilder ();
624625 final List <StyleElement > styleElements = new ArrayList <>(styleMap .values ());
625626 styleElements .sort (STYLE_ELEMENT_COMPARATOR );
627+
628+ final StringBuilder builder = new StringBuilder (styleElements .size () * 32 );
626629 for (final StyleElement e : styleElements ) {
627- if (builder .length () != 0 ) {
630+ if (builder .length () > 0 ) {
628631 builder .append (' ' );
629632 }
630633 builder .append (e .getName ())
631- .append (": " )
632- .append (e .getValue ());
634+ .append (": " )
635+ .append (e .getValue ());
633636
634637 final String prio = e .getPriority ();
635638 if (StringUtils .isNotBlank (prio )) {
@@ -798,11 +801,12 @@ public DomElement getFirstElementChild() {
798801 * @return the last child element node of this element. null if this element has no child elements
799802 */
800803 public DomElement getLastElementChild () {
801- DomElement lastChild = null ;
802- for (final DomElement domElement : getChildElements ()) {
803- lastChild = domElement ;
804+ for (DomNode child = getLastChild (); child != null ; child = child .getPreviousSibling ()) {
805+ if (child instanceof DomElement elem ) {
806+ return elem ;
807+ }
804808 }
805- return lastChild ;
809+ return null ;
806810 }
807811
808812 /**
@@ -811,9 +815,10 @@ public DomElement getLastElementChild() {
811815 */
812816 public int getChildElementCount () {
813817 int counter = 0 ;
814-
815- for (final DomElement domElement : getChildElements ()) {
816- counter ++;
818+ for (DomNode child = getFirstChild (); child != null ; child = child .getNextSibling ()) {
819+ if (child instanceof DomElement ) {
820+ counter ++;
821+ }
817822 }
818823 return counter ;
819824 }
@@ -1841,8 +1846,7 @@ public DomAttr put(final String key, final DomAttr value) {
18411846 @ Override
18421847 public DomAttr remove (final Object key ) {
18431848 if (key instanceof String string ) {
1844- final String name = fixName (string );
1845- return map_ .remove (name );
1849+ return map_ .remove (fixName (string ));
18461850 }
18471851 return null ;
18481852 }
@@ -1884,8 +1888,7 @@ public boolean containsKey(final Object key) {
18841888 @ Override
18851889 public DomAttr get (final Object key ) {
18861890 if (key instanceof String string ) {
1887- final String name = fixName (string );
1888- return map_ .get (name );
1891+ return map_ .get (fixName (string ));
18891892 }
18901893 return null ;
18911894 }
0 commit comments