@Test public void removeLastNewLineBreak() { assertEquals("l\n" + "a\n" + "l\n" + "a\n" + "\n", StringUtils.wrapSeparator("lala\n", "", "\n", 0)); }
@NotNull public static String wrapSeparator(String line, String separator, String newLine, int watermark) { StringBuilder sb = new StringBuilder(); String[] parts = line.split(separator); StringBuilder part = new StringBuilder(); for (int i = 0; i < parts.length; i++) { String word = parts[i]; part.append(word); if (i < parts.length - 1) { part.append(separator); } if (part.length() >= watermark) { String add = part.toString(); if (add.endsWith(separator)) { add = add.substring(0, add.length() - separator.length()); } sb.append(add); sb.append(newLine); sb.append(separator); part.setLength(0); } } if (part.length() > 0) { sb.append(part.toString()); } String answer = sb.toString(); if (answer.endsWith(newLine)) { answer = answer.substring(0, answer.length() - newLine.length()); } return answer; }
StringUtils { @NotNull public static String wrapSeparator(String line, String separator, String newLine, int watermark) { StringBuilder sb = new StringBuilder(); String[] parts = line.split(separator); StringBuilder part = new StringBuilder(); for (int i = 0; i < parts.length; i++) { String word = parts[i]; part.append(word); if (i < parts.length - 1) { part.append(separator); } if (part.length() >= watermark) { String add = part.toString(); if (add.endsWith(separator)) { add = add.substring(0, add.length() - separator.length()); } sb.append(add); sb.append(newLine); sb.append(separator); part.setLength(0); } } if (part.length() > 0) { sb.append(part.toString()); } String answer = sb.toString(); if (answer.endsWith(newLine)) { answer = answer.substring(0, answer.length() - newLine.length()); } return answer; } }
StringUtils { @NotNull public static String wrapSeparator(String line, String separator, String newLine, int watermark) { StringBuilder sb = new StringBuilder(); String[] parts = line.split(separator); StringBuilder part = new StringBuilder(); for (int i = 0; i < parts.length; i++) { String word = parts[i]; part.append(word); if (i < parts.length - 1) { part.append(separator); } if (part.length() >= watermark) { String add = part.toString(); if (add.endsWith(separator)) { add = add.substring(0, add.length() - separator.length()); } sb.append(add); sb.append(newLine); sb.append(separator); part.setLength(0); } } if (part.length() > 0) { sb.append(part.toString()); } String answer = sb.toString(); if (answer.endsWith(newLine)) { answer = answer.substring(0, answer.length() - newLine.length()); } return answer; } private  StringUtils(); }
StringUtils { @NotNull public static String wrapSeparator(String line, String separator, String newLine, int watermark) { StringBuilder sb = new StringBuilder(); String[] parts = line.split(separator); StringBuilder part = new StringBuilder(); for (int i = 0; i < parts.length; i++) { String word = parts[i]; part.append(word); if (i < parts.length - 1) { part.append(separator); } if (part.length() >= watermark) { String add = part.toString(); if (add.endsWith(separator)) { add = add.substring(0, add.length() - separator.length()); } sb.append(add); sb.append(newLine); sb.append(separator); part.setLength(0); } } if (part.length() > 0) { sb.append(part.toString()); } String answer = sb.toString(); if (answer.endsWith(newLine)) { answer = answer.substring(0, answer.length() - newLine.length()); } return answer; } private  StringUtils(); @Nullable static String asComponentName(String val); @Nullable static String asLanguageName(String val); @NotNull static String getSafeValue(String key, List<Map<String, String>> rows); @NotNull static String getSafeValue(String key, Map<String, String> rows); @NotNull static String wrapSeparator(String line, String separator, String newLine, int watermark); @Nullable static String wrapWords(String line, String newLine, int watermark, boolean wrapLongWords); static boolean isEmpty(String str); static boolean isNotEmpty(String str); static String stripDoubleQuotes(String text); }
StringUtils { @NotNull public static String wrapSeparator(String line, String separator, String newLine, int watermark) { StringBuilder sb = new StringBuilder(); String[] parts = line.split(separator); StringBuilder part = new StringBuilder(); for (int i = 0; i < parts.length; i++) { String word = parts[i]; part.append(word); if (i < parts.length - 1) { part.append(separator); } if (part.length() >= watermark) { String add = part.toString(); if (add.endsWith(separator)) { add = add.substring(0, add.length() - separator.length()); } sb.append(add); sb.append(newLine); sb.append(separator); part.setLength(0); } } if (part.length() > 0) { sb.append(part.toString()); } String answer = sb.toString(); if (answer.endsWith(newLine)) { answer = answer.substring(0, answer.length() - newLine.length()); } return answer; } private  StringUtils(); @Nullable static String asComponentName(String val); @Nullable static String asLanguageName(String val); @NotNull static String getSafeValue(String key, List<Map<String, String>> rows); @NotNull static String getSafeValue(String key, Map<String, String> rows); @NotNull static String wrapSeparator(String line, String separator, String newLine, int watermark); @Nullable static String wrapWords(String line, String newLine, int watermark, boolean wrapLongWords); static boolean isEmpty(String str); static boolean isNotEmpty(String str); static String stripDoubleQuotes(String text);  }