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 package org.apache.commons.httpclient;
31
32 import java.io.Serializable;
33
34 /***
35 * <p>A simple class encapsulating a name/value pair.</p>
36 *
37 * @author <a href="mailto:bcholmes@interlog.com">B.C. Holmes</a>
38 * @author Sean C. Sullivan
39 * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
40 *
41 * @version $Revision: 1.17 $ $Date: 2004/04/18 23:51:35 $
42 *
43 */
44 public class NameValuePair implements Serializable {
45
46
47
48 /***
49 * Default constructor.
50 *
51 */
52 public NameValuePair() {
53 this (null, null);
54 }
55
56 /***
57 * Constructor.
58 * @param name The name.
59 * @param value The value.
60 */
61 public NameValuePair(String name, String value) {
62 this.name = name;
63 this.value = value;
64 }
65
66
67
68 /***
69 * Name.
70 */
71 private String name = null;
72
73 /***
74 * Value.
75 */
76 private String value = null;
77
78
79
80 /***
81 * Set the name.
82 *
83 * @param name The new name
84 * @see #getName()
85 */
86 public void setName(String name) {
87 this.name = name;
88 }
89
90
91 /***
92 * Return the name.
93 *
94 * @return String name The name
95 * @see #setName(String)
96 */
97 public String getName() {
98 return name;
99 }
100
101
102 /***
103 * Set the value.
104 *
105 * @param value The new value.
106 */
107 public void setValue(String value) {
108 this.value = value;
109 }
110
111
112 /***
113 * Return the current value.
114 *
115 * @return String value The current value.
116 */
117 public String getValue() {
118 return value;
119 }
120
121
122
123 /***
124 * Get a String representation of this pair.
125 * @return A string representation.
126 */
127 public String toString() {
128 return ("name=" + name + ", " + "value=" + value);
129 }
130
131 /***
132 * Test if the given <i>object</i> is equal to me. <tt>NameValuePair</tt>s
133 * are equals if both their <tt>name</tt> and <tt>value</tt> fields are equal.
134 * If <tt>object</tt> is <tt>null</tt> this method returns <tt>false</tt>.
135 *
136 * @param object the {@link Object} to compare to or <tt>null</tt>
137 * @return true if the objects are equal.
138 */
139 public boolean equals(Object object) {
140 if (object == null) return false;
141 if (this == object) return true;
142 if (!(object instanceof NameValuePair)) return false;
143
144 NameValuePair pair = (NameValuePair) object;
145 return ((null == name ? null == pair.name : name.equals(pair.name))
146 && (null == value ? null == pair.value : value.equals(pair.value)));
147 }
148
149 /***
150 * hashCode. Returns a hash code for this object such that if <tt>a.{@link
151 * #equals equals}(b)</tt> then <tt>a.hashCode() == b.hashCode()</tt>.
152 * @return The hash code.
153 */
154 public int hashCode() {
155 return (this.getClass().hashCode()
156 ^ (null == name ? 0 : name.hashCode())
157 ^ (null == value ? 0 : value.hashCode()));
158 }
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173 }