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