Debug { public static String abbreviatedName(Class<?> c) { if (c == null) { return null; } StringBuilder result = new StringBuilder(); String fqcn = c.getName(); int lastDot = -1; int thisDot = -1; while ((thisDot = fqcn.indexOf('.', thisDot + 1)) != -1) { result.append(fqcn.charAt(lastDot + 1)); lastDot = thisDot; } if (lastDot != -1) { result.append('.'); } result.append(fqcn.substring(lastDot + 1)); return result.toString(); }  static String toMemorableString(long num); static String objectId(Object o); static String abbreviatedName(Class<?> c); static String shortName(Class<?> c);  }
@Test public void testAbbreviatedName() { assertEquals("ju.List", Debug.abbreviatedName(List.class)); }
@Test public void testAbbreviatedNameInDefaultPackage() throws Exception { assertEquals("NaughtyClassInDefaultPackage", Debug.abbreviatedName(Class.forName("NaughtyClassInDefaultPackage"))); }