1 /*
2 * This is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation; either version 2.1 of
5 * the License, or (at your option) any later version.
6 *
7 * This software is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this software; if not, write to the Free
14 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
15 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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 }