* Cookie is no longer a subclass of NameValuePair
* Removed #equals and #hashCode methods. The concept of identity equality and value equality of cookies is domain specific. It should be addressed at the application level git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@418102 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a7302e6278
commit
370b72bdf7
|
@ -31,9 +31,6 @@ package org.apache.http.cookie;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.apache.http.NameValuePair;
|
|
||||||
import org.apache.http.util.LangUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* HTTP "magic-cookie" represents a piece of state information
|
* HTTP "magic-cookie" represents a piece of state information
|
||||||
|
@ -54,13 +51,39 @@ import org.apache.http.util.LangUtils;
|
||||||
*
|
*
|
||||||
* @version $Revision$
|
* @version $Revision$
|
||||||
*/
|
*/
|
||||||
public class Cookie extends NameValuePair {
|
public class Cookie {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor. Creates a blank cookie
|
* Default Constructor taking a name and a value. The value may be null.
|
||||||
|
*
|
||||||
|
* @param name The name.
|
||||||
|
* @param value The value.
|
||||||
*/
|
*/
|
||||||
public Cookie(final String name, final String value) {
|
public Cookie(final String name, final String value) {
|
||||||
super(name, value);
|
super();
|
||||||
|
if (name == null) {
|
||||||
|
throw new IllegalArgumentException("Name may not be null");
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name.
|
||||||
|
*
|
||||||
|
* @return String name The name
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value.
|
||||||
|
*
|
||||||
|
* @return String value The current value.
|
||||||
|
*/
|
||||||
|
public String getValue() {
|
||||||
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -150,10 +173,6 @@ public class Cookie extends NameValuePair {
|
||||||
*/
|
*/
|
||||||
public void setDomain(String domain) {
|
public void setDomain(String domain) {
|
||||||
if (domain != null) {
|
if (domain != null) {
|
||||||
int ndx = domain.indexOf(":");
|
|
||||||
if (ndx != -1) {
|
|
||||||
domain = domain.substring(0, ndx);
|
|
||||||
}
|
|
||||||
cookieDomain = domain.toLowerCase();
|
cookieDomain = domain.toLowerCase();
|
||||||
} else {
|
} else {
|
||||||
cookieDomain = null;
|
cookieDomain = null;
|
||||||
|
@ -303,40 +322,11 @@ public class Cookie extends NameValuePair {
|
||||||
return hasDomainAttribute;
|
return hasDomainAttribute;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a hash code in keeping with the
|
|
||||||
* {@link Object#hashCode} general hashCode contract.
|
|
||||||
* @return A hash code
|
|
||||||
*/
|
|
||||||
public int hashCode() {
|
|
||||||
int hash = LangUtils.HASH_SEED;
|
|
||||||
hash = LangUtils.hashCode(hash, this.getName());
|
|
||||||
hash = LangUtils.hashCode(hash, this.cookieDomain);
|
|
||||||
hash = LangUtils.hashCode(hash, this.cookiePath);
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Two cookies are equal if the name, path and domain match.
|
|
||||||
* @param obj The object to compare against.
|
|
||||||
* @return true if the two objects are equal.
|
|
||||||
*/
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (obj == null) return false;
|
|
||||||
if (this == obj) return true;
|
|
||||||
if (obj instanceof Cookie) {
|
|
||||||
Cookie that = (Cookie) obj;
|
|
||||||
return LangUtils.equals(this.getName(), that.getName())
|
|
||||||
&& LangUtils.equals(this.cookieDomain, that.cookieDomain)
|
|
||||||
&& LangUtils.equals(this.cookiePath, that.cookiePath);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------- Instance Variables
|
// ----------------------------------------------------- Instance Variables
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final String value;
|
||||||
|
|
||||||
/** Comment attribute. */
|
/** Comment attribute. */
|
||||||
private String cookieComment;
|
private String cookieComment;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue