@@ -80,12 +80,12 @@ class MavenJDOMWriter {
80
80
/**
81
81
* Field factory.
82
82
*/
83
- private DefaultJDOMFactory factory ;
83
+ private final DefaultJDOMFactory factory ;
84
84
85
85
/**
86
86
* Field lineSeparator.
87
87
*/
88
- private String lineSeparator ;
88
+ private final String lineSeparator ;
89
89
90
90
// ----------------/
91
91
// - Constructors -/
@@ -175,7 +175,7 @@ protected Element findAndReplaceSimpleElement(Counter counter, Element parent, S
175
175
}
176
176
}
177
177
178
- boolean shouldExist = (text != null ) && (text .trim ().length () > 0 );
178
+ boolean shouldExist = (text != null ) && (! text .trim ().isEmpty () );
179
179
Element element = updateElement (counter , parent , name , shouldExist );
180
180
if (shouldExist ) {
181
181
element .setText (text );
@@ -262,7 +262,7 @@ protected void insertAtPreferredLocation(Element parent, Element child, Counter
262
262
Iterator it = parent .getContent ().iterator ();
263
263
Text lastText = null ;
264
264
int offset = 0 ;
265
- while (it .hasNext () && (elementCounter <= counter .getCurrentIndex ())) {
265
+ while (it .hasNext () && (elementCounter < counter .getCurrentIndex ())) {
266
266
Object next = it .next ();
267
267
offset = offset + 1 ;
268
268
if (next instanceof Element ) {
@@ -274,17 +274,13 @@ protected void insertAtPreferredLocation(Element parent, Element child, Counter
274
274
lastText = (Text ) next ;
275
275
}
276
276
}
277
- if ((lastText != null ) && (lastText .getTextTrim ().length () == 0 )) {
278
- lastText = ( Text ) lastText .clone ();
277
+ if ((lastText != null ) && (lastText .getTextTrim ().isEmpty () )) {
278
+ lastText = lastText .clone ();
279
279
} else {
280
- StringBuilder starter = new StringBuilder (lineSeparator );
281
- for (int i = 0 ; i < counter .getDepth (); i ++) {
282
- starter .append (" " );
283
- }
284
- lastText = factory .text (starter .toString ());
280
+ lastText = factory .text (lineSeparator + " " .repeat (Math .max (0 , counter .getDepth ())));
285
281
}
286
282
if (parent .getContentSize () == 0 ) {
287
- Text finalText = ( Text ) lastText .clone ();
283
+ Text finalText = lastText .clone ();
288
284
finalText .setText (finalText .getText ().substring (0 , finalText .getText ().length () - " " .length ()));
289
285
parent .addContent (contentIndex , finalText );
290
286
}
0 commit comments