1 /*--------------------------------------------------------------------------
2 * Copyright 2007 utgenome.org
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *--------------------------------------------------------------------------*/
16 //--------------------------------------
17 // utgb-core Project
18 //
19 // ParameterMap.java
20 // Since: Dec 10, 2007
21 //
22 // $URL$
23 // $Author$
24 //--------------------------------------
25 package org.utgenome.format.egt;
26
27 import java.util.ArrayList;
28
29 import org.xerial.util.Pair;
30 import org.xerial.xml.XMLGenerator;
31
32 /**
33 * @author leo
34 *
35 */
36 public class ParameterMap implements Parameter {
37 ArrayList<Pair<String, Parameter>> map = new ArrayList<Pair<String, Parameter>>();
38
39 /**
40 * @param map
41 */
42 public ParameterMap() {
43
44 }
45
46 public void put(String key, Parameter value) {
47 map.add(new Pair<String, Parameter>(key, value));
48 }
49
50 /**
51 * @param key
52 * @return value if found. If not found, it returns null
53 */
54 public Parameter get(String key) {
55 for (Pair<String, Parameter> p : map) {
56 if (p.equals(key))
57 return p.getSecond();
58 }
59 return null;
60 }
61
62 public void toXML(String elementName, XMLGenerator xout) {
63 xout.startTag(elementName);
64 for (Pair<String, Parameter> e : map) {
65 Parameter p = e.getSecond();
66 p.toXML(e.getFirst(), xout);
67 }
68 xout.endTag();
69 }
70
71 public void toXML(XMLGenerator xout) {
72 for (Pair<String, Parameter> e : map) {
73 Parameter p = e.getSecond();
74 p.toXML(e.getFirst(), xout);
75 }
76 }
77
78 }