19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package java.beans;
26
27 import java.util.HashMap;
28 import java.util.IdentityHashMap;
29 import java.util.Map;
30
31 import static java.util.Locale.ENGLISH;
32
33 /**
34 * A utility class which generates unique names for object instances.
35 * The name will be a concatenation of the unqualified class name
36 * and an instance number.
37 * <p>
38 * For example, if the first object instance javax.swing.JButton
39 * is passed into <code>instanceName</code> then the returned
40 * string identifier will be "JButton0".
41 *
42 * @author Philip Milne
43 */
44 class NameGenerator {
45
46 private Map<Object, String> valueToName;
47 private Map<String, Integer> nameToCount;
48
49 public NameGenerator() {
50 valueToName = new IdentityHashMap<>();
51 nameToCount = new HashMap<>();
52 }
53
54 /**
55 * Clears the name cache. Should be called to near the end of
56 * the encoding cycle.
57 */
58 public void clear() {
59 valueToName.clear();
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package java.beans;
26
27 import java.util.HashMap;
28 import java.util.IdentityHashMap;
29 import java.util.Map;
30
31 import static java.util.Locale.ENGLISH;
32
33 /**
34 * A utility class which generates unique names for object instances.
35 * The name will be a concatenation of the unqualified class name
36 * and an instance number.
37 * <p>
38 * For example, if the first object instance javax.swing.JButton
39 * is passed into {@code instanceName} then the returned
40 * string identifier will be "JButton0".
41 *
42 * @author Philip Milne
43 */
44 class NameGenerator {
45
46 private Map<Object, String> valueToName;
47 private Map<String, Integer> nameToCount;
48
49 public NameGenerator() {
50 valueToName = new IdentityHashMap<>();
51 nameToCount = new HashMap<>();
52 }
53
54 /**
55 * Clears the name cache. Should be called to near the end of
56 * the encoding cycle.
57 */
58 public void clear() {
59 valueToName.clear();
|