| Code with Finding: |
class Utility {
/**
* Shorten long class name <em>str</em>, i.e., chop off the <em>prefix</em>,
* if the
* class name starts with this string and the flag <em>chopit</em> is true.
* Slashes <em>/</em> are converted to dots <em>.</em>.
*
* @param str The long class name
* @param prefix The prefix the get rid off
* @param chopit Flag that determines whether chopping is executed or not
* @return Compacted class name
*/
public static String compactClassName( String str, String prefix, boolean chopit ) {
int len = prefix.length();
str = str.replace('/', '.'); // Is `/' on all systems, even DOS
if (chopit) {
// If string starts with `prefix' and contains no further dots
if (str.startsWith(prefix) && (str.substring(len).indexOf('.') == -1)) {
str = str.substring(len);
}
}
return str;
}
}
|