Skip to content

Commit 731f52f

Browse files
committed
Add toQuoteComment method
1 parent eb5eeca commit 731f52f

1 file changed

Lines changed: 43 additions & 4 deletions

File tree

  • src/main/java/com/junichi11/netbeans/modules/github/issues/utils

src/main/java/com/junichi11/netbeans/modules/github/issues/utils/StringUtils.java

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
package com.junichi11.netbeans.modules.github.issues.utils;
4343

4444
import java.util.List;
45+
import java.util.StringTokenizer;
4546

4647
/**
4748
*
@@ -52,17 +53,55 @@ public final class StringUtils {
5253
private StringUtils() {
5354
}
5455

56+
/**
57+
* Check whether specified string is {@code null} or empty.
58+
*
59+
* @param text text
60+
* @return {@code true} text is {@code null} or empty, otherwise
61+
* {@code false}
62+
*/
5563
public static boolean isEmpty(String text) {
5664
return text == null || text.isEmpty();
5765
}
5866

67+
/**
68+
* Combine tokens with a specified separator.
69+
*
70+
* @param tokens tokens
71+
* @param separator separator
72+
* @return one combined string, empty string if token or separator are
73+
* {@code null}
74+
*/
5975
public static String join(List<String> tokens, String separator) {
6076
StringBuilder sb = new StringBuilder();
61-
for (String token : tokens) {
62-
if (sb.length() > 0) {
63-
sb.append(separator);
77+
if (tokens != null && separator != null) {
78+
for (String token : tokens) {
79+
if (sb.length() > 0) {
80+
sb.append(separator);
81+
}
82+
sb.append(token);
6483
}
65-
sb.append(token);
84+
}
85+
return sb.toString();
86+
}
87+
88+
/**
89+
* Convert to quote comment text. Add "> " to the top of each lines.Add line
90+
* break(\n) the last position.
91+
*
92+
* @param comment
93+
* @return quote comment if comment is not {@code null} and not empty,
94+
* otherwise empty string
95+
*/
96+
public static String toQuoteComment(String comment) {
97+
if (isEmpty(comment)) {
98+
return ""; // NOI18N
99+
}
100+
StringBuilder sb = new StringBuilder();
101+
StringTokenizer tokenizer = new StringTokenizer(comment, "\n"); // NOI18N
102+
while (tokenizer.hasMoreTokens()) {
103+
String token = tokenizer.nextToken();
104+
sb.append("> ").append(token).append("\n"); // NOI18N
66105
}
67106
return sb.toString();
68107
}

0 commit comments

Comments
 (0)