String (@Nullable String text) { if (StringUtil.isEmpty(text)) return ""; // Split by new line, removing empty lines and white-spaces at end of lines. String[] lines = StringUtil.splitByLines(text); // Join lines, ensuring each line end with a punctuation. final StringBuilder result = new StringBuilder(); boolean first = true; for (String line : lines) { line = line.trim(); if (!StringUtil.isEmpty(line)) { if (first) first = false; else result.append(PUNCTUATION_SEPARATOR); result.append(line); if (!line.endsWith(PUNCTUATION_CHARACTER)) { result.append(PUNCTUATION_CHARACTER); } } } return result.toString(); }