Few more
[apertium.git] / trunk / crossdics / src / dictools / crossmodel / ConstantMap.java
blob9c39aa21e40356b10c182fb5ca73f622be6ec0d4
1 /*
2 * Copyright (C) 2007 Universitat d'Alacant / Universidad de Alicante
3 * Author: Enrique Benimeli Bofarull
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 * 02111-1307, USA.
21 package dictools.crossmodel;
23 import java.io.DataOutputStream;
24 import java.io.IOException;
25 import java.util.HashMap;
26 import java.util.Iterator;
27 import java.util.Set;
29 /**
31 * @author Enrique Benimeli Bofarull
34 public class ConstantMap extends HashMap<String, String> {
36 /**
39 static final long serialVersionUID = 0;
41 /**
43 * @param key
44 * @param value
46 public final String insert(final String key, final String value) {
47 if (!containsKey(key)) {
48 put(key, value);
49 return value;
50 } else {
51 return get(key);
55 /**
59 public final void print() {
60 final Set keySet = keySet();
61 final Iterator it = keySet.iterator();
63 System.out.print("constants: ");
64 while (it.hasNext()) {
65 final String key = (String) it.next();
66 final String value = get(key);
67 System.out.print("<" + key + "," + value + "> ");
69 System.out.println("");
72 /**
74 * @param dos
76 public final void printXML(DataOutputStream dos) throws IOException {
77 final Set keySet = keySet();
78 final Iterator it = keySet.iterator();
80 dos.writeBytes("\t<constants>\n");
81 while (it.hasNext()) {
82 final String key = (String) it.next();
83 final String value = get(key);
84 dos.writeBytes("\t\t<constant n=\"" + value + "\">" + key
85 + "</constant>\n");
87 dos.writeBytes("\t<constants>\n");
90 /**
92 * @param value
93 * @return
95 public final String getKey(final String value) {
96 final Set keySet = keySet();
97 final Iterator it = keySet.iterator();
99 while (it.hasNext()) {
100 final String key = (String) it.next();
101 final String v = get(key);
102 if (v.equals(value)) {
103 return key;
106 return null;