| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
package org.webmacro.util; |
| 25 | |
|
| 26 | |
import java.util.Dictionary; |
| 27 | |
import java.util.Enumeration; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
final public class DictionaryTool extends Dictionary |
| 33 | |
{ |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
public final String keyString () |
| 41 | |
{ |
| 42 | 0 | final Enumeration keys = dict.keys(); |
| 43 | 0 | String key = null; |
| 44 | 0 | StringBuffer buf = new StringBuffer(10 * dict.size()); |
| 45 | 0 | while (keys.hasMoreElements()) |
| 46 | |
{ |
| 47 | 0 | if (key != null) |
| 48 | |
{ |
| 49 | 0 | buf.append(", "); |
| 50 | |
} |
| 51 | 0 | key = (keys.nextElement()).toString(); |
| 52 | 0 | buf.append(key); |
| 53 | |
} |
| 54 | 0 | return buf.toString(); |
| 55 | |
} |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
final private Dictionary dict; |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
public DictionaryTool (final Dictionary dict) |
| 66 | 0 | { |
| 67 | 0 | this.dict = dict; |
| 68 | 0 | } |
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
final public Enumeration elements () |
| 74 | |
{ |
| 75 | 0 | return dict.elements(); |
| 76 | |
} |
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
final public boolean isEmpty () |
| 82 | |
{ |
| 83 | 0 | return dict.isEmpty(); |
| 84 | |
} |
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
final public Object get (final Object key) |
| 90 | |
{ |
| 91 | 0 | return dict.get(key); |
| 92 | |
} |
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
final public Enumeration keys () |
| 98 | |
{ |
| 99 | 0 | return dict.keys(); |
| 100 | |
} |
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
final public Object put (final Object newKey, final Object newValue) |
| 106 | |
{ |
| 107 | 0 | return dict.put(newKey, newValue); |
| 108 | |
} |
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
final public Object remove (final Object key) |
| 114 | |
{ |
| 115 | 0 | return dict.remove(key); |
| 116 | |
} |
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
final public int size () |
| 122 | |
{ |
| 123 | 0 | return dict.size(); |
| 124 | |
} |
| 125 | |
|
| 126 | |
static public void main (String arg[]) |
| 127 | |
{ |
| 128 | |
|
| 129 | 0 | Dictionary d = new java.util.Hashtable(); |
| 130 | |
|
| 131 | 0 | System.out.println("Adding arguments to hashtable."); |
| 132 | 0 | for (int i = 0; i < arg.length; i++) |
| 133 | |
{ |
| 134 | 0 | d.put(arg[i], "argument " + i); |
| 135 | |
} |
| 136 | |
|
| 137 | 0 | System.out.println("Wrapping hashtable"); |
| 138 | 0 | DictionaryTool dt = new DictionaryTool(d); |
| 139 | |
|
| 140 | 0 | System.out.println("keyString: " + dt.keyString()); |
| 141 | |
|
| 142 | 0 | System.out.println("Done."); |
| 143 | 0 | } |
| 144 | |
|
| 145 | |
} |