You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by jo...@apache.org on 2016/12/19 22:43:13 UTC

[07/14] opennlp git commit: Replace StringBuilder with String

Replace StringBuilder with String

Using a String concatenation makes the code shorter and simpler.

See issue OPENNLP-871


Project: http://git-wip-us.apache.org/repos/asf/opennlp/repo
Commit: http://git-wip-us.apache.org/repos/asf/opennlp/commit/c3eeb5c5
Tree: http://git-wip-us.apache.org/repos/asf/opennlp/tree/c3eeb5c5
Diff: http://git-wip-us.apache.org/repos/asf/opennlp/diff/c3eeb5c5

Branch: refs/heads/trunk
Commit: c3eeb5c530e9b0e738f84e74c774b4f63d944a7f
Parents: 7ef7235
Author: J�rn Kottmann <jo...@apache.org>
Authored: Wed Nov 2 19:57:47 2016 +0100
Committer: J�rn Kottmann <jo...@apache.org>
Committed: Mon Dec 19 23:37:33 2016 +0100

----------------------------------------------------------------------
 .../java/opennlp/tools/cmdline/GenerateManualTool.java    |  6 ++----
 .../opennlp/tools/parser/AbstractContextGenerator.java    | 10 ++--------
 .../tools/sentdetect/DefaultSDContextGenerator.java       |  8 ++++----
 .../opennlp/tools/sentdetect/SentenceDetectorFactory.java |  4 +---
 4 files changed, 9 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/opennlp/blob/c3eeb5c5/opennlp-tools/src/main/java/opennlp/tools/cmdline/GenerateManualTool.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/GenerateManualTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/GenerateManualTool.java
index ed58dde..b42f69c 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/GenerateManualTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/GenerateManualTool.java
@@ -76,10 +76,8 @@ public class GenerateManualTool {
    * @return this tool usage
    */
   private static String getUsage() {
-    StringBuilder sb = new StringBuilder();
-    sb.append("Requires one argument: \n");
-    sb.append("  Path to the output XML file \n");
-    return sb.toString();
+    return "Requires one argument: \n" +
+            "  Path to the output XML file \n";
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/opennlp/blob/c3eeb5c5/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractContextGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractContextGenerator.java
index f537576..09d3b0f 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractContextGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractContextGenerator.java
@@ -42,10 +42,7 @@ public abstract class AbstractContextGenerator {
    * @return Punctuation feature for the specified parse and the specified punctuation at the specfied index.
    */
   protected String punct(Parse punct, int i) {
-    StringBuilder feat = new StringBuilder(5);
-    feat.append(i).append("=");
-    feat.append(punct.getCoveredText());
-    return feat.toString();
+    return String.valueOf(i) + "=" + punct.getCoveredText();
   }
 
   /**
@@ -55,10 +52,7 @@ public abstract class AbstractContextGenerator {
    * @return Punctuation feature for the specified parse and the specified punctuation at the specfied index.
    */
   protected String punctbo(Parse punct, int i) {
-    StringBuilder feat = new StringBuilder(5);
-    feat.append(i).append("=");
-    feat.append(punct.getType());
-    return feat.toString();
+    return String.valueOf(i) + "=" + punct.getType();
   }
 
   protected String cons(Parse p, int i) {

http://git-wip-us.apache.org/repos/asf/opennlp/blob/c3eeb5c5/opennlp-tools/src/main/java/opennlp/tools/sentdetect/DefaultSDContextGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/DefaultSDContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/DefaultSDContextGenerator.java
index 7559a14..822c43b 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/DefaultSDContextGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/DefaultSDContextGenerator.java
@@ -129,10 +129,10 @@ public class DefaultSDContextGenerator implements SDContextGenerator {
           }
         }
       }
-      prefix = new StringBuffer(sb.subSequence(prefixStart, position)).toString().trim();
+      prefix = String.valueOf(sb.subSequence(prefixStart, position)).trim();
     }
     int prevStart = previousSpaceIndex(sb, prefixStart);
-    previous = new StringBuffer(sb.subSequence(prevStart, prefixStart)).toString().trim();
+    previous = String.valueOf(sb.subSequence(prevStart, prefixStart)).trim();
 
     int suffixEnd = nextSpaceIndex(sb, position, lastIndex);
     {
@@ -153,8 +153,8 @@ public class DefaultSDContextGenerator implements SDContextGenerator {
       next = "";
     }
     else {
-      suffix = new StringBuilder(sb.subSequence(position + 1, suffixEnd)).toString().trim();
-      next = new StringBuilder(sb.subSequence(suffixEnd + 1, nextEnd)).toString().trim();
+      suffix = String.valueOf(sb.subSequence(position + 1, suffixEnd)).trim();
+      next = String.valueOf(sb.subSequence(suffixEnd + 1, nextEnd)).trim();
     }
 
     collectFeatures(prefix,suffix,previous,next, sb.charAt(position));

http://git-wip-us.apache.org/repos/asf/opennlp/blob/c3eeb5c5/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorFactory.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorFactory.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorFactory.java
index d7e962f..c6d02cb 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorFactory.java
@@ -205,9 +205,7 @@ public class SentenceDetectorFactory extends BaseToolFactory {
   }
 
   private String eosCharArrayToString(char[] eosCharacters) {
-    StringBuilder eosString = new StringBuilder();
-    eosString.append(eosCharacters);
-    return eosString.toString();
+    return String.valueOf(eosCharacters);
   }
 
   private char[] eosStringToCharArray(String eosCharacters) {