1 17 18 package org.objectweb.jac.aspects.naming; 19 20 import java.util.Hashtable ; 21 import java.util.Iterator ; 22 import java.util.Map ; 23 24 28 public class NameGenerator extends Hashtable { 29 30 33 public NameGenerator() { 34 } 35 36 public synchronized String generateName(String className) { 37 Long n = (Long )get(className); 38 if (n==null) { 39 n = new Long (0); 40 } 41 String res = 44 className.substring(className.lastIndexOf('.')+1).toLowerCase() 45 + "#"+ n; 46 put(className,new Long (n.longValue()+1)); 47 return res; 48 } 49 50 53 public static long getCounterFromName(String name) { 54 return Long.parseLong(name.substring(name.indexOf('#')+1)); 55 } 56 57 60 public long getCounter(String className) { 61 Long counter = (Long )get(className); 62 return counter!=null?counter.longValue():-1; 63 } 64 65 68 public void setCounter(String className, long count) { 69 put(className,new Long (count)); 70 } 71 72 75 public synchronized void update(Map counters) { 76 Iterator i = counters.entrySet().iterator(); 77 while(i.hasNext()) { 78 Map.Entry entry = (Map.Entry )i.next(); 79 String name = (String )entry.getKey(); 80 Long value = (Long )entry.getValue(); 81 long current = getCounter(name); 82 if (current<value.longValue()) 83 put(name,value); 84 } 85 } 86 } 87 88 | Popular Tags |