KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > Options


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16  
17 package org.apache.commons.betwixt;
18
19 import java.util.HashMap JavaDoc;
20 import java.util.Set JavaDoc;
21
22 /**
23  * Collective for <code>Betwixt</code> optional behaviour hints.
24  * An option links a name with a value (both strings).
25  *
26  * @author <a HREF='http://jakarta.apache.org/'>Jakarta Commons Team</a>
27  * @since 0.5
28  */

29 public class Options {
30     /** Empty string array for use with toArray */
31     private static final String JavaDoc[] EMPTY_STRING_ARRAY = {};
32     /** Option values indexed by name */
33     private HashMap JavaDoc valuesByName = new HashMap JavaDoc();
34     
35     /**
36      * Gets the value (if any) associated with the given name.
37      * @param name <code>String</code>, not null
38      * @return the associated value, or null if no value is assocated
39      */

40     public String JavaDoc getValue(String JavaDoc name) {
41        return (String JavaDoc) valuesByName.get(name);
42     }
43     
44     /**
45      * Gets the names of each option.
46      * @return
47      */

48     public String JavaDoc[] getNames() {
49         Set JavaDoc names = valuesByName.keySet();
50         return (String JavaDoc[]) names.toArray(EMPTY_STRING_ARRAY);
51     }
52     
53     /**
54      * Adds the option.
55      * The rule with options is that the last call to set the
56      * value with a given name wins.
57      * @param name <code>String</code> name, not null
58      * @param value <code>Strong</code> name, not null
59      */

60     public void addOption(String JavaDoc name, String JavaDoc value) {
61         valuesByName.put(name, value);
62     }
63 }
64
Popular Tags