1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package installtoolkit.wix;
19
20 import java.text.DecimalFormat;
21
22 /**
23 * Helper class to generate ids from a prefix and a number.
24 *
25 * @author Christian Elberfeld <elberfeld@web.de>
26 *
27 */
28 public class IdGenarator {
29
30 protected long maximum;
31 DecimalFormat format;
32 protected long counter;
33
34 /**
35 *
36 * @param digits Number of digits for the numeric part
37 * @param prefix Prefix
38 */
39 public IdGenarator(int digits, String prefix) {
40
41 this.counter = 0;
42 this.maximum = (long) Math.pow(10,digits);
43
44 String fstr = "";
45 if (prefix != null) fstr += prefix;
46 for (int i=0; i<digits; i++) fstr += "0";
47
48 this.format = new DecimalFormat(fstr);
49 }
50
51 /**
52 * get the next ID as String
53 * @return
54 */
55 public String next() {
56
57 counter++;
58 if (counter >= maximum) counter = 1;
59 return format.format(counter);
60 }
61
62
63 }