1 16 package com.google.gwt.dev.generator; 17 18 import java.util.Set ; 19 import java.util.HashSet ; 20 import java.util.Collection ; 21 22 27 public class NameFactory { 28 29 private final Set usedNames = new HashSet (); 30 31 37 public NameFactory(Collection existingNames) { 38 if (existingNames == null) { 39 return; 40 } 41 usedNames.addAll(existingNames); 42 } 43 44 48 public NameFactory() { 49 this(null); 50 } 51 52 58 public void addName(String name) { 59 usedNames.add(name); 60 } 61 62 70 public String createName(String name) { 71 String newName = name; 72 73 for (int count = 0; true; ++count) { 74 if (usedNames.contains(newName)) { 75 newName = name + count; 76 } else { 77 return newName; 78 } 79 } 80 } 81 } 82 | Popular Tags |