Here you can find the source of getComponentName(Collection
Parameter | Description |
---|---|
existingNames | Existing collection of names to test the new name against |
name | The name to test |
public static String getComponentName(Collection<String> existingNames, String name)
//package com.java2s; //License from project: Apache License import java.util.Collection; public class Main { /**/*from w w w . ja v a 2 s. co m*/ * Create a unique name for an unnamed component * * @param existingNames * Existing collection of names to test the new name against * @param name * The name to test */ public static String getComponentName(Collection<String> existingNames, String name) { if (existingNames.contains(name)) { int n = 2; while (existingNames.contains(name + " (" + n + ")")) { n++; } return name + " (" + n + ")"; } else { return name; } } }