Coverage Report - org.apache.commons.betwixt.Options

Classes in this File Line Coverage Branch Coverage Complexity
Options
100% 
N/A 
1

 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;
 20  
 import java.util.Set;
 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/'>Apache Commons Team</a>
 27  
  * @since 0.5
 28  
  */
 29  86780
 public class Options {
 30  
     /** Empty string array for use with toArray  */
 31  1072
     private static final String[] EMPTY_STRING_ARRAY = {};
 32  
     /** Option values indexed by name */
 33  42854
     private HashMap valuesByName = new HashMap();
 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 getValue(String name) {
 41  28249
        return (String) valuesByName.get(name); 
 42  
     }
 43  
     
 44  
     /**
 45  
      * Gets the names of each option.
 46  
      * @return <code>String</code> array containing the name of each option
 47  
      */
 48  
     public String[] getNames() {
 49  13
         Set names = valuesByName.keySet();
 50  13
         return (String[]) 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 name, String value) {
 61  546
         valuesByName.put(name, value);
 62  546
     }
 63  
     
 64  
     /**
 65  
      * Adds multiple options from an existing <code>Options</code> collection.
 66  
      * The rule with options is that the most recently set value for an option
 67  
      * wins, so options are potentially overwritten by this call.
 68  
      * 
 69  
      * @param options -
 70  
      *            an existing <code>Options</code> collection
 71  
      */
 72  
     public void addOptions(Options options) {
 73  16579
         valuesByName.putAll(options.valuesByName);
 74  16579
     }
 75  
 }