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);
|
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() : "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -33,7 +33,7 @@
|
|||||||
## ChangeSubject.vm and ChangeFooter.vm.
|
## ChangeSubject.vm and ChangeFooter.vm.
|
||||||
##
|
##
|
||||||
#if($email.reviewerNames)
|
#if($email.reviewerNames)
|
||||||
Hello $StringUtils.join($email.reviewerNames, ', '),
|
Hello $email.joinStrings($email.reviewerNames, ', '),
|
||||||
|
|
||||||
I'd like you to do a code review.#if($email.changeUrl) Please visit
|
I'd like you to do a code review.#if($email.changeUrl) Please visit
|
||||||
|
|
||||||
|
@@ -33,7 +33,7 @@
|
|||||||
## ChangeEmail: see ChangeSubject.vm and ChangeFooter.vm.
|
## ChangeEmail: see ChangeSubject.vm and ChangeFooter.vm.
|
||||||
##
|
##
|
||||||
#if($email.reviewerNames)
|
#if($email.reviewerNames)
|
||||||
Hello $StringUtils.join($email.reviewerNames, ', '),
|
Hello $email.joinStrings($email.reviewerNames, ', '),
|
||||||
|
|
||||||
I'd like you to reexamine a change.#if($email.changeUrl) Please visit
|
I'd like you to reexamine a change.#if($email.changeUrl) Please visit
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user