View Javadoc

1   /*
2    * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/NameValuePair.java,v 1.14.2.1 2004/02/22 18:21:13 olegk Exp $
3    * $Revision: 1.14.2.1 $
4    * $Date: 2004/02/22 18:21:13 $
5    *
6    * ====================================================================
7    *
8    *  Copyright 1999-2004 The Apache Software Foundation
9    *
10   *  Licensed under the Apache License, Version 2.0 (the "License");
11   *  you may not use this file except in compliance with the License.
12   *  You may obtain a copy of the License at
13   *
14   *      http://www.apache.org/licenses/LICENSE-2.0
15   *
16   *  Unless required by applicable law or agreed to in writing, software
17   *  distributed under the License is distributed on an "AS IS" BASIS,
18   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   *  See the License for the specific language governing permissions and
20   *  limitations under the License.
21   * ====================================================================
22   *
23   * This software consists of voluntary contributions made by many
24   * individuals on behalf of the Apache Software Foundation.  For more
25   * information on the Apache Software Foundation, please see
26   * <http://www.apache.org/>.
27   *
28   * [Additional notices, if required by prior licensing conditions]
29   *
30   */
31  
32  package org.apache.commons.httpclient;
33  
34  import java.io.Serializable;
35  
36  /***
37   * <p>A simple class encapsulating a name/value pair.</p>
38   * 
39   * @author <a href="mailto:bcholmes@interlog.com">B.C. Holmes</a>
40   * @author Sean C. Sullivan
41   * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
42   * 
43   * @version $Revision: 1.14.2.1 $ $Date: 2004/02/22 18:21:13 $
44   * 
45   */
46  public class NameValuePair implements Serializable {
47  
48      // ----------------------------------------------------------- Constructors
49  
50      /***
51       * Default constructor.
52       * 
53       */
54      public NameValuePair() {
55          this (null, null);
56      }
57  
58      /***
59       * Constructor.
60       * @param name The name.
61       * @param value The value.
62       */
63      public NameValuePair(String name, String value) {
64          this.name = name;
65          this.value = value;
66      }
67  
68      // ----------------------------------------------------- Instance Variables
69  
70      /***
71       * Name.
72       */
73      private String name = null;
74  
75      /***
76       * Value.
77       */
78      private String value = null;
79  
80      // ------------------------------------------------------------- Properties
81  
82      /***
83       * Set the name.
84       *
85       * @param name The new name
86       * @see #getName()
87       */
88      public void setName(String name) {
89          this.name = name;
90      }
91  
92  
93      /***
94       * Return the name.
95       *
96       * @return String name The name
97       * @see #setName(String)
98       */
99      public String getName() {
100         return name;
101     }
102 
103 
104     /***
105      * Set the value.
106      *
107      * @param value The new value.
108      */
109     public void setValue(String value) {
110         this.value = value;
111     }
112 
113 
114     /***
115      * Return the current value.
116      *
117      * @return String value The current value.
118      */
119     public String getValue() {
120         return value;
121     }
122 
123     // --------------------------------------------------------- Public Methods
124 
125     /***
126      * Get a String representation of this pair.
127      * @return A string representation.
128      */
129     public String toString() {
130         return ("name=" + name + ", " + "value=" + value);
131     }
132 
133     /***
134      * Test if the given <i>object</i> is equal to me. In this implementation,
135      * an <i>object</i> is equal to me iff it has the same runtime type and the
136      * <i>name</i> and <i>value</i> attributes are both <tt>equal</tt> (or
137      * <tt>==</tt>).
138      *
139      * @param object the {@link Object} to compare to
140      * @return true if the objects are equal.
141      */
142     public boolean equals(Object object) {
143         if (this == object) {
144             return true;
145         } else if (this.getClass().equals(object.getClass())) {
146             NameValuePair pair = (NameValuePair) object;
147             return ((null == name ? null == pair.name : name.equals(pair.name))
148                    && (null == value ? null == pair.value : value.equals(pair.value)));
149         } else {
150             return false;
151         }
152     }
153 
154     /***
155      * hashCode. Returns a hash code for this object such that if <tt>a.{@link
156      * #equals equals}(b)</tt> then <tt>a.hashCode() == b.hashCode()</tt>.
157      * @return The hash code.
158      */
159     public int hashCode() {
160         return (this.getClass().hashCode() 
161             ^ (null == name ? 0 : name.hashCode()) 
162             ^ (null == value ? 0 : value.hashCode()));
163     }
164 
165     /*
166     public Object clone() {
167         try {
168             NameValuePair that = (NameValuePair)(super.clone());
169             that.setName(this.getName());
170             that.setValue(this.getValue());
171             return that;
172         } catch(CloneNotSupportedException e) {
173             // this should never happen
174             throw new RuntimeException("Panic. super.clone not supported in NameValuePair.");
175         }
176     }
177     */
178 }