KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > xml > MetaCharacterMap


1 /*
2  * XML input/output support for FindBugs
3  * Copyright (C) 2004, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package edu.umd.cs.findbugs.xml;
21
22 import java.util.BitSet JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
25
26 /**
27  * Map of metacharacters that need to be escaped,
28  * and what to replace them with.
29  *
30  * @see QuoteMetaCharacters
31  * @author David Hovemeyer
32  */

33 public class MetaCharacterMap {
34     private BitSet JavaDoc metaCharacterSet;
35     private Map JavaDoc<String JavaDoc, String JavaDoc> replacementMap;
36
37     /**
38      * Constructor.
39      * Creates an empty object.
40      */

41     public MetaCharacterMap() {
42         this.metaCharacterSet = new BitSet JavaDoc();
43         this.replacementMap = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
44     }
45
46     /**
47      * Add a metacharacter and its replacement.
48      *
49      * @param meta the metacharacter
50      * @param replacement the String to replace the metacharacter with
51      */

52     public void addMeta(char meta, String JavaDoc replacement) {
53         metaCharacterSet.set(meta);
54         replacementMap.put(new String JavaDoc(new char[]{meta}), replacement);
55     }
56
57     /**
58      * Return whether or not given character is a metacharacter.
59      */

60     boolean isMeta(char c) {
61         return metaCharacterSet.get(c);
62     }
63
64     /**
65      * Get the replacement for a metacharacter.
66      *
67      * @param c a String containing the metacharacter
68      */

69     String JavaDoc getReplacement(String JavaDoc c) {
70         return replacementMap.get(c);
71     }
72 }
73
74 // vim:ts=4
75
Popular Tags