StructuralVariantDAO { static String limitSizeOfCSV(int maxSize, String linkedBy) { if (linkedBy.length() <= maxSize) { return linkedBy; } if (!linkedBy.contains(",")) { return linkedBy.substring(0, maxSize); } StringJoiner joiner = new StringJoiner(","); String[] csv = linkedBy.split(","); for (String s : csv) { int sizeWithNewString = joiner.length() == 0 ? s.length() : joiner.length() + 1 + s.length(); if (sizeWithNewString > maxSize) { return joiner.toString(); } joiner.add(s); } return joiner.toString(); } StructuralVariantDAO(@NotNull final DSLContext context); @NotNull List<StructuralVariantData> read(@NotNull String sample);  }
@Test public void testLimitSizeOfCSV() { String one = "asm12/23"; String two = one + ",asm13/24"; String three = two + ",asm12233/1"; assertEquals(three, StructuralVariantDAO.limitSizeOfCSV(three.length(), three)); for (int i = three.length() - 1; i >= two.length(); i--) { assertEquals(two, StructuralVariantDAO.limitSizeOfCSV(i, three)); } for (int i = two.length() - 1; i >= one.length(); i--) { assertEquals(one, StructuralVariantDAO.limitSizeOfCSV(i, three)); } }