Remove use of StringBuffer 39/82639/2
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 21 Jun 2019 05:32:36 +0000 (07:32 +0200)
committerJakubToth <jtoth@luminanetworks.com>
Fri, 21 Jun 2019 10:57:37 +0000 (10:57 +0000)
StringBuilder is a faster replacement for StringBuffer, use that.
Also cleans up append() usage, so we do not do superfluous string
concatenations.

Change-Id: I2dd973dab6199290e2cbdd840f36b754b14827ad
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/ConcurrentClientsTest.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPatchBodyReader.java

index a1fac6bdc5eacd031714e33b10884c8cce817b0b..0462214578593409fa474e69dcc082d2558edff3 100644 (file)
@@ -330,8 +330,8 @@ public class ConcurrentClientsTest {
             DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
             InputStreamReader inFromServer = new InputStreamReader(clientSocket.getInputStream());
 
-            StringBuffer sb = new StringBuffer();
-            while (sb.toString().endsWith("]]>]]>") == false) {
+            StringBuilder sb = new StringBuilder();
+            while (!sb.toString().endsWith("]]>]]>")) {
                 sb.append((char) inFromServer.read());
             }
             LOG.info(sb.toString());
@@ -344,8 +344,8 @@ public class ConcurrentClientsTest {
             outToServer.write("]]>]]>".getBytes());
             outToServer.flush();
             Thread.sleep(100);
-            sb = new StringBuffer();
-            while (sb.toString().endsWith("]]>]]>") == false) {
+            sb = new StringBuilder();
+            while (!sb.toString().endsWith("]]>]]>")) {
                 sb.append((char) inFromServer.read());
             }
             LOG.info(sb.toString());
index 605ba4c526ebf389d07d61cc776674bd29686582..e60306061404c21341ddbaf2622bdc23d82fc82b 100644 (file)
@@ -230,7 +230,7 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider
     private void readEditDefinition(final @NonNull PatchEdit edit, final @NonNull JsonReader in,
                                     final @NonNull InstanceIdentifierContext<?> path,
                                     final @NonNull StringModuleInstanceIdentifierCodec codec) throws IOException {
-        final StringBuffer value = new StringBuffer();
+        final StringBuilder value = new StringBuilder();
         in.beginObject();
 
         while (in.hasNext()) {
@@ -279,35 +279,35 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider
      * @param in JsonReader reader
      * @throws IOException if operation fails
      */
-    private void readValueNode(final @NonNull StringBuffer value, final @NonNull JsonReader in) throws IOException {
+    private void readValueNode(final @NonNull StringBuilder value, final @NonNull JsonReader in) throws IOException {
         in.beginObject();
-        value.append("{");
+        value.append('{');
 
-        value.append("\"" + in.nextName() + "\"" + ":");
+        value.append('"').append(in.nextName()).append("\":");
 
         if (in.peek() == JsonToken.BEGIN_ARRAY) {
             in.beginArray();
-            value.append("[");
+            value.append('[');
 
             while (in.hasNext()) {
                 if (in.peek() == JsonToken.STRING) {
-                    value.append("\"" + in.nextString() + "\"");
+                    value.append('"').append(in.nextString()).append('"');
                 } else {
                     readValueObject(value, in);
                 }
                 if (in.peek() != JsonToken.END_ARRAY) {
-                    value.append(",");
+                    value.append(',');
                 }
             }
 
             in.endArray();
-            value.append("]");
+            value.append(']');
         } else {
             readValueObject(value, in);
         }
 
         in.endObject();
-        value.append("}");
+        value.append('}');
     }
 
     /**
@@ -316,52 +316,51 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider
      * @param in JsonReader reader
      * @throws IOException if operation fails
      */
-    private void readValueObject(final @NonNull StringBuffer value, final @NonNull JsonReader in) throws IOException {
+    private void readValueObject(final @NonNull StringBuilder value, final @NonNull JsonReader in) throws IOException {
         // read simple leaf value
         if (in.peek() == JsonToken.STRING) {
-            value.append("\"" + in.nextString() + "\"");
+            value.append('"').append(in.nextString()).append('"');
             return;
         }
 
         in.beginObject();
-        value.append("{");
+        value.append('{');
 
         while (in.hasNext()) {
-            value.append("\"" + in.nextName() + "\"");
-            value.append(":");
+            value.append('"').append(in.nextName()).append("\":");
 
             if (in.peek() == JsonToken.STRING) {
-                value.append("\"" + in.nextString() + "\"");
+                value.append('"').append(in.nextString()).append('"');
             } else {
                 if (in.peek() == JsonToken.BEGIN_ARRAY) {
                     in.beginArray();
-                    value.append("[");
+                    value.append('[');
 
                     while (in.hasNext()) {
                         if (in.peek() == JsonToken.STRING) {
-                            value.append("\"" + in.nextString() + "\"");
+                            value.append('"').append(in.nextString()).append('"');
                         } else {
                             readValueObject(value, in);
                         }
                         if (in.peek() != JsonToken.END_ARRAY) {
-                            value.append(",");
+                            value.append(',');
                         }
                     }
 
                     in.endArray();
-                    value.append("]");
+                    value.append(']');
                 } else {
                     readValueObject(value, in);
                 }
             }
 
             if (in.peek() != JsonToken.END_OBJECT) {
-                value.append(",");
+                value.append(',');
             }
         }
 
         in.endObject();
-        value.append("}");
+        value.append('}');
     }
 
     /**