List of utility methods to do String Shorten
String | shortenContent(String s, int maxLength) shorten Content if (s.length() > maxLength) { return s.substring(0, maxLength - 3) + "..."; } else { return s; |
String | shortenCount(final long count) Changes a large number into a binary postfixed version. int unit = 1000; if (count < unit) { return Long.toString(count); int exponential = (int) (Math.log(count) / Math.log(unit)); char postfix = "KMBT".charAt(exponential - 1); return String.format("%.1f%c", (count / Math.pow(unit, exponential)), postfix); |
String | shortenCount(int count) shorten Count int shortCount = count; String postFix = ""; if (count >= 1000000) { shortCount /= 1000000; postFix = "M"; } else if (count >= 1000) { shortCount /= 1000; postFix = "k"; ... |
String | shortenDbName(String dbName, int desiredLength) Start by removing all vowels, then pull 1 letter at a time off the end of each _ separated segment, go until it is less than or equal to the desired length StringBuilder dbBuf = new StringBuilder(dbName); if (dbBuf.length() > desiredLength) { for (int i = dbBuf.length() - 1; i > 0; i--) { if (dbBuf.charAt(i - 1) == '_') { continue; char curChar = dbBuf.charAt(i); if (vowelBag.indexOf(curChar) > 0) { ... |
String | shortenDerivedIdentifier(final String derivdedIdentifier) shorten Derived Identifier return shortenDerivedIdentifier(derivdedIdentifier, "_"); |
String | shortenFileName(String name) shorten File Name if (name == null) return name; String retVal; String tempStr = name.replace('\\', '/'); if (tempStr.indexOf('/') >= 0) { retVal = tempStr.substring(tempStr.lastIndexOf('/') + 1); } else { retVal = name; ... |
String | shortenFileName(String text, String filename) shorten File Name String fixed = filename.replace('\\', '/'); String shortname = filename; if (fixed.lastIndexOf('/') >= 0) shortname = filename.substring(fixed.lastIndexOf('/') + 1, filename.length()); text = text.replaceAll(filename, shortname); return text; |
String | shortenGeneratedIdentifier(final String name) shorten Generated Identifier return shortenGeneratedIdentifier(name, "_"); |
String | shortenHash(String s) shorten Hash return s.substring(0, 8);
|
String | shortenLabel(String key) Replace pre-determined keywords in a string, with shorter ones. for (int i = 0; i < KEYWORDS.length; i++) { if (key.indexOf(KEYWORDS[i]) >= 0) key = key.replace(KEYWORDS[i], REPLACEMENTS[i]); return key; |