View Javadoc

1   /*
2    * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/NameValuePair.java,v 1.17 2004/04/18 23:51:35 jsdever Exp $
3    * $Revision: 157457 $
4    * $Date: 2005-03-14 15:23:16 -0500 (Mon, 14 Mar 2005) $
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   */
29  
30  package org.apache.commons.httpclient;
31  
32  import java.io.Serializable;
33  
34  import org.apache.commons.httpclient.util.LangUtils;
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: 157457 $ $Date: 2005-03-14 15:23:16 -0500 (Mon, 14 Mar 2005) $
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     public boolean equals(final Object object) {
134         if (object == null) return false;
135         if (this == object) return true;
136         if (object instanceof NameValuePair) {
137             NameValuePair that = (NameValuePair) object;
138             return LangUtils.equals(this.name, that.name)
139                   && LangUtils.equals(this.value, that.value);
140         } else {
141             return false;
142         }
143     }
144 
145     public int hashCode() {
146         int hash = LangUtils.HASH_SEED;
147         hash = LangUtils.hashCode(hash, this.name);
148         hash = LangUtils.hashCode(hash, this.value);
149         return hash;
150     }
151 }