xref: /AOO41X/main/javainstaller2/src/JavaSetup/org/openoffice/setup/Util/Converter.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package org.openoffice.setup.Util;
29 
30 import java.util.HashMap;
31 import java.util.Iterator;
32 import java.util.Map;
33 import java.util.Vector;
34 
35 public class Converter {
36 
37     private Converter() {
38     }
39 
40     static public String[] convertHashmapToStringArray(HashMap map) {
41 
42         int size = map.size();
43         String[] myStringArray = new String[size];
44 
45         Iterator m = map.entrySet().iterator();
46         int counter = 0;
47 
48         while ( m.hasNext() ) {
49             Map.Entry entry = (Map.Entry) m.next();
50             String env = entry.getKey() + "=" + entry.getValue();
51             myStringArray[counter] = env;
52             counter = counter + 1;
53         }
54 
55         return myStringArray;
56     }
57 
58     static public HashMap convertVectorToHashmap(Vector vec) {
59         HashMap map = new HashMap();
60 
61         for (int i = 0; i < vec.size(); i++) {
62             String key = null;
63             String value = null;
64 
65             String line = (String)vec.get(i);
66             int position = line.indexOf("=");
67             if ( position > -1 ) {
68                 key = line.substring(0, position);
69                 value = line.substring(position + 1, line.length());
70             } else {
71                 key = line;
72                 value = null;
73             }
74 
75             map.put(key, value);
76         }
77 
78         return map;
79     }
80 
81     static public Vector convertHashMapToVector(HashMap hash) {
82         Vector vec = new Vector();
83 
84         Iterator m = hash.entrySet().iterator();
85 
86         while ( m.hasNext() ) {
87             Map.Entry entry = (Map.Entry) m.next();
88             String line = entry.getKey() + "=" + entry.getValue();
89             vec.add(line);
90         }
91 
92         return vec;
93     }
94 
95 }
96