class NewCookieHeaderDelegate implements RuntimeDelegate.HeaderDelegate<NewCookie> {

    @Override
    public String toString(NewCookie cookie) {
        checkArgument(cookie != null);
        StringBuilder sb = new StringBuilder();
        sb.append(cookie.getName()).append('=').append(addQuotesIfHasWhitespace(cookie.getValue()));

        sb.append(';').append("Version=").append(cookie.getVersion());

        if (cookie.getComment() != null) {
            sb.append(';').append("Comment=").append(addQuotesIfHasWhitespace(cookie.getComment()));
        }

        if (cookie.getDomain() != null) {
            sb.append(';').append("Domain=").append(addQuotesIfHasWhitespace(cookie.getDomain()));
        }

        if (cookie.getPath() != null) {
            sb.append(';').append("Path=").append(addQuotesIfHasWhitespace(cookie.getPath()));
        }

        if (cookie.getMaxAge() != -1) {
            sb.append(';').append("Max-Age=").append(addQuotesIfHasWhitespace(Integer.toString(cookie.getMaxAge())));
        }

        if (cookie.getExpiry() != null) {
            sb.append(';').append("Expires=");
            sb.append(HeaderHelper.formatDate(cookie.getExpiry()));
        }

        if (cookie.isSecure()) {
            sb.append(';').append("Secure");
        }

        if (cookie.isHttpOnly()) {
            sb.append(';').append("HttpOnly");
        }

        return sb.toString();
    }

}