blob: fec2044387fc7f9f9d891bd8aaed47e92413f6b6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
package com.c2kernel.utils;
import java.util.HashMap;
import java.util.Iterator;
// This subclass of hashtable can be marshalled
// and unmarshalled with Castor
public class CastorHashMap extends HashMap
{
public CastorHashMap()
{
clear();
}
public KeyValuePair[] getKeyValuePairs()
{
int numKeys = size();
KeyValuePair[] keyValuePairs = new KeyValuePair[numKeys];
Iterator keyIter = keySet().iterator();
int i = 0;
for(i=0; i<numKeys; i++)
if (keyIter.hasNext())
{
String tmp = (String)keyIter.next();
keyValuePairs[i] = new KeyValuePair(tmp,get(tmp));
}
return keyValuePairs;
}
public void setKeyValuePairs(KeyValuePair[] keyValuePairs)
{
int i = 0;
// Clears this hashtable so that it contains no keys
clear();
// Put each key value pair into this hashtable
for(i=0; i<keyValuePairs.length; i++)
{
setKeyValuePair(keyValuePairs[i]);
}
}
public void setKeyValuePair(KeyValuePair keyValuePair)
{
put(keyValuePair.getKey(), keyValuePair.getValue());
}
}
|