View Javadoc
1   /*
2    * $Header: /cvsroot/sinon/sinon/src/java/eteg/sinon/core/ParameterSet.java,v 1.3 2005/08/08 16:37:47 thiagohp Exp $
3    * $Revision: 1.3 $
4    * $Date: 2005/08/08 16:37:47 $
5    * $Author: thiagohp $
6    *
7    * =============================================================================
8    *
9    * Copyright 2004-2005 Eteg Internet Ltda. (http://www.eteg.com.br)
10   *
11   * Licensed under the Apache License, Version 2.0 (the "License");
12   * you may not use this file except in compliance with the License.
13   * You may obtain a copy of the License at
14   *
15   *     http://www.apache.org/licenses/LICENSE-2.0
16   *
17   * Unless required by applicable law or agreed to in writing, software
18   * distributed under the License is distributed on an "AS IS" BASIS,
19   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   * See the License for the specific language governing permissions and
21   * limitations under the License.
22   */
23  package eteg.sinon.core;
24  
25  import java.util.HashMap;
26  import java.util.Iterator;
27  import java.util.Set;
28  import java.util.Map;
29  
30  /***
31   * Class that encapsulates a set of {@link Parameter}s used
32   * int a HTTP request.
33   *
34   * @author <a href="mailto:thiagohp at users.sourceforge.net">Thiago H. de Paula Figueiredo</a>
35   * @author Last modified by $Author: thiagohp $
36   * @version $Revision: 1.3 $
37   */
38  public class ParameterSet {
39  
40      /***
41       * ParameterSet identifier.
42       */
43      private String id;
44  
45      /***
46       * Hashtable that maps parameter names to their values.
47       * Tabela hash nome -> valor.
48       */
49      private HashMap parameters;
50  
51      /***
52       * Constructor without parameters.
53       */
54      public ParameterSet() {
55  
56          id = null;
57          parameters = new HashMap();
58  
59      }
60  
61      /***
62       * Constructor that receives another {@link ParameterSet} from which
63       * this one copies all its parameters. In other words, this instance
64       * becames a copy of the {@link ParameterSet} passed to this constructor.
65       * @param include a {@link ParameterSet} instance.
66       */
67      public ParameterSet(ParameterSet include) {
68  
69          this();
70  
71          final Map includedProperties = include.getParameters();
72          Set keys = includedProperties.keySet();
73          Iterator iterator = keys.iterator();
74  
75          while (iterator.hasNext()) {
76  
77              String name = (String) iterator.next();
78              Parameter parameter = (Parameter) includedProperties.get(name);
79              parameters.put(name, parameter);
80  
81          }
82  
83      }
84  
85      /***
86       * Adds this <code>parameter</code> to this parameter set.
87       * It this object already has a parameter with name
88       * <code>parameter.getName()</code>, it value is overwritten with
89       * <code>parameter.getValue()</code>.
90       * @param parameter um {@link Parameter}.
91       */
92      public void setParameter(Parameter parameter) {
93          parameters.put(parameter.getName(), parameter);
94      }
95  
96      /***
97       * Returns the parameter name associated with <code>name</code>.
98       * @param name a <code>String</code>.
99       * @return uma a {@link Parameter} whose name is <code>name</code>
100      * or <code>null</code>.
101      */
102     public Parameter getParameter(String name) {
103         return (Parameter) parameters.get(name);
104     }
105 
106     /***
107      * Returns the value of the <code>id</code> property.
108      * @return a <code>String</code>.
109      */
110     public String getId() {
111         return id;
112     }
113 
114     /***
115      * Sets the value of the <code>id</code> property.
116      * @param id the new <code>id</code> value.
117      */
118     public void setId(String id) {
119         this.id = id;
120     }
121 
122     /***
123      * Returns the value of the <code>parameters</code> property.
124      * @return a <code>Mao</code>.
125      */
126     public Map getParameters() {
127         return this.parameters;
128     }
129 
130 }