@Test public void testTheories() { int MAX_RANDOM_FIXED_LEN = 20; int MAX_RANDOM_AVG_LEN = 20; int MAX_RANDOM_MAX_LEN = 100; for (int i = 0; i < 10000; i++) { int fixedLen = rh.nextInt(MAX_RANDOM_FIXED_LEN); int averageLen = rh.nextInt(MAX_RANDOM_AVG_LEN) + 3; int maxLen = rh.nextInt(MAX_RANDOM_MAX_LEN) + fixedLen; if (maxLen <= 1) { continue; } int targetLen = (maxLen / 2) + rh.nextInt(maxLen / 2) + 1; if (targetLen > maxLen) { targetLen = maxLen; } String filename = rh.buildRandomFileName(averageLen, maxLen); Abbreviator abb = new Abbreviator(fixedLen, targetLen, FS); String result = abb.abbreviate(filename); assertTheory0(averageLen, filename, result, fixedLen, targetLen); assertUsefulness(averageLen, filename, result, fixedLen, targetLen); assertTheory1(filename, result, fixedLen, targetLen); assertTheory2(filename, result, fixedLen, targetLen); } }
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);  }