@Test public void testSmoke() { { Abbreviator abb = new Abbreviator(2, 100, FS); String r = abb.abbreviate(INPUT_0); assertEquals(INPUT_0, r); } { Abbreviator abb = new Abbreviator(3, 8, FS); String r = abb.abbreviate(INPUT_0); assertEquals("/abc/.../ABC", r); } { Abbreviator abb = new Abbreviator(3, 8, FS); String r = abb.abbreviate(INPUT_0); assertEquals("/abc/.../ABC", r); } }
public String abbreviate(String filename) { if (filename.length() <= desiredLength) { return filename; } else { int firstIndex = filename.indexOf(folderSeparator, invariantPrefixLength); if (firstIndex == -1) { return filename; } StringBuilder buf = new StringBuilder(desiredLength); buf.append(filename, 0, firstIndex + 1); buf.append(FILLER); int nextIndex = computeNextIndex(filename, firstIndex); if (nextIndex != -1) { buf.append(filename.substring(nextIndex)); } else { return filename; } if (buf.length() < filename.length()) { return buf.toString(); } else { return filename; } } }
Abbreviator { public String abbreviate(String filename) { if (filename.length() <= desiredLength) { return filename; } else { int firstIndex = filename.indexOf(folderSeparator, invariantPrefixLength); if (firstIndex == -1) { return filename; } StringBuilder buf = new StringBuilder(desiredLength); buf.append(filename, 0, firstIndex + 1); buf.append(FILLER); int nextIndex = computeNextIndex(filename, firstIndex); if (nextIndex != -1) { buf.append(filename.substring(nextIndex)); } else { return filename; } if (buf.length() < filename.length()) { return buf.toString(); } else { return filename; } } } }
Abbreviator { public String abbreviate(String filename) { if (filename.length() <= desiredLength) { return filename; } else { int firstIndex = filename.indexOf(folderSeparator, invariantPrefixLength); if (firstIndex == -1) { return filename; } StringBuilder buf = new StringBuilder(desiredLength); buf.append(filename, 0, firstIndex + 1); buf.append(FILLER); int nextIndex = computeNextIndex(filename, firstIndex); if (nextIndex != -1) { buf.append(filename.substring(nextIndex)); } else { return filename; } if (buf.length() < filename.length()) { return buf.toString(); } else { return filename; } } } Abbreviator(int invariantPrefixLength, int desiredLength, char folderSeparator); }
Abbreviator { public String abbreviate(String filename) { if (filename.length() <= desiredLength) { return filename; } else { int firstIndex = filename.indexOf(folderSeparator, invariantPrefixLength); if (firstIndex == -1) { return filename; } StringBuilder buf = new StringBuilder(desiredLength); buf.append(filename, 0, firstIndex + 1); buf.append(FILLER); int nextIndex = computeNextIndex(filename, firstIndex); if (nextIndex != -1) { buf.append(filename.substring(nextIndex)); } else { return filename; } if (buf.length() < filename.length()) { return buf.toString(); } else { return filename; } } } Abbreviator(int invariantPrefixLength, int desiredLength, char folderSeparator); String abbreviate(String filename); }
Abbreviator { public String abbreviate(String filename) { if (filename.length() <= desiredLength) { return filename; } else { int firstIndex = filename.indexOf(folderSeparator, invariantPrefixLength); if (firstIndex == -1) { return filename; } StringBuilder buf = new StringBuilder(desiredLength); buf.append(filename, 0, firstIndex + 1); buf.append(FILLER); int nextIndex = computeNextIndex(filename, firstIndex); if (nextIndex != -1) { buf.append(filename.substring(nextIndex)); } else { return filename; } if (buf.length() < filename.length()) { return buf.toString(); } else { return filename; } } } Abbreviator(int invariantPrefixLength, int desiredLength, char folderSeparator); String abbreviate(String filename);  }