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 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
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 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 }