Modernize list and string handling in query processors

Change-Id: Ie2dc8756bc38d90abd546009cbeae88cd5c0e6a9
diff --git a/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/FCSSRUQueryParser.java b/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/FCSSRUQueryParser.java
index c4d0fa1..3babf9c 100644
--- a/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/FCSSRUQueryParser.java
+++ b/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/FCSSRUQueryParser.java
@@ -2,6 +2,7 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 import de.ids_mannheim.korap.query.object.KoralContext;
@@ -125,7 +126,7 @@
     private KoralGroup parseWithinQuery(QueryWithWithin queryNode)
             throws KoralException {
         KoralGroup koralGroup = new KoralGroup(KoralOperation.POSITION);
-        koralGroup.setFrames(Arrays.asList(KoralFrame.IS_AROUND));
+        koralGroup.setFrames(Collections.singletonList(KoralFrame.IS_AROUND));
 
         List<KoralObject> operands = new ArrayList<KoralObject>();
         operands.add(parseQueryNode(queryNode.getWithin()));
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
index 4bc806a..f2ed6e1 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
@@ -1550,14 +1550,13 @@
                     Pattern.compile("(\\+|-)?(sa|se|pa|pe|ta|te)");
             Matcher conditionMatcher =
                     conditionPattern.matcher(conditionsString);
-            String replacement = "#BED(" + m.group(1) + " , ";
+            StringBuilder replacement = new StringBuilder("#BED(" + m.group(1) + " , ");
             while (conditionMatcher.find()) {
-                replacement = replacement + conditionMatcher.group() + ",";
+                replacement.append(conditionMatcher.group()).append(",");
             }
             // remove trailing comma and close parenthesis
-            replacement =
-                    replacement.substring(0, replacement.length() - 1) + ")";
-            rewrittenQuery = rewrittenQuery.replace(match, replacement);
+            replacement = new StringBuilder(replacement.substring(0, replacement.length() - 1) + ")");
+            rewrittenQuery = rewrittenQuery.replace(match, replacement.toString());
         }
         return rewrittenQuery;
     }
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
index aed8c3d..7cde9c1 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
@@ -639,9 +639,7 @@
         CollectionQueryProcessor cq = new CollectionQueryProcessor(
                 node.getChild(1).getText());
         requestMap.put("collection", cq.getRequestMap().get("collection"));
-        for (ParseTree child : getChildren(node)) {
-            visited.add(child);
-        }
+        visited.addAll(getChildren(node));
     }
 
 
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/QueryUtils.java b/src/main/java/de/ids_mannheim/korap/query/serialize/QueryUtils.java
index 47b5e09..5845f70 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/QueryUtils.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/QueryUtils.java
@@ -73,87 +73,86 @@
                 break;
         }
 
-        StringBuffer buffer = new StringBuffer();
-        buffer.append("<query><cypher><![CDATA[");
-        buffer.append(cypher);
-        buffer.append("]]></cypher>");
-        buffer.append("<wordAliasPrefix>wtok_</wordAliasPrefix>");
-        buffer.append("<contextColumn>sent</contextColumn>");
-        buffer.append("<contextIdColumn>sid</contextIdColumn>");
-        buffer.append("<textColumn>txt</textColumn>");
-        buffer.append("<startIndex>");
-        buffer.append(page);
-        buffer.append("</startIndex>");
-        buffer.append("<itemsPerPage>");
-        buffer.append(limit);
-        buffer.append("</itemsPerPage>");
-        buffer.append("<context>");
-        buffer.append("<left>");
-        buffer.append("<" + sctypel + ">");
-        buffer.append(cl);
-        buffer.append("</" + sctypel + ">");
-        buffer.append("</left>");
-        buffer.append("<right>");
-        buffer.append("<" + sctyper + ">");
-        buffer.append(cr);
-        buffer.append("</" + sctyper + ">");
-        buffer.append("</right>");
-        buffer.append("</context>");
-        buffer.append("</query>");
-        return buffer.toString();
+        return new StringBuffer()
+                .append("<query><cypher><![CDATA[")
+                .append(cypher)
+                .append("]]></cypher>")
+                .append("<wordAliasPrefix>wtok_</wordAliasPrefix>")
+                .append("<contextColumn>sent</contextColumn>")
+                .append("<contextIdColumn>sid</contextIdColumn>")
+                .append("<textColumn>txt</textColumn>")
+                .append("<startIndex>")
+                .append(page)
+                .append("</startIndex>")
+                .append("<itemsPerPage>")
+                .append(limit)
+                .append("</itemsPerPage>")
+                .append("<context>")
+                .append("<left>")
+                .append("<").append(sctypel).append(">")
+                .append(cl)
+                .append("</").append(sctypel).append(">")
+                .append("</left>")
+                .append("<right>")
+                .append("<").append(sctyper).append(">")
+                .append(cr)
+                .append("</").append(sctyper).append(">")
+                .append("</right>")
+                .append("</context>")
+                .append("</query>")
+                .toString();
     }
 
 
     public static String buildDotQuery (long sid, String graphdb_id) {
-        StringBuffer b = new StringBuffer();
-        b.append("<query>");
-        b.append("<sentenceId>");
-        b.append(sid);
-        b.append("</sentenceId>");
-        b.append("<gdbId>");
-        b.append(graphdb_id);
-        b.append("</gdbId>");
-        b.append("<hls>");
-        b.append("<hl>");
-        b.append(40857);
-        b.append("</hl>");
-        b.append("<hl>");
-        b.append(40856);
-        b.append("</hl>");
-        b.append("</hls>");
-        b.append("</query>");
-
-        return b.toString();
+        return new StringBuffer()
+                .append("<query>")
+                .append("<sentenceId>")
+                .append(sid)
+                .append("</sentenceId>")
+                .append("<gdbId>")
+                .append(graphdb_id)
+                .append("</gdbId>")
+                .append("<hls>")
+                .append("<hl>")
+                .append(40857)
+                .append("</hl>")
+                .append("<hl>")
+                .append(40856)
+                .append("</hl>")
+                .append("</hls>")
+                .append("</query>")
+                .toString();
     }
 
 
     public String buildaggreQuery (String query) {
-        StringBuffer b = new StringBuffer();
-        b.append("<query><cypher><![CDATA[");
-        b.append(query);
-        b.append("]]></cypher>");
-        b.append("<columns>");
-        b.append("<column agg='true' sum='false'>");
-        b.append("<cypherAlias>");
-        b.append("aggBy");
-        b.append("</cypherAlias>");
-        b.append("<displayName>");
-        b.append("Aggregate");
-        b.append("</displayName>");
-        b.append("</column>");
+        return new StringBuffer()
+                .append("<query><cypher><![CDATA[")
+                .append(query)
+                .append("]]></cypher>")
+                .append("<columns>")
+                .append("<column agg='true' sum='false'>")
+                .append("<cypherAlias>")
+                .append("aggBy")
+                .append("</cypherAlias>")
+                .append("<displayName>")
+                .append("Aggregate")
+                .append("</displayName>")
+                .append("</column>")
 
-        b.append("<column agg='fals' sum='true'>");
-        b.append("<cypherAlias>");
-        b.append("cnt");
-        b.append("</cypherAlias>");
-        b.append("<displayName>");
-        b.append("Count");
-        b.append("</displayName>");
-        b.append("</column>");
-        b.append("</columns>");
+                .append("<column agg='fals' sum='true'>")
+                .append("<cypherAlias>")
+                .append("cnt")
+                .append("</cypherAlias>")
+                .append("<displayName>")
+                .append("Count")
+                .append("</displayName>")
+                .append("</column>")
+                .append("</columns>")
 
-        b.append("</query>");
-        return b.toString();
+                .append("</query>")
+                .toString();
     }