/*
 * Copyright 2010 Ning, Inc.
 *
 * Ning licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 *
 */
package com.ning.http.client;

public class Cookie {
    private String domain;
    private String name;
    private String value;
    private String path;
    private int maxAge;
    private boolean secure;

    public Cookie(String domain, String name, String value, String path, int maxAge, boolean secure) {
        this.domain = domain;
        this.name = name;
        this.value = value;
        this.path = path;
        this.maxAge = maxAge;
        this.secure = secure;
    }

    public String getDomain() {
        return domain;
    }

    public String getName() {
        return name;
    }

    public String getValue() {
        return value;
    }

    public String getPath() {
        return path;
    }

    public int getMaxAge() {
        return maxAge;
    }

    public boolean isSecure() {
        return secure;
    }

    @Override
    public String toString() {
        return String.format("Cookie: domain=%s, name=%s, value=%s, path=%s, maxAge=%d, secure=%s",
                domain, name, value, path, maxAge, secure);
    }
}

@@ -645,16 +645,95 @@
 lient;%0A%0A
+import java.util.Collections;%0Aimport java.util.Set;%0Aimport java.util.TreeSet;%0A%0A
 public c
@@ -754,24 +754,30 @@
     private 
+final 
 String domai
@@ -787,24 +787,30 @@
     private 
+final 
 String name;
@@ -818,24 +818,30 @@
     private 
+final 
 String value
@@ -854,16 +854,22 @@
 private 
+final 
 String p
@@ -885,16 +885,22 @@
 private 
+final 
 int maxA
@@ -915,16 +915,22 @@
 private 
+final 
 boolean 
@@ -936,16 +936,156 @@
  secure;
+%0A    private final int version;%0A    private Set%3CInteger%3E ports = Collections.emptySet();%0A    private Set%3CInteger%3E unmodifiablePorts = ports;
 %0A%0A    pu
@@ -1343,32 +1343,383 @@
 ecure = secure;%0A
+        this.version = 1;%0A    %7D%0A%0A    public Cookie(String domain, String name, String value, String path, int maxAge, boolean secure, int version) %7B%0A        this.domain = domain;%0A        this.name = name;%0A        this.value = value;%0A        this.path = path;%0A        this.maxAge = maxAge;%0A        this.secure = secure;%0A        this.version = version;%0A
     %7D%0A%0A    publi
@@ -2064,24 +2064,1510 @@
 ure;%0A    %7D%0A%0A
+    public int getVersion() %7B%0A        return version;%0A    %7D%0A%0A    public Set%3CInteger%3E getPorts() %7B%0A        if (unmodifiablePorts == null) %7B%0A            unmodifiablePorts = Collections.unmodifiableSet(ports);%0A        %7D%0A        return unmodifiablePorts;%0A    %7D%0A%0A    public void setPorts(int... ports) %7B%0A        if (ports == null) %7B%0A            throw new NullPointerException(%22ports%22);%0A        %7D%0A%0A        int%5B%5D portsCopy = ports.clone();%0A        if (portsCopy.length == 0) %7B%0A            unmodifiablePorts = this.ports = Collections.emptySet();%0A        %7D else %7B%0A            Set%3CInteger%3E newPorts = new TreeSet%3CInteger%3E();%0A            for (int p: portsCopy) %7B%0A                if (p %3C= 0 %7C%7C p %3E 65535) %7B%0A                    throw new IllegalArgumentException(%22port out of range: %22 + p);%0A                %7D%0A                newPorts.add(Integer.valueOf(p));%0A            %7D%0A            this.ports = newPorts;%0A            unmodifiablePorts = null;%0A        %7D%0A    %7D%0A%0A    public void setPorts(Iterable%3CInteger%3E ports) %7B%0A        Set%3CInteger%3E newPorts = new TreeSet%3CInteger%3E();%0A        for (int p: ports) %7B%0A            if (p %3C= 0 %7C%7C p %3E 65535) %7B%0A                throw new IllegalArgumentException(%22port out of range: %22 + p);%0A            %7D%0A            newPorts.add(Integer.valueOf(p));%0A        %7D%0A        if (newPorts.isEmpty()) %7B%0A            unmodifiablePorts = this.ports = Collections.emptySet();%0A        %7D else %7B%0A            this.ports = newPorts;%0A            unmodifiablePorts = null;%0A        %7D%0A    %7D%0A%0A
     @Overrid

Improve Cookie class.