From ae435beec10d8fbe1934a10638e8ed34d154b0d6 Mon Sep 17 00:00:00 2001 From: Arturo Bernal Date: Sat, 2 Oct 2021 10:31:27 +0200 Subject: [PATCH] JSPWIKI-1157 - Remove redundant String --- .../src/main/java/org/apache/wiki/TranslationsCheck.java | 6 +++--- .../java/org/apache/wiki/content/DefaultPageRenamer.java | 6 +++--- .../org/apache/wiki/parser/CreoleToJSPWikiTranslator.java | 8 ++++---- .../java/org/apache/wiki/parser/JSPWikiMarkupParser.java | 2 +- .../main/java/org/apache/wiki/plugin/WeblogPlugin.java | 2 +- .../src/main/java/org/apache/wiki/util/TextUtil.java | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/jspwiki-main/src/main/java/org/apache/wiki/TranslationsCheck.java b/jspwiki-main/src/main/java/org/apache/wiki/TranslationsCheck.java index b04cbdaf82..4a764e9d4e 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/TranslationsCheck.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/TranslationsCheck.java @@ -126,7 +126,7 @@ Map< String, Integer > checkFile( final String en, final String lang ) throws IO System.out.println( iter.next() ); } } - System.out.println( "" ); + System.out.println( ); return metrics; } @@ -157,7 +157,7 @@ public Map< String, Integer > diff( final String source1, final String source2 ) } } if( missing > 0 ) { - System.out.println( "" ); + System.out.println(); } iter = sortedNames( p2 ).iterator(); @@ -175,7 +175,7 @@ public Map< String, Integer > diff( final String source1, final String source2 ) } } if( outdated > 0 ) { - System.out.println( "" ); + System.out.println(); } final Map< String, Integer > diff = new HashMap<>( 2 ); diff --git a/jspwiki-main/src/main/java/org/apache/wiki/content/DefaultPageRenamer.java b/jspwiki-main/src/main/java/org/apache/wiki/content/DefaultPageRenamer.java index b1bb8c6250..022b14d62f 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/content/DefaultPageRenamer.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/content/DefaultPageRenamer.java @@ -234,7 +234,7 @@ private String replaceCCReferrerString( final Context context, final String sour while( matcher.find( start ) ) { final String match = matcher.group(); - sb.append( sourceText.substring( start, matcher.start() ) ); + sb.append( sourceText, start, matcher.start() ); final int lastOpenBrace = sourceText.lastIndexOf( '[', matcher.start() ); final int lastCloseBrace = sourceText.lastIndexOf( ']', matcher.start() ); @@ -270,7 +270,7 @@ private String replaceReferrerString( final Context context, final String source if( !matcher.group(1).isEmpty() || charBefore == '~' || charBefore == '[' ) { // Found an escape character, so I am escaping. - sb.append( sourceText.substring( start, matcher.end() ) ); + sb.append( sourceText, start, matcher.end() ); start = matcher.end(); continue; } @@ -291,7 +291,7 @@ private String replaceReferrerString( final Context context, final String source // // Construct the new string // - sb.append( sourceText.substring( start, matcher.start() ) ); + sb.append( sourceText, start, matcher.start() ); sb.append( "[" ).append( text ); if( !link.isEmpty() ) { sb.append( "|" ).append( link ); diff --git a/jspwiki-main/src/main/java/org/apache/wiki/parser/CreoleToJSPWikiTranslator.java b/jspwiki-main/src/main/java/org/apache/wiki/parser/CreoleToJSPWikiTranslator.java index 2626e6f797..f314ca7e85 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/parser/CreoleToJSPWikiTranslator.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/parser/CreoleToJSPWikiTranslator.java @@ -290,7 +290,7 @@ private static String translateLists(final String content, final String sourceSy && (actSourceSymbol.equals("") || line.substring(0, 1).equals(actSourceSymbol))) { actSourceSymbol = line.substring(0, 1); - line = line.substring(1, line.length()); + line = line.substring( 1 ); counter++; } if ((inList == -1 && counter != 1) || (inList != -1 && inList + 1 < counter)) @@ -358,7 +358,7 @@ private String unprotectMarkup(String content, final boolean replacePlugins) final String protectedMarkup = c_protectionMap.get(hash); content = content.replace(hash, protectedMarkup); if ((protectedMarkup.length() < 3 || (protectedMarkup.length() > 2 && - !protectedMarkup.substring(0, 3).equals("{{{")))&&replacePlugins) + !protectedMarkup.startsWith("{{{")))&&replacePlugins) content = translateElement(content, CREOLE_PLUGIN, JSPWIKI_PLUGIN); } @@ -475,7 +475,7 @@ private String replaceImageArea(final Properties wikiProps, final String content final int pos = contentCopy.indexOf(temp); contentCopy = contentCopy.substring(0, pos) + protectedMarkup - + contentCopy.substring(pos + temp.length(), contentCopy.length()); + + contentCopy.substring(pos + temp.length()); } return contentCopy; } @@ -492,7 +492,7 @@ private String replaceArea(final String content, final String markupRegex, final protectedMarkup = protectedMarkup.replaceAll(replaceSource, replaceTarget); final int pos = contentCopy.indexOf(temp); contentCopy = contentCopy.substring(0, pos) + protectedMarkup - + contentCopy.substring(pos + temp.length(), contentCopy.length()); + + contentCopy.substring(pos + temp.length() ); } return contentCopy; } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java b/jspwiki-main/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java index 3c8e6fcc73..e4c9b4dc4e 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java @@ -1602,7 +1602,7 @@ private Element handleGeneralList() { // Substitute all but the last character (keep the expressed bullet preference) strBullets = (numBullets > 1 ? m_genlistBulletBuffer.substring(0, numBullets-1) : "") - + strBullets.substring(numBullets-1, numBullets); + + strBullets.charAt( numBullets-1 ); } else { diff --git a/jspwiki-main/src/main/java/org/apache/wiki/plugin/WeblogPlugin.java b/jspwiki-main/src/main/java/org/apache/wiki/plugin/WeblogPlugin.java index 8311b1aac8..fe6ba1aaef 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/plugin/WeblogPlugin.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/plugin/WeblogPlugin.java @@ -325,7 +325,7 @@ private void addEntryHTML( final Context context, final DateFormat entryFormat, } cutoff++; } - buffer.append(html.substring(0, cutoff)); + buffer.append( html, 0, cutoff ); if (hasBeenCutOff) { buffer.append( " " ).append( rb.getString( "weblogentryplugin.more" ) ).append( "\n" ); } diff --git a/jspwiki-util/src/main/java/org/apache/wiki/util/TextUtil.java b/jspwiki-util/src/main/java/org/apache/wiki/util/TextUtil.java index d7bd856d06..efabc9bb06 100644 --- a/jspwiki-util/src/main/java/org/apache/wiki/util/TextUtil.java +++ b/jspwiki-util/src/main/java/org/apache/wiki/util/TextUtil.java @@ -241,7 +241,7 @@ public static String replaceString( final String orig, final String src, final S int last = 0; while ( ( start = orig.indexOf( src,end ) ) != -1 ) { - res.append( orig.substring( last, start ) ); + res.append( orig, last, start ); res.append( dest ); end = start + src.length(); last = start + src.length(); @@ -291,7 +291,7 @@ public static String replaceStringCaseUnsensitive( final String orig, final Stri final String origCaseUnsn = orig.toLowerCase(); final String srcCaseUnsn = src.toLowerCase(); while( ( start = origCaseUnsn.indexOf( srcCaseUnsn, end ) ) != -1 ) { - res.append( orig.substring( last, start ) ); + res.append( orig, last, start ); res.append( dest ); end = start + src.length(); last = start + src.length(); @@ -829,7 +829,7 @@ public static String generateRandomPassword() { final StringBuilder pw = new StringBuilder(); for( int i = 0; i < PASSWORD_LENGTH; i++ ) { final int index = ( int )( RANDOM.nextDouble() * PWD_BASE.length() ); - pw.append(PWD_BASE.substring(index, index + 1)); + pw.append(PWD_BASE.charAt( index )); } return pw.toString(); }