KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > common > HashtableTools


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.syncclient.common;
20
21 import java.util.Enumeration JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Hashtable JavaDoc;
24
25
26 /**
27  * This class supplies a method for the conversion of
28  * one Hashtable in one HashMap.
29  *
30  * @version $Id: HashtableTools.java,v 1.2 2005/01/19 11:18:36 fabius Exp $
31  * @author Stefano Nichele
32  */

33
34 public class HashtableTools {
35
36
37     // -----------------------------------------------------------Public methods
38

39     /**
40      * Convert the given Hashtable in an HashMap.
41      * @param hashtable the Hashtable to convert.
42      * @return a HashMap containing all the elements in the Hashtable
43      */

44     public static HashMap JavaDoc hashtable2hashMap(Hashtable JavaDoc hashtable) {
45         HashMap JavaDoc map = null;
46         if (hashtable == null) {
47             return map;
48         }
49         map = new HashMap JavaDoc();
50         Enumeration JavaDoc enumKeys = hashtable.keys();
51         Object JavaDoc key = null;
52         while (enumKeys.hasMoreElements()) {
53             key = enumKeys.nextElement();
54             map.put(key, hashtable.get(key));
55         }
56         return map;
57     }
58 }
Popular Tags