1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
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
69
70 /***
71 * Name.
72 */
73 private String name = null;
74
75 /***
76 * Value.
77 */
78 private String value = null;
79
80
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
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
167
168
169
170
171
172
173
174
175
176
177
178 }