##### Coverage Report - org.webmacro.util.DictionaryTool

Classes in this File | Line Coverage | Branch Coverage | Complexity
DictionaryTool |
0% | 0/28
0% | 0/6
| 1.3;1.3

1 |  |
     /*
2 |  |
      * Copyright (C) 1998-2000 Semiotek Inc.  All Rights Reserved.
3 |  |
      *
4 |  |
      * Redistribution and use in source and binary forms, with or without
5 |  |
      * modification, are permitted under the terms of either of the following
6 |  |
      * Open Source licenses:
7 |  |
      *
8 |  |
      * The GNU General Public License, version 2, or any later version, as
9 |  |
      * published by the Free Software Foundation
10 |  |
      * (http://www.fsf.org/copyleft/gpl.html);
11 |  |
      *
12 |  |
      *  or
13 |  |
      *
14 |  |
      * The Semiotek Public License (http://webmacro.org/LICENSE.)
15 |  |
      *
16 |  |
      * This software is provided "as is", with NO WARRANTY, not even the
17 |  |
      * implied warranties of fitness to purpose, or merchantability. You
18 |  |
      * assume all risks and liabilities associated with its use.
19 |  |
      *
20 |  |
      * See www.webmacro.org for more information on the WebMacro project.
21 |  |
      */
22 |  |
23 |  |
24 |  |
     package org.webmacro.util;
25 |  |
26 |  |
     import java.util.Dictionary;
27 |  |
     import java.util.Enumeration;
28 |  |
29 |  |
     /**
30 |  |
      * A HashTool wraps a java.util.Dictionary and provides additional features
31 |  |
      */
32 |  |
     final public class DictionaryTool extends Dictionary
33 |  |
     {
34 |  |
35 |  |
36 |  |
         /**
37 |  |
          * Return a string which concatenates the keys, putting commas
38 |  |
          * between the keys
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 |  |
          * The dictionary being wrapped
59 |  |
          */
60 |  |
         final private Dictionary dict;
61 |  |
62 |  |
         /**
63 |  |
          * Wrap the supplied dictionary.
64 |  |
          */
65 |  |
         public DictionaryTool (final Dictionary dict)
66 | 0 |
         {
67 | 0 |
             this.dict = dict;
68 | 0 |
         }
69 |  |
70 |  |
         /**
71 |  |
          * Forward call to Dictionary
72 |  |
          */
73 |  |
         final public Enumeration elements ()
74 |  |
         {
75 | 0 |
             return dict.elements();
76 |  |
         }
77 |  |
78 |  |
         /**
79 |  |
          * Forward call to Dictionary
80 |  |
          */
81 |  |
         final public boolean isEmpty ()
82 |  |
         {
83 | 0 |
             return dict.isEmpty();
84 |  |
         }
85 |  |
86 |  |
         /**
87 |  |
          * Forward call to Dictionary
88 |  |
          */
89 |  |
         final public Object get (final Object key)
90 |  |
         {
91 | 0 |
             return dict.get(key);
92 |  |
         }
93 |  |
94 |  |
         /**
95 |  |
          * Forward call to Dictionary
96 |  |
          */
97 |  |
         final public Enumeration keys ()
98 |  |
         {
99 | 0 |
             return dict.keys();
100 |  |
         }
101 |  |
102 |  |
         /**
103 |  |
          * Forward call to Dictionary
104 |  |
          */
105 |  |
         final public Object put (final Object newKey, final Object newValue)
106 |  |
         {
107 | 0 |
             return dict.put(newKey, newValue);
108 |  |
         }
109 |  |
110 |  |
         /**
111 |  |
          * Forward call to Dictionary
112 |  |
          */
113 |  |
         final public Object remove (final Object key)
114 |  |
         {
115 | 0 |
             return dict.remove(key);
116 |  |
         }
117 |  |
118 |  |
         /**
119 |  |
          * Forward call to Dictionary
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 |  |
     }