Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * The contents of this file are subject to the terms
   * of the Common Development and Distribution License
   * (the "License").  You may not use this file except
   * in compliance with the License.
   * 
   * You can obtain a copy of the license at
   * http://www.opensource.org/licenses/cddl1.php
   * See the License for the specific language governing
  * permissions and limitations under the License.
  */
 
 /*
  * NewCookie.java
  *
  * Created on March 12, 2007, 5:08 PM
  *
  */
 
 package javax.ws.rs.core;
 
Used to create a new HTTP cookie, transferred in a response.

See also:
IETF RFC 2109
 
 public class NewCookie extends Cookie {
    
    
Specifies that the cookie expires with the current application/browser session.
 
     public static final int DEFAULT_MAX_AGE = -1;
     
     private static final HeaderDelegate<NewCookiedelegate = 
             RuntimeDelegate.getInstance().createHeaderDelegate(NewCookie.class);
 
     private String comment = null;
     private int maxAge = ;
     private boolean secure = false;
    
    
Create a new instance.

Parameters:
name the name of the cookie
value the value of the cookie
Throws:
java.lang.IllegalArgumentException if name is null
 
     public NewCookie(String nameString value) {
         super(namevalue);
     }
    
    
Create a new instance.

Parameters:
name the name of the cookie
value the value of the cookie
path the URI path for which the cookie is valid
domain the host domain for which the cookie is valid
comment the comment
maxAge the maximum age of the cookie in seconds
secure specifies whether the cookie will only be sent over a secure connection
Throws:
java.lang.IllegalArgumentException if name is null
 
     public NewCookie(String nameString valueString pathString domainString commentint maxAgeboolean secure) {
         super(namevaluepathdomain);
         this. = comment;
         this. = maxAge;
         this. = secure;
     }
    
    
Create a new instance.

Parameters:
name the name of the cookie
value the value of the cookie
path the URI path for which the cookie is valid
domain the host domain for which the cookie is valid
version the version of the specification to which the cookie complies
comment the comment
maxAge the maximum age of the cookie in seconds
secure specifies whether the cookie will only be sent over a secure connection
Throws:
java.lang.IllegalArgumentException if name is null
 
     public NewCookie(String nameString valueString pathString domainint versionString commentint maxAgeboolean secure) {
         super(namevaluepathdomainversion);
         this. = comment;
         this. = maxAge;
         this. = secure;
     }
    
    
Create a new instance copying the information in the supplied cookie.

Parameters:
cookie the cookie to clone
Throws:
java.lang.IllegalArgumentException if cookie is null
 
     public NewCookie(Cookie cookie) {
         super(cookie==null ? null : cookie.getName(), 
               cookie==null ? null : cookie.getValue(),
               cookie==null ? null : cookie.getPath(),
               cookie==null ? null : cookie.getDomain(),
              cookie==null ? . : cookie.getVersion());
    }

    
Create a new instance supplementing the information in the supplied cookie.

Parameters:
cookie the cookie to clone
comment the comment
maxAge the maximum age of the cookie in seconds
secure specifies whether the cookie will only be sent over a secure connection
Throws:
java.lang.IllegalArgumentException if cookie is null
    public NewCookie(Cookie cookieString commentint maxAgeboolean secure) {
        this(cookie);
        this. = comment;
        this. = maxAge;
        this. = secure;
    }

    
Creates a new instance of NewCookie by parsing the supplied string.

Parameters:
value the cookie string
Returns:
the newly created NewCookie
Throws:
java.lang.IllegalArgumentException if the supplied string cannot be parsed or is null
    public static NewCookie valueOf(String valuethrows IllegalArgumentException {
        return .fromString(value);
    }
    
    
Get the comment associated with the cookie.

Returns:
the comment or null if none set
    public String getComment() {
        return ;
    }

    
Get the maximum age of the the cookie in seconds. Cookies older than the maximum age are discarded. A cookie can be unset by sending a new cookie with maximum age of 0 since it will overwrite any existing cookie and then be immediately discarded. The default value of -1 indicates that the cookie will be discarded at the end of the browser/application session.

Returns:
the maximum age in seconds
    public int getMaxAge() {
        return ;
    }

    
Whether the cookie will only be sent over a secure connection. Defaults to false.

Returns:
true if the cookie will only be sent over a secure connection, false otherwise.
    public boolean isSecure() {
        return ;
    }
    
    
Obtain a new instance of a Cookie with the same name, value, path, domain and version as this NewCookie. This method can be used to obtain an object that can be compared for equality with another Cookie; since a Cookie will never compare equal to a NewCookie.

Returns:
a Cookie
    public Cookie toCookie() {
        return new Cookie(this.getName(),this.getValue(), this.getPath(), 
                this.getDomain(), this.getVersion());
    }

    
Convert the cookie to a string suitable for use as the value of the corresponding HTTP header.

Returns:
a stringified cookie
    @Override
    public String toString() {
        return .toString(this);
    }

    
Generate a hashcode by hashing all of the properties

Returns:
the hashcode
    @Override
    public int hashCode() {
        int hash = super.hashCode();
        hash = 59 * hash + (this. != null ? this..hashCode() : 0);
        hash = 59 * hash + this.;
        hash = 59 * hash + (this. ? 1 : 0);
        return hash;
    }

    
Compare for equality. Use toCookie() to compare a NewCookie to a Cookie considering only the common properties.

Parameters:
obj
Returns:
true if the object is a NewCookie with the same value for all properties, false otherwise.
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final NewCookie other = (NewCookieobj;
        if (this.getName() != other.getName() && (this.getName() == null || !this.getName().equals(other.getName()))) {
            return false;
        }
        if (this.getValue() != other.getValue() && (this.getValue() == null || !this.getValue().equals(other.getValue()))) {
            return false;
        }
        if (this.getVersion() != other.getVersion()) {
            return false;
        }
        if (this.getPath() != other.getPath() && (this.getPath() == null || !this.getPath().equals(other.getPath()))) {
            return false;
        }
        if (this.getDomain() != other.getDomain() && (this.getDomain() == null || !this.getDomain().equals(other.getDomain()))) {
            return false;
        }
        if (this. != other.comment && (this. == null || !this..equals(other.comment))) {
            return false;
        }
        if (this. != other.maxAge) {
            return false;
        }
        if (this. != other.secure) {
            return false;
        }
        return true;
    }
    
New to GrepCode? Check out our FAQ X