Move string utils join logic into Gerrit
Version 2.4 of Apache Commons Lang doesn't have the join method. Work around it by implementing our own string joiner. Change-Id: I87e252acf1efdb10aa2d0e96445669748a92ecc8
This commit is contained in:
@@ -369,4 +369,30 @@ public abstract class OutgoingEmail {
|
||||
throw new EmailException("Velocity template " + name + ".\n", e);
|
||||
}
|
||||
}
|
||||
|
||||
public String joinStrings(Iterable<Object> in, String joiner) {
|
||||
return joinStrings(in.iterator(), joiner);
|
||||
}
|
||||
|
||||
public String joinStrings(Iterator<Object> in, String joiner) {
|
||||
if (!in.hasNext()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
Object first = in.next();
|
||||
if (!in.hasNext()) {
|
||||
return safeToString(first);
|
||||
}
|
||||
|
||||
StringBuilder r = new StringBuilder();
|
||||
r.append(safeToString(first));
|
||||
while (in.hasNext()) {
|
||||
r.append(joiner).append(safeToString(in.next()));
|
||||
}
|
||||
return r.toString();
|
||||
}
|
||||
|
||||
private static String safeToString(Object obj) {
|
||||
return obj != null ? obj.toString() : "";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user