Skip to content

Commit

Permalink
(chores) Fix StringBuilder append misuses
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio R. Piske <[email protected]>
  • Loading branch information
orpiske committed Aug 24, 2024
1 parent 513ddae commit 6a42f10
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,15 @@ public void setCreated(Date created) {
@Override
public String toString() {
StringBuilder temp = new StringBuilder();
temp.append(Order.class.getName() + " --> 1: " + this.account + ", 11: " + this.clOrdId
+ ", 58: " + this.text + ", 777: " + this.created);
temp.append(Order.class.getName())
.append(" --> 1: ")
.append(this.account)
.append(", 11: ")
.append(this.clOrdId)
.append(", 58: ")
.append(this.text)
.append(", 777: ")
.append(this.created);
temp.append("\r");

if (this.securities != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,12 @@ public void testCreateEndpointComposite2() throws Exception {
String outFile = "target/outfile.xml";
long timeout = 10000;
StringBuilder builder = new StringBuilder();
builder.append("exec:executable.exe").append("?workingDir=" + workingDir).append("&timeout=" + timeout);
builder.append("&outFile=" + outFile);
builder.append("exec:executable.exe")
.append("?workingDir=")
.append(workingDir)
.append("&timeout=")
.append(timeout);
builder.append("&outFile=").append(outFile);
builder.append("&commandExecutor=#customExecutor&binding=#customBinding");

ExecEndpoint e = createExecEndpoint(UnsafeUriCharactersEncoder.encode(builder.toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public void testExecJavaProcessInputLines() throws Exception {
final StringBuilder builder = new StringBuilder();
int lines = 10;
for (int t = 1; t < lines; t++) {
builder.append("Line" + t + System.lineSeparator());
builder.append("Line").append(t).append(System.lineSeparator());
}
String whiteSpaceSeparatedLines = builder.toString();
String expected = builder.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public void testExecJavaProcessInputLines() throws Exception {
final StringBuilder builder = new StringBuilder();
int lines = 10;
for (int t = 1; t < lines; t++) {
builder.append("Line" + t + System.lineSeparator());
builder.append("Line").append(t).append(System.lineSeparator());
}
String whiteSpaceSeparatedLines = builder.toString();
String expected = builder.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void testExecuteScript() {
private Exchange executeScript(final File scriptFile, long timeout, String... args) {
StringBuilder argsBuilder = new StringBuilder();
for (String arg : args) {
argsBuilder.append(arg + " ");
argsBuilder.append(arg).append(" ");
}
final String whiteSpaceSeparatedArgs = argsBuilder.toString().trim();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ private static String buildAntFileContent() {
StringBuilder builder = new StringBuilder();
builder.append("<project name=\"TestExec\" default=\"test\" basedir=\".\">");
builder.append("<target name=\"test\">");
builder.append("<echo message=\"" + TEST_MSG + "\"/>");
builder.append("<echo message=\"")
.append(TEST_MSG)
.append("\"/>");
builder.append("</target>");
builder.append("</project>");
return builder.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static String toString(PDU pdu) {

// prepare the header
if (pdu.getType() == PDU.V1TRAP) {
sb.append("<" + SNMP_TAG + " messageType=\"v1\">");
sb.append("<").append(SNMP_TAG).append(" messageType=\"v1\">");
} else {
sb.append(SNMP_TAG_OPEN);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ public ObjectName getObjectName(Object managedObject) throws MalformedObjectName
public ObjectName getObjectNameForCamelContext(String managementName, String name) throws MalformedObjectNameException {
StringBuilder buffer = new StringBuilder();
buffer.append(domainName).append(":");
buffer.append(KEY_CONTEXT + "=").append(getContextId(managementName)).append(",");
buffer.append(KEY_TYPE + "=" + TYPE_CONTEXT + ",");
buffer.append(KEY_NAME + "=").append(ObjectName.quote(name));
buffer.append(KEY_CONTEXT).append("=").append(getContextId(managementName)).append(",");
buffer.append(KEY_TYPE).append("=").append(TYPE_CONTEXT).append(",");
buffer.append(KEY_NAME).append("=").append(ObjectName.quote(name));
return createObjectName(buffer);
}

Expand All @@ -203,9 +203,9 @@ public ObjectName getObjectNameForCamelHealth(CamelContext context) throws Malfo

StringBuilder buffer = new StringBuilder();
buffer.append(domainName).append(":");
buffer.append(KEY_CONTEXT + "=").append(getContextId(managementName)).append(",");
buffer.append(KEY_TYPE + "=" + TYPE_HEALTH + ",");
buffer.append(KEY_NAME + "=").append("DefaultHealthCheck");
buffer.append(KEY_CONTEXT).append("=").append(getContextId(managementName)).append(",");
buffer.append(KEY_TYPE).append("=").append(TYPE_HEALTH).append(",");
buffer.append(KEY_NAME).append("=").append("DefaultHealthCheck");

return createObjectName(buffer);
}
Expand All @@ -221,9 +221,9 @@ public ObjectName getObjectNameForRouteController(CamelContext context, RouteCon

StringBuilder buffer = new StringBuilder();
buffer.append(domainName).append(":");
buffer.append(KEY_CONTEXT + "=").append(getContextId(managementName)).append(",");
buffer.append(KEY_TYPE + "=" + TYPE_SERVICE + ",");
buffer.append(KEY_NAME + "=").append(routeController.getClass().getSimpleName());
buffer.append(KEY_CONTEXT).append("=").append(getContextId(managementName)).append(",");
buffer.append(KEY_TYPE).append("=").append(TYPE_SERVICE).append(",");
buffer.append(KEY_NAME).append("=").append(routeController.getClass().getSimpleName());

return createObjectName(buffer);
}
Expand All @@ -232,9 +232,9 @@ public ObjectName getObjectNameForRouteController(CamelContext context, RouteCon
public ObjectName getObjectNameForEndpoint(Endpoint endpoint) throws MalformedObjectNameException {
StringBuilder buffer = new StringBuilder();
buffer.append(domainName).append(":");
buffer.append(KEY_CONTEXT + "=").append(getContextId(endpoint.getCamelContext())).append(",");
buffer.append(KEY_TYPE + "=" + TYPE_ENDPOINT + ",");
buffer.append(KEY_NAME + "=").append(ObjectName.quote(getEndpointId(endpoint)));
buffer.append(KEY_CONTEXT).append("=").append(getContextId(endpoint.getCamelContext())).append(",");
buffer.append(KEY_TYPE).append("=").append(TYPE_ENDPOINT).append(",");
buffer.append(KEY_NAME).append("=").append(ObjectName.quote(getEndpointId(endpoint)));
return createObjectName(buffer);
}

Expand All @@ -243,9 +243,9 @@ public ObjectName getObjectNameForDataFormat(CamelContext context, DataFormat da
throws MalformedObjectNameException {
StringBuilder buffer = new StringBuilder();
buffer.append(domainName).append(":");
buffer.append(KEY_CONTEXT + "=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE + "=" + TYPE_DATAFORMAT + ",");
buffer.append(KEY_NAME + "=").append(dataFormat.getClass().getSimpleName());
buffer.append(KEY_CONTEXT).append("=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE).append("=").append(TYPE_DATAFORMAT).append(",");
buffer.append(KEY_NAME).append("=").append(dataFormat.getClass().getSimpleName());
if (!(dataFormat instanceof StaticService)) {
buffer.append("(").append(ObjectHelper.getIdentityHashCode(dataFormat)).append(")");
}
Expand All @@ -256,9 +256,9 @@ public ObjectName getObjectNameForDataFormat(CamelContext context, DataFormat da
public ObjectName getObjectNameForComponent(Component component, String name) throws MalformedObjectNameException {
StringBuilder buffer = new StringBuilder();
buffer.append(domainName).append(":");
buffer.append(KEY_CONTEXT + "=").append(getContextId(component.getCamelContext())).append(",");
buffer.append(KEY_TYPE + "=" + TYPE_COMPONENT + ",");
buffer.append(KEY_NAME + "=").append(ObjectName.quote(name));
buffer.append(KEY_CONTEXT).append("=").append(getContextId(component.getCamelContext())).append(",");
buffer.append(KEY_TYPE).append("=").append(TYPE_COMPONENT).append(",");
buffer.append(KEY_NAME).append("=").append(ObjectName.quote(name));
return createObjectName(buffer);
}

Expand All @@ -267,14 +267,14 @@ public ObjectName getObjectNameForProcessor(CamelContext context, Processor proc
throws MalformedObjectNameException {
StringBuilder buffer = new StringBuilder();
buffer.append(domainName).append(":");
buffer.append(KEY_CONTEXT + "=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE + "=").append(TYPE_PROCESSOR).append(",");
buffer.append(KEY_CONTEXT).append("=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE).append("=").append(TYPE_PROCESSOR).append(",");
String id = definition.getId();
String prefix = definition.getNodePrefixId();
if (prefix != null) {
id = prefix + id;
}
buffer.append(KEY_NAME + "=").append(ObjectName.quote(id));
buffer.append(KEY_NAME).append("=").append(ObjectName.quote(id));
return createObjectName(buffer);
}

Expand All @@ -283,29 +283,29 @@ public ObjectName getObjectNameForStep(CamelContext context, Processor processor
throws MalformedObjectNameException {
StringBuilder buffer = new StringBuilder();
buffer.append(domainName).append(":");
buffer.append(KEY_CONTEXT + "=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE + "=").append(TYPE_STEP).append(",");
buffer.append(KEY_CONTEXT).append("=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE).append("=").append(TYPE_STEP).append(",");
String id = definition.getId();
String prefix = definition.getNodePrefixId();
if (prefix != null) {
id = prefix + id;
}
buffer.append(KEY_NAME + "=").append(ObjectName.quote(id));
buffer.append(KEY_NAME).append("=").append(ObjectName.quote(id));
return createObjectName(buffer);
}

@Override
public ObjectName getObjectNameForConsumer(CamelContext context, Consumer consumer) throws MalformedObjectNameException {
StringBuilder buffer = new StringBuilder();
buffer.append(domainName).append(":");
buffer.append(KEY_CONTEXT + "=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE + "=").append(TYPE_CONSUMER).append(",");
buffer.append(KEY_CONTEXT).append("=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE).append("=").append(TYPE_CONSUMER).append(",");

String name = consumer.getClass().getSimpleName();
if (ObjectHelper.isEmpty(name)) {
name = "Consumer";
}
buffer.append(KEY_NAME + "=")
buffer.append(KEY_NAME).append("=")
.append(name)
.append("(").append(ObjectHelper.getIdentityHashCode(consumer)).append(")");
return createObjectName(buffer);
Expand All @@ -315,8 +315,8 @@ public ObjectName getObjectNameForConsumer(CamelContext context, Consumer consum
public ObjectName getObjectNameForProducer(CamelContext context, Producer producer) throws MalformedObjectNameException {
StringBuilder buffer = new StringBuilder();
buffer.append(domainName).append(":");
buffer.append(KEY_CONTEXT + "=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE + "=").append(TYPE_PRODUCER).append(",");
buffer.append(KEY_CONTEXT).append("=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE).append("=").append(TYPE_PRODUCER).append(",");

String name = producer.getClass().getSimpleName();
if (ObjectHelper.isEmpty(name)) {
Expand All @@ -341,9 +341,9 @@ public ObjectName getObjectNameForTracer(CamelContext context, Service tracer) t

StringBuilder buffer = new StringBuilder();
buffer.append(domainName).append(":");
buffer.append(KEY_CONTEXT + "=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE + "=" + TYPE_TRACER + ",");
buffer.append(KEY_NAME + "=").append(name);
buffer.append(KEY_CONTEXT).append("=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE).append("=").append(TYPE_TRACER).append(",");
buffer.append(KEY_NAME).append("=").append(name);
return createObjectName(buffer);
}

Expand All @@ -352,15 +352,15 @@ public ObjectName getObjectNameForEventNotifier(CamelContext context, EventNotif
throws MalformedObjectNameException {
StringBuilder buffer = new StringBuilder();
buffer.append(domainName).append(":");
buffer.append(KEY_CONTEXT + "=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE + "=" + TYPE_EVENT_NOTIFIER + ",");
buffer.append(KEY_CONTEXT).append("=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE).append("=").append(TYPE_EVENT_NOTIFIER).append(",");

if (eventNotifier instanceof JmxNotificationEventNotifier) {
// JMX notifier shall have an easy to use name
buffer.append(KEY_NAME + "=").append("JmxEventNotifier");
buffer.append(KEY_NAME).append("=").append("JmxEventNotifier");
} else {
// others can be per instance
buffer.append(KEY_NAME + "=")
buffer.append(KEY_NAME).append("=")
.append("EventNotifier")
.append("(").append(ObjectHelper.getIdentityHashCode(eventNotifier)).append(")");
}
Expand All @@ -371,19 +371,19 @@ public ObjectName getObjectNameForEventNotifier(CamelContext context, EventNotif
public ObjectName getObjectNameForRoute(org.apache.camel.Route route) throws MalformedObjectNameException {
StringBuilder buffer = new StringBuilder();
buffer.append(domainName).append(":");
buffer.append(KEY_CONTEXT + "=").append(getContextId(route.getCamelContext())).append(",");
buffer.append(KEY_TYPE + "=" + TYPE_ROUTE + ",");
buffer.append(KEY_NAME + "=").append(ObjectName.quote(route.getId()));
buffer.append(KEY_CONTEXT).append("=").append(getContextId(route.getCamelContext())).append(",");
buffer.append(KEY_TYPE).append("=").append(TYPE_ROUTE).append(",");
buffer.append(KEY_NAME).append("=").append(ObjectName.quote(route.getId()));
return createObjectName(buffer);
}

@Override
public ObjectName getObjectNameForService(CamelContext context, Service service) throws MalformedObjectNameException {
StringBuilder buffer = new StringBuilder();
buffer.append(domainName).append(":");
buffer.append(KEY_CONTEXT + "=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE + "=" + TYPE_SERVICE + ",");
buffer.append(KEY_NAME + "=").append(service.getClass().getSimpleName());
buffer.append(KEY_CONTEXT).append("=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE).append("=").append(TYPE_SERVICE).append(",");
buffer.append(KEY_NAME).append("=").append(service.getClass().getSimpleName());
if (!(service instanceof StaticService)) {
buffer.append("(").append(ObjectHelper.getIdentityHashCode(service)).append(")");
}
Expand All @@ -395,9 +395,9 @@ public ObjectName getObjectNameForClusterService(CamelContext context, CamelClus
throws MalformedObjectNameException {
StringBuilder buffer = new StringBuilder();
buffer.append(domainName).append(":");
buffer.append(KEY_CONTEXT + "=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE + "=" + TYPE_HA + ",");
buffer.append(KEY_NAME + "=").append(service.getClass().getSimpleName());
buffer.append(KEY_CONTEXT).append("=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE).append("=").append(TYPE_HA).append(",");
buffer.append(KEY_NAME).append("=").append(service.getClass().getSimpleName());
if (!(service instanceof StaticService)) {
buffer.append("(").append(ObjectHelper.getIdentityHashCode(service)).append(")");
}
Expand All @@ -410,15 +410,15 @@ public ObjectName getObjectNameForThreadPool(
throws MalformedObjectNameException {
StringBuilder buffer = new StringBuilder();
buffer.append(domainName).append(":");
buffer.append(KEY_CONTEXT + "=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE + "=" + TYPE_THREAD_POOL + ",");
buffer.append(KEY_CONTEXT).append("=").append(getContextId(context)).append(",");
buffer.append(KEY_TYPE).append("=").append(TYPE_THREAD_POOL).append(",");

String name = id;
if (sourceId != null) {
// provide source id if we know it, this helps end user to know where the pool is used
name = name + "(" + sourceId + ")";
}
buffer.append(KEY_NAME + "=").append(ObjectName.quote(name));
buffer.append(KEY_NAME).append("=").append(ObjectName.quote(name));
return createObjectName(buffer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {

if (!models.isEmpty()) {
StringBuilder sb = new StringBuilder();
sb.append("# " + GENERATED_MSG + NL);
sb.append("# ").append(GENERATED_MSG).append(NL);
for (String name : models) {
sb.append(name).append(NL);
}
Expand Down

0 comments on commit 6a42f10

Please sign in to comment.