1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package org.openoffice.setup.Util;
25 
26 import java.util.HashMap;
27 import java.util.Iterator;
28 import java.util.Map;
29 import java.util.Vector;
30 
31 public class Converter {
32 
Converter()33     private Converter() {
34     }
35 
convertHashmapToStringArray(HashMap map)36     static public String[] convertHashmapToStringArray(HashMap map) {
37 
38         int size = map.size();
39         String[] myStringArray = new String[size];
40 
41         Iterator m = map.entrySet().iterator();
42         int counter = 0;
43 
44         while ( m.hasNext() ) {
45             Map.Entry entry = (Map.Entry) m.next();
46             String env = entry.getKey() + "=" + entry.getValue();
47             myStringArray[counter] = env;
48             counter = counter + 1;
49         }
50 
51         return myStringArray;
52     }
53 
convertVectorToHashmap(Vector vec)54     static public HashMap convertVectorToHashmap(Vector vec) {
55         HashMap map = new HashMap();
56 
57         for (int i = 0; i < vec.size(); i++) {
58             String key = null;
59             String value = null;
60 
61             String line = (String)vec.get(i);
62             int position = line.indexOf("=");
63             if ( position > -1 ) {
64                 key = line.substring(0, position);
65                 value = line.substring(position + 1, line.length());
66             } else {
67                 key = line;
68                 value = null;
69             }
70 
71             map.put(key, value);
72         }
73 
74         return map;
75     }
76 
convertHashMapToVector(HashMap hash)77     static public Vector convertHashMapToVector(HashMap hash) {
78         Vector vec = new Vector();
79 
80         Iterator m = hash.entrySet().iterator();
81 
82         while ( m.hasNext() ) {
83             Map.Entry entry = (Map.Entry) m.next();
84             String line = entry.getKey() + "=" + entry.getValue();
85             vec.add(line);
86         }
87 
88         return vec;
89     }
90 
91 }
92