NameValuePair.java
1 /* 2 * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/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: 480424 $ 4 * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $ 5 * 6 * ==================================================================== 7 * 8 * Licensed to the Apache Software Foundation (ASF) under one or more 9 * contributor license agreements. See the NOTICE file distributed with 10 * this work for additional information regarding copyright ownership. 11 * The ASF licenses this file to You under the Apache License, Version 2.0 12 * (the "License"); you may not use this file except in compliance with 13 * the License. You may obtain a copy of the License at 14 * 15 * http://www.apache.org/licenses/LICENSE-2.0 16 * 17 * Unless required by applicable law or agreed to in writing, software 18 * distributed under the License is distributed on an "AS IS" BASIS, 19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 * See the License for the specific language governing permissions and 21 * limitations under the License. 22 * ==================================================================== 23 * 24 * This software consists of voluntary contributions made by many 25 * individuals on behalf of the Apache Software Foundation. For more 26 * information on the Apache Software Foundation, please see 27 * <http://www.apache.org/>. 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: 480424 $ $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $ 45 * 46 */ 47 public class NameValuePair implements Serializable { 48 49 // ----------------------------------------------------------- Constructors 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 // ----------------------------------------------------- Instance Variables 70 71 /** 72 * Name. 73 */ 74 private String name = null; 75 76 /** 77 * Value. 78 */ 79 private String value = null; 80 81 // ------------------------------------------------------------- Properties 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 // --------------------------------------------------------- Public Methods 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 }