List of utility methods to do String Abbreviate
String | abbreviate(String str, int offset, int maxWidth) abbreviate if (str == null) { return null; if (maxWidth < 4) { throw new IllegalArgumentException("Minimum abbreviation width is 4"); if (str.length() <= maxWidth) { return str; ... |
String | abbreviate(String str, int preferredLength) Abbreviates a string for display if necessary. return abbreviate(str, preferredLength, 0, true);
|
String | abbreviate(String string, int maxLength) Shortens a String if it is longer than the given maxLength, ending an abbreviated String with "...". return string.length() <= maxLength ? string : string.substring(0, maxLength - 3) + "..."; |
String | abbreviate(String text, int maxFront, int maxBack) abbreviate if (text.length() > maxFront + maxBack - 3) { text = text.substring(0, maxFront) + "..." + text.substring(text.length() - maxBack, text.length()); return text; |
String | abbreviate(String text, Number maxNbrChars) abbreviate return abbreviate(text, maxNbrChars, "..."); |
String | abbreviate(String time) abbreviate time = time.replaceAll(" days", "d"); time = time.replaceAll(" day", "d"); time = time.replaceAll(" hours", "hr"); time = time.replaceAll(" hour", "hr"); time = time.replaceAll(" minutes", "m"); time = time.replaceAll(" minute", "m"); time = time.replaceAll(" seconds", "s"); time = time.replaceAll(" second", "s"); ... |
String | abbreviated(final String str, final int maxLength) abbreviated return str != null ? (str.length() < maxLength ? str : str.substring(0, maxLength - 3) + "...") : null; |
String | abbreviateDotSeparatedString(String string, int targetLength) Abbreviates the given dot-separated string to reduce its length (if necessary) to within the supplied target length. if (string.length() <= targetLength) { return string; String[] components = string.split(DOT_SEPARATOR_SPLIT_REGEX); int actualLength = string.length(); StringBuilder builder = new StringBuilder(); int index = 0; while (actualLength > targetLength && index < components.length - 1) { ... |
String | abbreviateFileName(final String fileName) Create a truncated file name suitable for display in interfaces if (fileName == null) { throw new IllegalArgumentException("null fileName"); StringBuilder sb = new StringBuilder(); if (fileName.length() < 100) { sb.append(fileName); } else { sb.append(fileName.substring(0, 50)); ... |
String | abbreviateInCenter(String stringToAbbreviate, int length) abbreviate In Center int halfLength = length / 2; int firstPartLastIndex = halfLength - ELLIPSIS.length(); int stringLength = stringToAbbreviate.length(); return String.format("%s%s%s", stringToAbbreviate.substring(0, firstPartLastIndex), ELLIPSIS, stringToAbbreviate.substring(stringLength - halfLength, stringLength)); |