Skip to content
This repository
Browse code

Committed a patch set from Victor Toni.

He fixed the bug he reported earlier where the attribute type would
change on a setAttribute() call.

He did a stylistic fix to remove the cast to Element in the loop of
the isAncestor() method which was unnecessary because one can iterate
over the returned parent.

He changed almost all local variables and parameters to final.
This doesn't affect compiled code or inheritance.  It's just an
optimization and a safety check.

-jh-
  • Loading branch information...
commit b48373d95cd91986f83ac5345566258d80e88027 1 parent 0107926
authored August 15, 2006

Showing 1 changed file with 115 additions and 95 deletions. Show diff stats Hide diff stats

  1. 210  core/src/java/org/jdom/Element.java
210  core/src/java/org/jdom/Element.java
... ...
@@ -1,6 +1,6 @@
1 1
 /*--
2 2
 
3  
- $Id: Element.java,v 1.154 2004/12/11 00:27:38 jhunter Exp $
  3
+ $Id: Element.java,v 1.155 2006/08/15 00:42:18 jhunter Exp $
4 4
 
5 5
  Copyright (C) 2000-2004 Jason Hunter & Brett McLaughlin.
6 6
  All rights reserved.
@@ -66,7 +66,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
66 66
  * elements and content, directly access the element's textual content,
67 67
  * manipulate its attributes, and manage namespaces.
68 68
  *
69  
- * @version $Revision: 1.154 $, $Date: 2004/12/11 00:27:38 $
  69
+ * @version $Revision: 1.155 $, $Date: 2006/08/15 00:42:18 $
70 70
  * @author  Brett McLaughlin
71 71
  * @author  Jason Hunter
72 72
  * @author  Lucas Gonze
@@ -77,11 +77,12 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
77 77
  * @author  Jools Enticknap
78 78
  * @author  Alex Rosen
79 79
  * @author  Bradley S. Huffman
  80
+ * @author  Victor Toni
80 81
  */
81 82
 public class Element extends Content implements Parent {
82 83
 
83 84
     private static final String CVS_ID =
84  
-    "@(#) $RCSfile: Element.java,v $ $Revision: 1.154 $ $Date: 2004/12/11 00:27:38 $ $Name:  $";
  85
+    "@(#) $RCSfile: Element.java,v $ $Revision: 1.155 $ $Date: 2006/08/15 00:42:18 $ $Name:  $";
85 86
 
86 87
     private static final int INITIAL_ARRAY_SIZE = 5;
87 88
 
@@ -136,7 +137,7 @@ protected Element() { }
136 137
      * @throws IllegalNameException if the given name is illegal as an element
137 138
      *                              name
138 139
      */
139  
-    public Element(String name, Namespace namespace) {
  140
+    public Element(final String name, final Namespace namespace) {
140 141
         setName(name);
141 142
         setNamespace(namespace);
142 143
     }
@@ -148,7 +149,7 @@ public Element(String name, Namespace namespace) {
148 149
      * @throws IllegalNameException if the given name is illegal as an element
149 150
      *                              name.
150 151
      */
151  
-    public Element(String name) {
  152
+    public Element(final String name) {
152 153
         this(name, (Namespace) null);
153 154
     }
154 155
 
@@ -163,7 +164,7 @@ public Element(String name) {
163 164
      *                              name or the given URI is illegal as a
164 165
      *                              namespace URI
165 166
      */
166  
-    public Element(String name, String uri) {
  167
+    public Element(final String name, final String uri) {
167 168
         this(name, Namespace.getNamespace("", uri));
168 169
     }
169 170
 
@@ -179,7 +180,7 @@ public Element(String name, String uri) {
179 180
      *                              namespace prefix, or the given URI is
180 181
      *                              illegal as a namespace URI
181 182
      */
182  
-    public Element(String name, String prefix, String uri) {
  183
+    public Element(final String name, final String prefix, final String uri) {
183 184
         this(name, Namespace.getNamespace(prefix, uri));
184 185
     }
185 186
 
@@ -200,8 +201,8 @@ public String getName() {
200 201
      * @throws IllegalNameException if the given name is illegal as an Element
201 202
      *                              name
202 203
      */
203  
-    public Element setName(String name) {
204  
-        String reason = Verifier.checkElementName(name);
  204
+    public Element setName(final String name) {
  205
+        final String reason = Verifier.checkElementName(name);
205 206
         if (reason != null) {
206 207
             throw new IllegalNameException(name, "element", reason);
207 208
         }
@@ -266,7 +267,7 @@ public String getNamespaceURI() {
266 267
      * @return                     the Namespace for this prefix at this
267 268
      *                             location, or null if none
268 269
      */
269  
-    public Namespace getNamespace(String prefix) {
  270
+    public Namespace getNamespace(final String prefix) {
270 271
         if (prefix == null) {
271 272
             return null;
272 273
         }
@@ -284,7 +285,7 @@ public Namespace getNamespace(String prefix) {
284 285
         // Scan the additional namespaces
285 286
         if (additionalNamespaces != null) {
286 287
             for (int i = 0; i < additionalNamespaces.size(); i++) {
287  
-                Namespace ns = (Namespace) additionalNamespaces.get(i);
  288
+                final Namespace ns = (Namespace) additionalNamespaces.get(i);
288 289
                 if (prefix.equals(ns.getPrefix())) {
289 290
                     return ns;
290 291
                 }
@@ -332,11 +333,11 @@ public String getQualifiedName() {
332 333
      * @throws IllegalAddException if the namespace prefix collides with another
333 334
      *                             namespace prefix on the element
334 335
      */
335  
-    public void addNamespaceDeclaration(Namespace additional) {
  336
+    public void addNamespaceDeclaration(final Namespace additional) {
336 337
 
337 338
         // Verify the new namespace prefix doesn't collide with another
338 339
         // declared namespace, an attribute prefix, or this element's prefix
339  
-        String reason = Verifier.checkNamespaceCollision(additional, this);
  340
+        final String reason = Verifier.checkNamespaceCollision(additional, this);
340 341
         if (reason != null) {
341 342
             throw new IllegalAddException(this, additional, reason);
342 343
         }
@@ -394,11 +395,11 @@ public List getAdditionalNamespaces() {
394 395
      * @return a concatentation of all text node descendants
395 396
      */
396 397
     public String getValue() {
397  
-        StringBuffer buffer = new StringBuffer();
  398
+        final StringBuffer buffer = new StringBuffer();
398 399
 
399 400
         Iterator itr = getContent().iterator();
400 401
         while (itr.hasNext()) {
401  
-            Content child = (Content) itr.next();
  402
+            final Content child = (Content) itr.next();
402 403
             if (child instanceof Element || child instanceof Text) {
403 404
                 buffer.append(child.getValue());
404 405
             }
@@ -421,7 +422,7 @@ public int getContentSize() {
421 422
         return content.size();
422 423
     }
423 424
 
424  
-    public int indexOf(Content child) {
  425
+    public int indexOf(final Content child) {
425 426
         return content.indexOf(child);
426 427
     }
427 428
 
@@ -454,7 +455,7 @@ public String getText() {
454 455
 
455 456
         // If we hold only a Text or CDATA, return it directly
456 457
         if (content.size() == 1) {
457  
-            Object obj = content.get(0);
  458
+            final Object obj = content.get(0);
458 459
             if (obj instanceof Text) {
459 460
                 return ((Text) obj).getText();
460 461
             } else {
@@ -463,11 +464,11 @@ public String getText() {
463 464
         }
464 465
 
465 466
         // Else build String up
466  
-        StringBuffer textContent = new StringBuffer();
  467
+        final StringBuffer textContent = new StringBuffer();
467 468
         boolean hasText = false;
468 469
 
469 470
         for (int i = 0; i < content.size(); i++) {
470  
-            Object obj = content.get(i);
  471
+            final Object obj = content.get(i);
471 472
             if (obj instanceof Text) {
472 473
                 textContent.append(((Text) obj).getText());
473 474
                 hasText = true;
@@ -516,8 +517,8 @@ public String getTextNormalize() {
516 517
      * @return                     text content for the named child, or null if
517 518
      *                             no such child
518 519
      */
519  
-    public String getChildText(String name) {
520  
-        Element child = getChild(name);
  520
+    public String getChildText(final String name) {
  521
+        final Element child = getChild(name);
521 522
         if (child == null) {
522 523
             return null;
523 524
         }
@@ -533,8 +534,8 @@ public String getChildText(String name) {
533 534
      * @return                     trimmed text content for the named child, or
534 535
      *                             null if no such child
535 536
      */
536  
-    public String getChildTextTrim(String name) {
537  
-        Element child = getChild(name);
  537
+    public String getChildTextTrim(final String name) {
  538
+        final Element child = getChild(name);
538 539
         if (child == null) {
539 540
             return null;
540 541
         }
@@ -550,8 +551,8 @@ public String getChildTextTrim(String name) {
550 551
      * @return                     normalized text content for the named child,
551 552
      *                             or null if no such child
552 553
      */
553  
-    public String getChildTextNormalize(String name) {
554  
-        Element child = getChild(name);
  554
+    public String getChildTextNormalize(final String name) {
  555
+        final Element child = getChild(name);
555 556
         if (child == null) {
556 557
             return null;
557 558
         }
@@ -567,8 +568,8 @@ public String getChildTextNormalize(String name) {
567 568
      * @return                     text content for the named child, or null if
568 569
      *                             no such child
569 570
      */
570  
-    public String getChildText(String name, Namespace ns) {
571  
-        Element child = getChild(name, ns);
  571
+    public String getChildText(final String name, final Namespace ns) {
  572
+        final Element child = getChild(name, ns);
572 573
         if (child == null) {
573 574
             return null;
574 575
         }
@@ -584,8 +585,8 @@ public String getChildText(String name, Namespace ns) {
584 585
      * @return                     trimmed text content for the named child, or
585 586
      *                             null if no such child
586 587
      */
587  
-    public String getChildTextTrim(String name, Namespace ns) {
588  
-        Element child = getChild(name, ns);
  588
+    public String getChildTextTrim(final String name, final Namespace ns) {
  589
+        final Element child = getChild(name, ns);
589 590
         if (child == null) {
590 591
             return null;
591 592
         }
@@ -601,8 +602,8 @@ public String getChildTextTrim(String name, Namespace ns) {
601 602
      * @return                     normalized text content for the named child,
602 603
      *                             or null if no such child
603 604
      */
604  
-    public String getChildTextNormalize(String name, Namespace ns) {
605  
-        Element child = getChild(name, ns);
  605
+    public String getChildTextNormalize(final String name, final Namespace ns) {
  606
+        final Element child = getChild(name, ns);
606 607
         if (child == null) {
607 608
             return null;
608 609
         }
@@ -623,7 +624,7 @@ public String getChildTextNormalize(String name, Namespace ns) {
623 624
      *                              determined by {@link
624 625
      *                              org.jdom.Verifier#checkCharacterData})
625 626
      */
626  
-    public Element setText(String text) {
  627
+    public Element setText(final String text) {
627 628
         content.clear();
628 629
 
629 630
         if (text != null) {
@@ -671,7 +672,7 @@ public List getContent() {
671 672
      * @param filter <code>Filter</code> to apply
672 673
      * @return <code>List</code> - filtered Element content
673 674
      */
674  
-    public List getContent(Filter filter) {
  675
+    public List getContent(final Filter filter) {
675 676
         return content.getView(filter);
676 677
     }
677 678
 
@@ -692,11 +693,11 @@ public List removeContent() {
692 693
      * @param filter filter to select which content to remove
693 694
      * @return list of the old children detached from this parent
694 695
      */
695  
-    public List removeContent(Filter filter) {
696  
-        List old = new ArrayList();
697  
-        Iterator itr = content.getView(filter).iterator();
  696
+    public List removeContent(final Filter filter) {
  697
+        final List old = new ArrayList();
  698
+        final Iterator itr = content.getView(filter).iterator();
698 699
         while (itr.hasNext()) {
699  
-            Content child = (Content) itr.next();
  700
+            final Content child = (Content) itr.next();
700 701
             old.add(child);
701 702
             itr.remove();
702 703
         }
@@ -738,7 +739,7 @@ public List removeContent(Filter filter) {
738 739
      * @throws IllegalAddException if the List contains objects of
739 740
      *         illegal types or with existing parentage.
740 741
      */
741  
-    public Element setContent(Collection newContent) {
  742
+    public Element setContent(final Collection newContent) {
742 743
         content.clearAndSet(newContent);
743 744
         return this;
744 745
     }
@@ -758,7 +759,7 @@ public Element setContent(Collection newContent) {
758 759
      * @throws IndexOutOfBoundsException if index is negative or greater
759 760
      *         than the current number of children.
760 761
      */
761  
-    public Element setContent(int index, Content child) {
  762
+    public Element setContent(final int index, final Content child) {
762 763
         content.set(index, child);
763 764
         return this;
764 765
     }
@@ -779,7 +780,7 @@ public Element setContent(int index, Content child) {
779 780
      * @throws IndexOutOfBoundsException if index is negative or greater
780 781
      *         than the current number of children.
781 782
      */
782  
-    public Element setContent(int index, Collection collection) {
  783
+    public Element setContent(final int index, final Collection collection) {
783 784
         content.remove(index);
784 785
         content.addAll(index, collection);
785 786
         return this;
@@ -795,7 +796,7 @@ public Element setContent(int index, Collection collection) {
795 796
      *         illegal character such as a vertical tab (as determined
796 797
      *         by {@link org.jdom.Verifier#checkCharacterData})
797 798
      */
798  
-    public Element addContent(String str) {
  799
+    public Element addContent(final String str) {
799 800
         return addContent(new Text(str));
800 801
     }
801 802
 
@@ -805,7 +806,7 @@ public Element addContent(String str) {
805 806
      * @param child   child to append to end of content list
806 807
      * @return        the element on which the method was called
807 808
      * @throws IllegalAddException if the given child already has a parent.     */
808  
-    public Element addContent(Content child) {
  809
+    public Element addContent(final Content child) {
809 810
         content.add(child);
810 811
         return this;
811 812
     }
@@ -821,7 +822,7 @@ public Element addContent(Content child) {
821 822
      * @throws IllegalAddException if any item in the collection
822 823
      *         already has a parent or is of an inappropriate type.
823 824
      */
824  
-    public Element addContent(Collection collection) {
  825
+    public Element addContent(final Collection collection) {
825 826
         content.addAll(collection);
826 827
         return this;
827 828
     }
@@ -836,7 +837,7 @@ public Element addContent(Collection collection) {
836 837
      *         the current number of children
837 838
      * @throws IllegalAddException if the given child already has a parent.
838 839
      */
839  
-    public Element addContent(int index, Content child) {
  840
+    public Element addContent(final int index, final Content child) {
840 841
         content.add(index, child);
841 842
         return this;
842 843
     }
@@ -855,22 +856,22 @@ public Element addContent(int index, Content child) {
855 856
      * @throws IllegalAddException if any item in the collection
856 857
      *         already has a parent or is of an inappropriate type.
857 858
      */
858  
-    public Element addContent(int index, Collection c) {
  859
+    public Element addContent(final int index, final Collection c) {
859 860
         content.addAll(index, c);
860 861
         return this;
861 862
     }
862 863
 
863 864
     public List cloneContent() {
864  
-        int size = getContentSize();
865  
-        List list = new ArrayList(size);
  865
+        final int size = getContentSize();
  866
+        final List list = new ArrayList(size);
866 867
         for (int i = 0; i < size; i++) {
867  
-            Content child = getContent(i);
  868
+            final Content child = getContent(i);
868 869
             list.add(child.clone());
869 870
         }
870 871
         return list;
871 872
     }
872 873
 
873  
-    public Content getContent(int index) {
  874
+    public Content getContent(final int index) {
874 875
         return (Content) content.get(index);
875 876
     }
876 877
 
@@ -879,11 +880,11 @@ public Content getContent(int index) {
879 880
 //        return (i < 0) ? null : getContent(i);
880 881
 //    }
881 882
 
882  
-    public boolean removeContent(Content child) {
  883
+    public boolean removeContent(final Content child) {
883 884
         return content.remove(child);
884 885
     }
885 886
 
886  
-    public Content removeContent(int index) {
  887
+    public Content removeContent(final int index) {
887 888
         return (Content) content.remove(index);
888 889
     }
889 890
 
@@ -914,7 +915,7 @@ public Content removeContent(int index) {
914 915
      * @throws IllegalAddException if the supplied child is already attached
915 916
      *                             or not legal content for an Element
916 917
      */
917  
-    public Element setContent(Content child) {
  918
+    public Element setContent(final Content child) {
918 919
         content.clear();
919 920
         content.add(child);
920 921
         return this;
@@ -928,13 +929,13 @@ public Element setContent(Content child) {
928 929
      * @return <code>true</code> if this element is the ancestor of the
929 930
      *         supplied element
930 931
      */
931  
-    public boolean isAncestor(Element element) {
932  
-        Object p = element.getParent();
  932
+    public boolean isAncestor(final Element element) {
  933
+        Parent p = element.getParent();
933 934
         while (p instanceof Element) {
934 935
             if (p == this) {
935 936
                 return true;
936 937
             }
937  
-            p = ((Element) p).getParent();
  938
+            p = p.getParent();
938 939
         }
939 940
         return false;
940 941
     }
@@ -963,7 +964,7 @@ public List getAttributes() {
963 964
      * @param name name of the attribute to return
964 965
      * @return attribute for the element
965 966
      */
966  
-    public Attribute getAttribute(String name) {
  967
+    public Attribute getAttribute(final String name) {
967 968
         return getAttribute(name, Namespace.NO_NAMESPACE);
968 969
     }
969 970
 
@@ -977,7 +978,7 @@ public Attribute getAttribute(String name) {
977 978
      * @param ns <code>Namespace</code> to search within
978 979
      * @return attribute for the element
979 980
      */
980  
-    public Attribute getAttribute(String name, Namespace ns) {
  981
+    public Attribute getAttribute(final String name, final Namespace ns) {
981 982
         return (Attribute) attributes.get(name, ns);
982 983
     }
983 984
 
@@ -991,7 +992,7 @@ public Attribute getAttribute(String name, Namespace ns) {
991 992
      * @param name name of the attribute whose value to be returned
992 993
      * @return the named attribute's value, or null if no such attribute
993 994
      */
994  
-    public String getAttributeValue(String name) {
  995
+    public String getAttributeValue(final String name) {
995 996
         return getAttributeValue(name, Namespace.NO_NAMESPACE);
996 997
     }
997 998
 
@@ -1006,7 +1007,7 @@ public String getAttributeValue(String name) {
1006 1007
      * @param def a default value to return if the attribute does not exist
1007 1008
      * @return the named attribute's value, or the default if no such attribute
1008 1009
      */
1009  
-    public String getAttributeValue(String name, String def) {
  1010
+    public String getAttributeValue(final String name, final String def) {
1010 1011
         return getAttributeValue(name, Namespace.NO_NAMESPACE, def);
1011 1012
     }
1012 1013
 
@@ -1021,7 +1022,7 @@ public String getAttributeValue(String name, String def) {
1021 1022
      * @param ns <code>Namespace</code> to search within
1022 1023
      * @return the named attribute's value, or null if no such attribute
1023 1024
      */
1024  
-    public String getAttributeValue(String name, Namespace ns) {
  1025
+    public String getAttributeValue(final String name, final Namespace ns) {
1025 1026
         return getAttributeValue(name, ns, null);
1026 1027
     }
1027 1028
 
@@ -1037,8 +1038,8 @@ public String getAttributeValue(String name, Namespace ns) {
1037 1038
      * @param def a default value to return if the attribute does not exist
1038 1039
      * @return the named attribute's value, or the default if no such attribute
1039 1040
      */
1040  
-    public String getAttributeValue(String name, Namespace ns, String def) {
1041  
-        Attribute attribute = (Attribute) attributes.get(name, ns);
  1041
+    public String getAttributeValue(final String name, final Namespace ns, final String def) {
  1042
+        final Attribute attribute = (Attribute) attributes.get(name, ns);
1042 1043
         return (attribute == null) ? def : attribute.getValue();
1043 1044
     }
1044 1045
 
@@ -1085,7 +1086,7 @@ public String getAttributeValue(String name, Namespace ns, String def) {
1085 1086
      *         or if any of the <code>Attribute</code> objects have
1086 1087
      *         conflicting namespace prefixes.
1087 1088
      */
1088  
-    public Element setAttributes(List newAttributes) {
  1089
+    public Element setAttributes(final List newAttributes) {
1089 1090
         attributes.clearAndSet(newAttributes);
1090 1091
         return this;
1091 1092
     }
@@ -1105,8 +1106,16 @@ public Element setAttributes(List newAttributes) {
1105 1106
      *         illegal character data (as determined by
1106 1107
      *         {@link org.jdom.Verifier#checkCharacterData}).
1107 1108
      */
1108  
-    public Element setAttribute(String name, String value) {
1109  
-        return setAttribute(new Attribute(name, value));
  1109
+    public Element setAttribute(final String name, final String value) {
  1110
+        final Attribute attribute = getAttribute(name);
  1111
+        if (attribute == null) {
  1112
+            final Attribute newAttribute = new Attribute(name, value);
  1113
+            setAttribute(newAttribute);
  1114
+        } else {
  1115
+            attribute.setValue(value);
  1116
+        }
  1117
+        
  1118
+        return this;
1110 1119
     }
1111 1120
 
1112 1121
     /**
@@ -1128,8 +1137,16 @@ public Element setAttribute(String name, String value) {
1128 1137
      * @throws IllegalAddException if the attribute namespace prefix
1129 1138
      *         collides with another namespace prefix on the element.
1130 1139
      */
1131  
-    public Element setAttribute(String name, String value, Namespace ns) {
1132  
-        return setAttribute(new Attribute(name, value, ns));
  1140
+    public Element setAttribute(final String name, final String value, final Namespace ns) {
  1141
+        final Attribute attribute = getAttribute(name, ns);
  1142
+        if (attribute == null) {
  1143
+            final Attribute newAttribute = new Attribute(name, value, ns);
  1144
+            setAttribute(newAttribute);
  1145
+        } else {
  1146
+            attribute.setValue(value);
  1147
+        }
  1148
+        
  1149
+        return this;
1133 1150
     }
1134 1151
 
1135 1152
     /**
@@ -1144,7 +1161,7 @@ public Element setAttribute(String name, String value, Namespace ns) {
1144 1161
      *   parent or if the attribute namespace prefix collides with another
1145 1162
      *   namespace prefix on the element.
1146 1163
      */
1147  
-    public Element setAttribute(Attribute attribute) {
  1164
+    public Element setAttribute(final Attribute attribute) {
1148 1165
         attributes.add(attribute);
1149 1166
         return this;
1150 1167
     }
@@ -1158,7 +1175,7 @@ public Element setAttribute(Attribute attribute) {
1158 1175
      * @param name name of attribute to remove
1159 1176
      * @return whether the attribute was removed
1160 1177
      */
1161  
-    public boolean removeAttribute(String name) {
  1178
+    public boolean removeAttribute(final String name) {
1162 1179
         return removeAttribute(name, Namespace.NO_NAMESPACE);
1163 1180
     }
1164 1181
 
@@ -1173,7 +1190,7 @@ public boolean removeAttribute(String name) {
1173 1190
      * @param ns namespace URI of attribute to remove
1174 1191
      * @return whether the attribute was removed
1175 1192
      */
1176  
-    public boolean removeAttribute(String name, Namespace ns) {
  1193
+    public boolean removeAttribute(final String name, final Namespace ns) {
1177 1194
         return attributes.remove(name, ns);
1178 1195
     }
1179 1196
 
@@ -1185,7 +1202,7 @@ public boolean removeAttribute(String name, Namespace ns) {
1185 1202
      * @param attribute Reference to the attribute to be removed.
1186 1203
      * @return whether the attribute was removed
1187 1204
      */
1188  
-    public boolean removeAttribute(Attribute attribute) {
  1205
+    public boolean removeAttribute(final Attribute attribute) {
1189 1206
         return attributes.remove(attribute);
1190 1207
     }
1191 1208
 
@@ -1202,12 +1219,12 @@ public boolean removeAttribute(Attribute attribute) {
1202 1219
      *         <code>Element</code>
1203 1220
      */
1204 1221
     public String toString() {
1205  
-        StringBuffer stringForm = new StringBuffer(64)
  1222
+        final StringBuffer stringForm = new StringBuffer(64)
1206 1223
             .append("[Element: <")
1207 1224
             .append(getQualifiedName());
1208 1225
 
1209  
-        String nsuri = getNamespaceURI();
1210  
-        if (!nsuri.equals("")) {
  1226
+        final String nsuri = getNamespaceURI();
  1227
+        if (!"".equals(nsuri)) {
1211 1228
             stringForm
1212 1229
             .append(" [Namespace: ")
1213 1230
             .append(nsuri)
@@ -1274,7 +1291,7 @@ public Object clone() {
1274 1291
 
1275 1292
     // Support a custom Namespace serialization so no two namespace
1276 1293
     // object instances may exist for the same prefix/uri pair
1277  
-    private void writeObject(ObjectOutputStream out) throws IOException {
  1294
+    private void writeObject(final ObjectOutputStream out) throws IOException {
1278 1295
 
1279 1296
         out.defaultWriteObject();
1280 1297
 
@@ -1290,14 +1307,14 @@ private void writeObject(ObjectOutputStream out) throws IOException {
1290 1307
             int size = additionalNamespaces.size();
1291 1308
             out.write(size);
1292 1309
             for (int i = 0; i < size; i++) {
1293  
-                Namespace additional = (Namespace) additionalNamespaces.get(i);
  1310
+                final Namespace additional = (Namespace) additionalNamespaces.get(i);
1294 1311
                 out.writeObject(additional.getPrefix());
1295 1312
                 out.writeObject(additional.getURI());
1296 1313
             }
1297 1314
         }
1298 1315
     }
1299 1316
 
1300  
-    private void readObject(ObjectInputStream in)
  1317
+    private void readObject(final ObjectInputStream in)
1301 1318
         throws IOException, ClassNotFoundException {
1302 1319
 
1303 1320
         in.defaultReadObject();
@@ -1305,12 +1322,12 @@ private void readObject(ObjectInputStream in)
1305 1322
         namespace = Namespace.getNamespace(
1306 1323
             (String)in.readObject(), (String)in.readObject());
1307 1324
 
1308  
-        int size = in.read();
  1325
+        final int size = in.read();
1309 1326
 
1310 1327
         if (size != 0) {
1311 1328
             additionalNamespaces = new ArrayList(size);
1312 1329
             for (int i = 0; i < size; i++) {
1313  
-                Namespace additional = Namespace.getNamespace(
  1330
+                final Namespace additional = Namespace.getNamespace(
1314 1331
                     (String)in.readObject(), (String)in.readObject());
1315 1332
                 additionalNamespaces.add(additional);
1316 1333
             }
@@ -1335,8 +1352,9 @@ public Iterator getDescendants() {
1335 1352
      * @param filter filter to select which descendants to see
1336 1353
      * @return an iterator to walk descendants within a filter
1337 1354
      */
1338  
-    public Iterator getDescendants(Filter filter) {
1339  
-        return new FilterIterator(new DescendantIterator(this), filter);
  1355
+    public Iterator getDescendants(final Filter filter) {
  1356
+        final Iterator iterator = new DescendantIterator(this);
  1357
+        return new FilterIterator(iterator, filter);
1340 1358
     }
1341 1359
 
1342 1360
 
@@ -1392,7 +1410,7 @@ public List getChildren() {
1392 1410
      * @param name local name for the children to match
1393 1411
      * @return all matching child elements
1394 1412
      */
1395  
-    public List getChildren(String name) {
  1413
+    public List getChildren(final String name) {
1396 1414
         return getChildren(name, Namespace.NO_NAMESPACE);
1397 1415
     }
1398 1416
 
@@ -1413,7 +1431,7 @@ public List getChildren(String name) {
1413 1431
      * @param ns <code>Namespace</code> to search within
1414 1432
      * @return all matching child elements
1415 1433
      */
1416  
-    public List getChildren(String name, Namespace ns) {
  1434
+    public List getChildren(final String name, final Namespace ns) {
1417 1435
         return content.getView(new ElementFilter(name, ns));
1418 1436
     }
1419 1437
 
@@ -1427,9 +1445,9 @@ public List getChildren(String name, Namespace ns) {
1427 1445
      * @param ns <code>Namespace</code> to search within
1428 1446
      * @return the first matching child element, or null if not found
1429 1447
      */
1430  
-    public Element getChild(String name, Namespace ns) {
1431  
-        List elements = content.getView(new ElementFilter(name, ns));
1432  
-        Iterator i = elements.iterator();
  1448
+    public Element getChild(final String name, final Namespace ns) {
  1449
+        final List elements = content.getView(new ElementFilter(name, ns));
  1450
+        final Iterator i = elements.iterator();
1433 1451
         if (i.hasNext()) {
1434 1452
             return (Element) i.next();
1435 1453
         }
@@ -1445,7 +1463,7 @@ public Element getChild(String name, Namespace ns) {
1445 1463
      * @param name local name of child element to match
1446 1464
      * @return the first matching child element, or null if not found
1447 1465
      */
1448  
-    public Element getChild(String name) {
  1466
+    public Element getChild(final String name) {
1449 1467
         return getChild(name, Namespace.NO_NAMESPACE);
1450 1468
     }
1451 1469
 
@@ -1459,7 +1477,7 @@ public Element getChild(String name) {
1459 1477
      * @param name the name of child elements to remove
1460 1478
      * @return whether deletion occurred
1461 1479
      */
1462  
-    public boolean removeChild(String name) {
  1480
+    public boolean removeChild(final String name) {
1463 1481
         return removeChild(name, Namespace.NO_NAMESPACE);
1464 1482
     }
1465 1483
 
@@ -1474,9 +1492,10 @@ public boolean removeChild(String name) {
1474 1492
      * @param ns <code>Namespace</code> to search within
1475 1493
      * @return whether deletion occurred
1476 1494
      */
1477  
-    public boolean removeChild(String name, Namespace ns) {
1478  
-        List old = content.getView(new ElementFilter(name, ns));
1479  
-        Iterator i = old.iterator();
  1495
+    public boolean removeChild(final String name, final Namespace ns) {
  1496
+        final Filter filter = new ElementFilter(name, ns);
  1497
+        final List old = content.getView(filter);
  1498
+        final Iterator i = old.iterator();
1480 1499
         if (i.hasNext()) {
1481 1500
             i.next();
1482 1501
             i.remove();
@@ -1496,7 +1515,7 @@ public boolean removeChild(String name, Namespace ns) {
1496 1515
      * @param name the name of child elements to remove
1497 1516
      * @return whether deletion occurred
1498 1517
      */
1499  
-    public boolean removeChildren(String name) {
  1518
+    public boolean removeChildren(final String name) {
1500 1519
         return removeChildren(name, Namespace.NO_NAMESPACE);
1501 1520
     }
1502 1521
 
@@ -1511,11 +1530,12 @@ public boolean removeChildren(String name) {
1511 1530
      * @param ns <code>Namespace</code> to search within
1512 1531
      * @return whether deletion occurred
1513 1532
      */
1514  
-    public boolean removeChildren(String name, Namespace ns) {
  1533
+    public boolean removeChildren(final String name, final Namespace ns) {
1515 1534
         boolean deletedSome = false;
1516 1535
 
1517  
-        List old = content.getView(new ElementFilter(name, ns));
1518  
-        Iterator i = old.iterator();
  1536
+        final Filter filter = new ElementFilter(name, ns);
  1537
+        final List old = content.getView(filter);
  1538
+        final Iterator i = old.iterator();
1519 1539
         while (i.hasNext()) {
1520 1540
             i.next();
1521 1541
             i.remove();

0 notes on commit b48373d

Please sign in to comment.
Something went wrong with that request. Please try again.