From: Jakub Skoczen Date: Fri, 22 Jul 2011 12:47:43 +0000 (+0200) Subject: Use StringBuilder instead of StringBuffer, optimize X-Git-Tag: v1.8~7 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=b07c9ebbcf1956dc21df4fb7737439e369e30e83;p=cql-java-moved-to-github.git Use StringBuilder instead of StringBuffer, optimize --- diff --git a/src/main/java/org/z3950/zing/cql/CQLSortNode.java b/src/main/java/org/z3950/zing/cql/CQLSortNode.java index 1c3aa14..55e69d5 100644 --- a/src/main/java/org/z3950/zing/cql/CQLSortNode.java +++ b/src/main/java/org/z3950/zing/cql/CQLSortNode.java @@ -52,13 +52,13 @@ public class CQLSortNode extends CQLNode { @Override public String toCQL() { - StringBuffer buf = new StringBuffer(subtree.toCQL()); + StringBuilder buf = new StringBuilder(subtree.toCQL()); if (keys != null) { buf.append(" sortby"); for (int i = 0; i < keys.size(); i++) { ModifierSet key = keys.get(i); - buf.append(" " + key.toCQL()); + buf.append(" ").append(key.toCQL()); } } diff --git a/src/main/java/org/z3950/zing/cql/Modifier.java b/src/main/java/org/z3950/zing/cql/Modifier.java index 7b9fbbe..9057dee 100644 --- a/src/main/java/org/z3950/zing/cql/Modifier.java +++ b/src/main/java/org/z3950/zing/cql/Modifier.java @@ -1,7 +1,6 @@ // $Id: Modifier.java,v 1.4 2007-07-03 13:29:34 mike Exp $ package org.z3950.zing.cql; -import java.lang.StringBuffer; /** * Represents a single modifier, consisting of three elements: a type, @@ -60,27 +59,27 @@ public class Modifier { } public String toXCQL(int level, String relationElement) { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); - buf.append(Utils.indent(level) + "\n"); - buf.append(Utils.indent(level+1) + - "" + Utils.xq(type) + "\n"); + buf.append(Utils.indent(level)).append("\n"). + append(Utils.indent(level + 1)).append(""). + append(Utils.xq(type)).append("\n"); if (value != null) { - buf.append(Utils.indent(level+1) + "<" + relationElement + ">" + - Utils.xq(comparison) + "\n"); - buf.append(Utils.indent(level+1) + - "" + Utils.xq(value) + "\n"); + buf.append(Utils.indent(level + 1)).append("<"). + append(relationElement).append(">"). + append(Utils.xq(comparison)).append("\n"). + append(Utils.indent(level + 1)).append(""). + append(Utils.xq(value)).append("\n"); } - - buf.append(Utils.indent(level) + "\n"); + buf.append(Utils.indent(level)).append("\n"); return buf.toString(); } public String toCQL() { - StringBuffer buf = new StringBuffer(type); + StringBuilder buf = new StringBuilder(type); if (value != null) - buf.append(" " + comparison + " " + value); - + buf.append(" ").append(comparison).append(" ").append(value); return buf.toString(); } } diff --git a/src/main/java/org/z3950/zing/cql/ModifierSet.java b/src/main/java/org/z3950/zing/cql/ModifierSet.java index 31fdad1..ce5915c 100644 --- a/src/main/java/org/z3950/zing/cql/ModifierSet.java +++ b/src/main/java/org/z3950/zing/cql/ModifierSet.java @@ -1,7 +1,6 @@ // $Id: ModifierSet.java,v 1.13 2007-07-03 13:30:18 mike Exp $ package org.z3950.zing.cql; -import java.lang.StringBuffer; import java.util.ArrayList; import java.util.List; @@ -88,26 +87,27 @@ public class ModifierSet { private String underlyingToXCQL(int level, String topLevelElement, String valueElement) { - StringBuffer buf = new StringBuffer(); - buf.append(Utils.indent(level) + "<" + topLevelElement + ">\n"); - buf.append(Utils.indent(level+1) + - "<" + valueElement + ">" + Utils.xq(base) + - "\n"); + StringBuilder buf = new StringBuilder(); + buf.append(Utils.indent(level)).append("<").append(topLevelElement). + append(">\n").append(Utils.indent(level + 1)).append("<"). + append(valueElement).append(">").append(Utils.xq(base)).append("\n"); if (modifiers.size() > 0) { - buf.append(Utils.indent(level+1) + "\n"); + buf.append(Utils.indent(level + 1)).append("\n"); for (int i = 0; i < modifiers.size(); i++) { buf.append(modifiers.get(i).toXCQL(level+2, "comparison")); } - buf.append(Utils.indent(level+1) + "\n"); + buf.append(Utils.indent(level + 1)).append("\n"); } - buf.append(Utils.indent(level) + "\n"); + buf.append(Utils.indent(level)).append("\n"); return buf.toString(); } public String toCQL() { - StringBuffer buf = new StringBuffer(base); + StringBuilder buf = new StringBuilder(base); for (int i = 0; i < modifiers.size(); i++) { - buf.append("/" + modifiers.get(i).toCQL()); + buf.append("/").append(modifiers.get(i).toCQL()); } return buf.toString();