1. /*
  2. * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/NameValuePair.java,v 1.17 2004/04/18 23:51:35 jsdever Exp $
  3. * $Revision: 1.17 $
  4. * $Date: 2004/04/18 23:51:35 $
  5. *
  6. * ====================================================================
  7. *
  8. * Copyright 1999-2004 The Apache Software Foundation
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. * ====================================================================
  22. *
  23. * This software consists of voluntary contributions made by many
  24. * individuals on behalf of the Apache Software Foundation. For more
  25. * information on the Apache Software Foundation, please see
  26. * <http://www.apache.org/>.
  27. *
  28. */
  29. package org.apache.commons.httpclient;
  30. import java.io.Serializable;
  31. /**
  32. * <p>A simple class encapsulating a name/value pair.</p>
  33. *
  34. * @author <a href="mailto:bcholmes@interlog.com">B.C. Holmes</a>
  35. * @author Sean C. Sullivan
  36. * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
  37. *
  38. * @version $Revision: 1.17 $ $Date: 2004/04/18 23:51:35 $
  39. *
  40. */
  41. public class NameValuePair implements Serializable {
  42. // ----------------------------------------------------------- Constructors
  43. /**
  44. * Default constructor.
  45. *
  46. */
  47. public NameValuePair() {
  48. this (null, null);
  49. }
  50. /**
  51. * Constructor.
  52. * @param name The name.
  53. * @param value The value.
  54. */
  55. public NameValuePair(String name, String value) {
  56. this.name = name;
  57. this.value = value;
  58. }
  59. // ----------------------------------------------------- Instance Variables
  60. /**
  61. * Name.
  62. */
  63. private String name = null;
  64. /**
  65. * Value.
  66. */
  67. private String value = null;
  68. // ------------------------------------------------------------- Properties
  69. /**
  70. * Set the name.
  71. *
  72. * @param name The new name
  73. * @see #getName()
  74. */
  75. public void setName(String name) {
  76. this.name = name;
  77. }
  78. /**
  79. * Return the name.
  80. *
  81. * @return String name The name
  82. * @see #setName(String)
  83. */
  84. public String getName() {
  85. return name;
  86. }
  87. /**
  88. * Set the value.
  89. *
  90. * @param value The new value.
  91. */
  92. public void setValue(String value) {
  93. this.value = value;
  94. }
  95. /**
  96. * Return the current value.
  97. *
  98. * @return String value The current value.
  99. */
  100. public String getValue() {
  101. return value;
  102. }
  103. // --------------------------------------------------------- Public Methods
  104. /**
  105. * Get a String representation of this pair.
  106. * @return A string representation.
  107. */
  108. public String toString() {
  109. return ("name=" + name + ", " + "value=" + value);
  110. }
  111. /**
  112. * Test if the given <i>object</i> is equal to me. <tt>NameValuePair</tt>s
  113. * are equals if both their <tt>name</tt> and <tt>value</tt> fields are equal.
  114. * If <tt>object</tt> is <tt>null</tt> this method returns <tt>false</tt>.
  115. *
  116. * @param object the {@link Object} to compare to or <tt>null</tt>
  117. * @return true if the objects are equal.
  118. */
  119. public boolean equals(Object object) {
  120. if (object == null) return false;
  121. if (this == object) return true;
  122. if (!(object instanceof NameValuePair)) return false;
  123. NameValuePair pair = (NameValuePair) object;
  124. return ((null == name ? null == pair.name : name.equals(pair.name))
  125. && (null == value ? null == pair.value : value.equals(pair.value)));
  126. }
  127. /**
  128. * hashCode. Returns a hash code for this object such that if <tt>a.{@link
  129. * #equals equals}(b)</tt> then <tt>a.hashCode() == b.hashCode()</tt>.
  130. * @return The hash code.
  131. */
  132. public int hashCode() {
  133. return (this.getClass().hashCode()
  134. ^ (null == name ? 0 : name.hashCode())
  135. ^ (null == value ? 0 : value.hashCode()));
  136. }
  137. /*
  138. public Object clone() {
  139. try {
  140. NameValuePair that = (NameValuePair)(super.clone());
  141. that.setName(this.getName());
  142. that.setValue(this.getValue());
  143. return that;
  144. } catch(CloneNotSupportedException e) {
  145. // this should never happen
  146. throw new RuntimeException("Panic. super.clone not supported in NameValuePair.");
  147. }
  148. }
  149. */
  150. }