Commit | Line | Data |
---|---|---|
c2da4d40 JL |
1 | package com.hexidec.util;\r |
2 | \r | |
3 | /*\r | |
4 | GNU General Public License\r | |
5 | \r | |
6 | PatternReplacer - Simple Pattern Replacement Class\r | |
7 | Copyright (C) 2001 Howard A Kistler\r | |
8 | \r | |
9 | This program is free software; you can redistribute it and/or\r | |
10 | modify it under the terms of the GNU General Public License\r | |
11 | as published by the Free Software Foundation; either version 2\r | |
12 | of the License, or (at your option) any later version.\r | |
13 | \r | |
14 | This program is distributed in the hope that it will be useful,\r | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of\r | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r | |
17 | GNU General Public License for more details.\r | |
18 | \r | |
19 | You should have received a copy of the GNU General Public License\r | |
20 | along with this program; if not, write to the Free Software\r | |
21 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r | |
22 | */\r | |
23 | \r | |
24 | import java.util.Hashtable;\r | |
25 | \r | |
26 | /** PatternReplacer\r | |
27 | * Utility class for replacing patterns in script strings\r | |
28 | *\r | |
29 | * @author Howard Kistler\r | |
30 | * @version 0.2\r | |
31 | *\r | |
32 | * VERSION HISTORY\r | |
33 | * 0.1 (04/04/2001) - initial creation (04/04/2001)\r | |
34 | * 0.2 (04/09/2001) - separation into own class (04/09/2001)\r | |
35 | */\r | |
36 | \r | |
37 | public class PatternReplacer {\r | |
38 | \r | |
39 | private Hashtable patternTable;\r | |
40 | \r | |
41 | public PatternReplacer(Hashtable patterns) {\r | |
42 | patternTable = patterns;\r | |
43 | }\r | |
44 | \r | |
45 | public PatternReplacer() {\r | |
46 | patternTable = new Hashtable();\r | |
47 | }\r | |
48 | \r | |
49 | public void addPattern(String pattern, String replacement) {\r | |
50 | if(patternTable.containsKey(pattern)) {\r | |
51 | patternTable.remove(pattern);\r | |
52 | }\r | |
53 | patternTable.put(pattern, replacement);\r | |
54 | }\r | |
55 | \r | |
56 | public void removePattern(String pattern) {\r | |
57 | if(patternTable.containsKey(pattern)) {\r | |
58 | patternTable.remove(pattern);\r | |
59 | }\r | |
60 | }\r | |
61 | \r | |
62 | public String getPattern(String pattern) {\r | |
63 | if(patternTable.containsKey(pattern)) {\r | |
64 | return (String)(patternTable.get(pattern));\r | |
65 | }\r | |
66 | return null;\r | |
67 | }\r | |
68 | \r | |
69 | public void clearPatterns() {\r | |
70 | patternTable.clear();\r | |
71 | }\r | |
72 | \r | |
73 | public int patternCount() {\r | |
74 | return patternTable.size();\r | |
75 | }\r | |
76 | \r | |
77 | }\r | |
78 | \r |