@Test public void testBreakText() { Date d = new Date(); SRT oldSRT = new SRT(1, d, d, "0123456789 0123456789 0123456789 0123456789"); SRT newSRT = SRTEditor.breakText(oldSRT, 21); assertEquals(oldSRT.number, newSRT.number); assertEquals(SRTTimeFormat.format(oldSRT.startTime), SRTTimeFormat.format(newSRT.startTime)); assertEquals(SRTTimeFormat.format(oldSRT.startTime), SRTTimeFormat.format(newSRT.startTime)); assertEquals(2, newSRT.text.size()); assertEquals("0123456789 0123456789", newSRT.text.get(0)); assertEquals("0123456789 0123456789", newSRT.text.get(1)); oldSRT = new SRT(1, d, d, "0123456789 0123456789 0123456789 0123456789 0123456789"); newSRT = SRTEditor.breakText(oldSRT, 21); assertEquals(oldSRT.number, newSRT.number); assertEquals(SRTTimeFormat.format(oldSRT.startTime), SRTTimeFormat.format(newSRT.startTime)); assertEquals(SRTTimeFormat.format(oldSRT.startTime), SRTTimeFormat.format(newSRT.startTime)); assertEquals(3, newSRT.text.size()); assertEquals("0123456789 0123456789", newSRT.text.get(0)); assertEquals("0123456789 0123456789", newSRT.text.get(1)); assertEquals("0123456789", newSRT.text.get(2)); oldSRT = new SRT(1, d, d, "0123456789"); newSRT = SRTEditor.breakText(oldSRT, 5); assertEquals(oldSRT.number, newSRT.number); assertEquals(SRTTimeFormat.format(oldSRT.startTime), SRTTimeFormat.format(newSRT.startTime)); assertEquals(SRTTimeFormat.format(oldSRT.startTime), SRTTimeFormat.format(newSRT.startTime)); assertEquals(1, newSRT.text.size()); assertEquals("0123456789", newSRT.text.get(0)); }
static SRT breakText(SRT srt, int width) { List<String> newTexts = new ArrayList<>(); String subtitle = StringUtils.join(srt.text, " "); if (subtitle.length() <= width) { newTexts.addAll(srt.text); } else { int begin = 0; int end = width; while (end < subtitle.length()) { while (subtitle.charAt(end) != ' ' && end != 0) { end--; } if (end == 0) { break; } newTexts.add(subtitle.substring(begin, end)); begin = end + 1; end = begin + width; } newTexts.add(subtitle.substring(begin, subtitle.length())); } return new SRT(srt.number, srt.startTime, srt.endTime, newTexts); }
SRTEditor { static SRT breakText(SRT srt, int width) { List<String> newTexts = new ArrayList<>(); String subtitle = StringUtils.join(srt.text, " "); if (subtitle.length() <= width) { newTexts.addAll(srt.text); } else { int begin = 0; int end = width; while (end < subtitle.length()) { while (subtitle.charAt(end) != ' ' && end != 0) { end--; } if (end == 0) { break; } newTexts.add(subtitle.substring(begin, end)); begin = end + 1; end = begin + width; } newTexts.add(subtitle.substring(begin, subtitle.length())); } return new SRT(srt.number, srt.startTime, srt.endTime, newTexts); } }
SRTEditor { static SRT breakText(SRT srt, int width) { List<String> newTexts = new ArrayList<>(); String subtitle = StringUtils.join(srt.text, " "); if (subtitle.length() <= width) { newTexts.addAll(srt.text); } else { int begin = 0; int end = width; while (end < subtitle.length()) { while (subtitle.charAt(end) != ' ' && end != 0) { end--; } if (end == 0) { break; } newTexts.add(subtitle.substring(begin, end)); begin = end + 1; end = begin + width; } newTexts.add(subtitle.substring(begin, subtitle.length())); } return new SRT(srt.number, srt.startTime, srt.endTime, newTexts); } private  SRTEditor(); }
SRTEditor { static SRT breakText(SRT srt, int width) { List<String> newTexts = new ArrayList<>(); String subtitle = StringUtils.join(srt.text, " "); if (subtitle.length() <= width) { newTexts.addAll(srt.text); } else { int begin = 0; int end = width; while (end < subtitle.length()) { while (subtitle.charAt(end) != ' ' && end != 0) { end--; } if (end == 0) { break; } newTexts.add(subtitle.substring(begin, end)); begin = end + 1; end = begin + width; } newTexts.add(subtitle.substring(begin, subtitle.length())); } return new SRT(srt.number, srt.startTime, srt.endTime, newTexts); } private  SRTEditor(); static void updateTime(SRTInfo info, int subtitleNumber,
        SRTTimeFormat.Type type, int value); static void updateTimes(SRTInfo info, SRTTimeFormat.Type type, int value); static void updateText(SRTInfo info, int subtitleNumber, int width); static void updateTexts(SRTInfo info, int width); static void appendSubtitle(SRTInfo info, String startTime,
        String endTime, List<String> text); static void prependSubtitle(SRTInfo info, String startTime,
        String endTime, List<String> text); static void insertSubtitle(SRTInfo info, int subtitleNumber,
        String startTime, String endTime, List<String> text); static void insertSubtitle(SRTInfo info, SRT newSRT); static void removeSubtitle(SRTInfo info, int subtitleNumber); static void updateSubtitle(SRTInfo info, SRT srt); }
SRTEditor { static SRT breakText(SRT srt, int width) { List<String> newTexts = new ArrayList<>(); String subtitle = StringUtils.join(srt.text, " "); if (subtitle.length() <= width) { newTexts.addAll(srt.text); } else { int begin = 0; int end = width; while (end < subtitle.length()) { while (subtitle.charAt(end) != ' ' && end != 0) { end--; } if (end == 0) { break; } newTexts.add(subtitle.substring(begin, end)); begin = end + 1; end = begin + width; } newTexts.add(subtitle.substring(begin, subtitle.length())); } return new SRT(srt.number, srt.startTime, srt.endTime, newTexts); } private  SRTEditor(); static void updateTime(SRTInfo info, int subtitleNumber,
        SRTTimeFormat.Type type, int value); static void updateTimes(SRTInfo info, SRTTimeFormat.Type type, int value); static void updateText(SRTInfo info, int subtitleNumber, int width); static void updateTexts(SRTInfo info, int width); static void appendSubtitle(SRTInfo info, String startTime,
        String endTime, List<String> text); static void prependSubtitle(SRTInfo info, String startTime,
        String endTime, List<String> text); static void insertSubtitle(SRTInfo info, int subtitleNumber,
        String startTime, String endTime, List<String> text); static void insertSubtitle(SRTInfo info, SRT newSRT); static void removeSubtitle(SRTInfo info, int subtitleNumber); static void updateSubtitle(SRTInfo info, SRT srt);  }