KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > maverick > http > NameValuePair


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.maverick.http;
21
22 import java.io.Serializable JavaDoc;
23
24 /**
25  *
26  * @author Lee David Painter <a HREF="mailto:lee@3sp.com">&lt;lee@3sp.com&gt;</a>
27  */

28 public class NameValuePair implements Serializable JavaDoc {
29
30     // ----------------------------------------------------------- Constructors
31

32     /**
33      * Default constructor.
34      *
35      */

36     public NameValuePair() {
37         this(null, null);
38     }
39
40     /**
41      * Constructor.
42      *
43      * @param name The name.
44      * @param value The value.
45      */

46     public NameValuePair(String JavaDoc name, String JavaDoc value) {
47         this.name = name;
48         this.value = value;
49     }
50
51     // ----------------------------------------------------- Instance Variables
52

53     /**
54      * Name.
55      */

56     private String JavaDoc name = null;
57
58     /**
59      * Value.
60      */

61     private String JavaDoc value = null;
62
63     // ------------------------------------------------------------- Properties
64

65     /**
66      * Set the name.
67      *
68      * @param name The new name
69      * @see #getName()
70      */

71     public void setName(String JavaDoc name) {
72         this.name = name;
73     }
74
75     /**
76      * Return the name.
77      *
78      * @return String name The name
79      * @see #setName(String)
80      */

81     public String JavaDoc getName() {
82         return name;
83     }
84
85     /**
86      * Set the value.
87      *
88      * @param value The new value.
89      */

90     public void setValue(String JavaDoc value) {
91         this.value = value;
92     }
93
94     /**
95      * Return the current value.
96      *
97      * @return String value The current value.
98      */

99     public String JavaDoc getValue() {
100         return value;
101     }
102
103     // --------------------------------------------------------- Public Methods
104

105     /**
106      * Get a String representation of this pair.
107      *
108      * @return A string representation.
109      */

110     public String JavaDoc toString() {
111         return ("name=" + name + ", " + "value=" + value); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
112
}
113
114     /**
115      * Test if the given <i>object</i> is equal to me. <tt>NameValuePair</tt>s
116      * are equals if both their <tt>name</tt> and <tt>value</tt> fields are
117      * equal. If <tt>object</tt> is <tt>null</tt> this method returns
118      * <tt>false</tt>.
119      *
120      * @param object the {@link Object} to compare to or <tt>null</tt>
121      * @return true if the objects are equal.
122      */

123     public boolean equals(Object JavaDoc object) {
124         if (object == null)
125             return false;
126         if (this == object)
127             return true;
128         if (!(object instanceof NameValuePair))
129             return false;
130
131         NameValuePair pair = (NameValuePair) object;
132         return ((null == name ? null == pair.name : name.equals(pair.name)) && (null == value ? null == pair.value
133             : value.equals(pair.value)));
134     }
135
136     /**
137      * hashCode. Returns a hash code for this object such that if <tt>a.{@link
138      * #equals equals}(b)</tt>
139      * then <tt>a.hashCode() == b.hashCode()</tt>.
140      *
141      * @return The hash code.
142      */

143     public int hashCode() {
144         return (this.getClass().hashCode() ^ (null == name ? 0 : name.hashCode()) ^ (null == value ? 0 : value.hashCode()));
145     }
146
147     /*
148      * public Object clone() { try { NameValuePair that =
149      * (NameValuePair)(super.clone()); that.setName(this.getName());
150      * that.setValue(this.getValue()); return that; }
151      * catch(CloneNotSupportedException e) { // this should never happen throw
152      * new RuntimeException("Panic. super.clone not supported in
153      * NameValuePair."); } }
154      */

155 }
156
Popular Tags