1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 06:12:05 +01:00

Use StringBuilder instead of String concatenation

This commit is contained in:
Paul Schaub 2019-12-13 18:28:09 +01:00
parent 2391cffa97
commit 85ff749d89
2 changed files with 17 additions and 10 deletions

View file

@ -209,15 +209,17 @@ public abstract class OmemoBundleElement implements ExtensionElement {
@Override @Override
public String toString() { public String toString() {
String out = "OmemoBundleElement[\n"; StringBuilder sb = new StringBuilder("OmemoBundleElement[\n");
out += SIGNED_PRE_KEY_PUB + " " + SIGNED_PRE_KEY_ID + "=" + signedPreKeyId + ": " + signedPreKeyB64 + "\n"; sb.append(SIGNED_PRE_KEY_PUB).append(' ').append(SIGNED_PRE_KEY_ID).append('=').append(signedPreKeyId)
out += SIGNED_PRE_KEY_SIG + ": " + signedPreKeySignatureB64 + "\n"; .append(':').append(signedPreKeyB64).append('\n')
out += IDENTITY_KEY + ": " + identityKeyB64 + "\n"; .append(SIGNED_PRE_KEY_SIG).append(": ").append(signedPreKeySignatureB64).append('\n')
out += PRE_KEYS + " (" + preKeysB64.size() + ")\n"; .append(IDENTITY_KEY).append(": ").append(identityKeyB64).append('\n')
.append(PRE_KEYS).append(" (").append(preKeysB64.size()).append(")\n");
for (Map.Entry<Integer, String> e : preKeysB64.entrySet()) { for (Map.Entry<Integer, String> e : preKeysB64.entrySet()) {
out += PRE_KEY_PUB + " " + PRE_KEY_ID + "=" + e.getKey() + ": " + e.getValue() + "\n"; sb.append(PRE_KEY_PUB).append(' ').append(PRE_KEY_ID).append("=").append(e.getKey()).append(": ").append(e.getValue()).append("\n");
} }
return out; sb.append("]");
return sb.toString();
} }
@Override @Override

View file

@ -18,6 +18,7 @@ package org.jivesoftware.smackx.omemo.element;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.Set; import java.util.Set;
import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.packet.ExtensionElement;
@ -78,10 +79,14 @@ public abstract class OmemoDeviceListElement implements ExtensionElement {
@Override @Override
public final String toString() { public final String toString() {
String out = "OmemoDeviceListElement["; StringBuilder sb = new StringBuilder("OmemoDeviceListElement[");
Iterator<Integer> iterator = deviceIds.iterator();
for (int i : deviceIds) { for (int i : deviceIds) {
out += i + ","; sb.append(i);
} if (iterator.hasNext()) {
return out.substring(0, out.length() - 1) + "]"; sb.append(',');
}
}
return sb.append(']').toString();
} }
} }