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 package org.apache.commons.httpclient;
32
33 import java.io.Serializable;
34
35 import org.apache.commons.httpclient.util.LangUtils;
36
37 /***
38 * <p>A simple class encapsulating a name/value pair.</p>
39 *
40 * @author <a href="mailto:bcholmes@interlog.com">B.C. Holmes</a>
41 * @author Sean C. Sullivan
42 * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
43 *
44 * @version $Revision$ $Date$
45 *
46 */
47 public class NameValuePair implements Serializable {
48
49
50
51 /***
52 * Default constructor.
53 *
54 */
55 public NameValuePair() {
56 this (null, null);
57 }
58
59 /***
60 * Constructor.
61 * @param name The name.
62 * @param value The value.
63 */
64 public NameValuePair(String name, String value) {
65 this.name = name;
66 this.value = value;
67 }
68
69
70
71 /***
72 * Name.
73 */
74 private String name = null;
75
76 /***
77 * Value.
78 */
79 private String value = null;
80
81
82
83 /***
84 * Set the name.
85 *
86 * @param name The new name
87 * @see #getName()
88 */
89 public void setName(String name) {
90 this.name = name;
91 }
92
93
94 /***
95 * Return the name.
96 *
97 * @return String name The name
98 * @see #setName(String)
99 */
100 public String getName() {
101 return name;
102 }
103
104
105 /***
106 * Set the value.
107 *
108 * @param value The new value.
109 */
110 public void setValue(String value) {
111 this.value = value;
112 }
113
114
115 /***
116 * Return the current value.
117 *
118 * @return String value The current value.
119 */
120 public String getValue() {
121 return value;
122 }
123
124
125
126 /***
127 * Get a String representation of this pair.
128 * @return A string representation.
129 */
130 public String toString() {
131 return ("name=" + name + ", " + "value=" + value);
132 }
133
134 public boolean equals(final Object object) {
135 if (object == null) return false;
136 if (this == object) return true;
137 if (object instanceof NameValuePair) {
138 NameValuePair that = (NameValuePair) object;
139 return LangUtils.equals(this.name, that.name)
140 && LangUtils.equals(this.value, that.value);
141 } else {
142 return false;
143 }
144 }
145
146 public int hashCode() {
147 int hash = LangUtils.HASH_SEED;
148 hash = LangUtils.hashCode(hash, this.name);
149 hash = LangUtils.hashCode(hash, this.value);
150 return hash;
151 }
152 }