FileDocCategorySizeDatePackage
CookiePathComparator.javaAPI DocAndroid 1.5 API2846Wed May 06 22:41:10 BST 2009org.apache.http.cookie

CookiePathComparator

public class CookiePathComparator extends Object implements Serializable, Comparator
This cookie comparator ensures that multiple cookies satisfying a common criteria are ordered in the Cookie header such that those with more specific Path attributes precede those with less specific.

This comparator assumes that Path attributes of two cookies path-match a commmon request-URI. Otherwise, the result of the comparison is undefined.

author
Oleg Kalnichevski

Fields Summary
private static final long
serialVersionUID
Constructors Summary
Methods Summary
public intcompare(org.apache.http.cookie.Cookie c1, org.apache.http.cookie.Cookie c2)

        String path1 = normalizePath(c1);
        String path2 = normalizePath(c2);
        if (path1.equals(path2)) {
            return 0;
        } else if (path1.startsWith(path2)) {
            return -1;
        } else if (path2.startsWith(path1)) {
            return 1;
        } else {
            // Does not really matter
            return 0;
        }
    
private java.lang.StringnormalizePath(org.apache.http.cookie.Cookie cookie)


         
        String path = cookie.getPath();
        if (path == null) {
            path = "/";
        }
        if (!path.endsWith("/")) {
            path = path + '/";
        }
        return path;