UniqueNameGenerator { public static String get(String base) { int newValue = 0; Integer value = names.get(base); if (value != null) { newValue = value.intValue() + 1; } names.put(base, Integer.valueOf(newValue)); return base + Integer.toString(newValue); }  static String get(String base);  }
@Test public void testGenerator() { String result = UniqueNameGenerator.get("sample"); Assert.assertEquals(result, "sample0"); for (int k = 0; k < 100; k++) { result = UniqueNameGenerator.get("sample"); } Assert.assertEquals(result, "sample100"); for (int k = 0; k < 100; k++) { result = UniqueNameGenerator.get("other"); } Assert.assertEquals(result, "other99"); Assert.assertEquals(UniqueNameGenerator.get(""), "0"); }