KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > svggen > SVGIDGenerator


1 /*
2
3    Copyright 2001-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.svggen;
19
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22
23 /**
24  * Generates id for an arbitrary number of prefix
25  *
26  * @author <a HREF="mailto:cjolif@ilog.fr">Christophe Jolif</a>
27  * @author <a HREF="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
28  * @version $Id: SVGIDGenerator.java,v 1.7 2004/08/18 07:15:08 vhardy Exp $
29  */

30 public class SVGIDGenerator {
31     private Map JavaDoc prefixMap = new HashMap JavaDoc();
32
33     public SVGIDGenerator() {
34     }
35
36     /**
37      * Generates an id for the given prefix. This class keeps
38      * track of all invocations to that it generates unique ids
39      *
40      * @param prefix defines the prefix for which the id should
41      * be generated.
42      * @return a value of the form <prefix><n>
43      */

44     public String JavaDoc generateID(String JavaDoc prefix) {
45         Integer JavaDoc maxId = (Integer JavaDoc)prefixMap.get(prefix);
46         if (maxId == null) {
47             maxId = new Integer JavaDoc(0);
48             prefixMap.put(prefix, maxId);
49         }
50
51         maxId = new Integer JavaDoc(maxId.intValue()+1);
52         prefixMap.put(prefix, maxId);
53         return prefix + maxId;
54     }
55 }
56
Popular Tags