1 30 31 package org.apache.commons.httpclient.cookie; 32 33 import java.util.Comparator ; 34 35 import org.apache.commons.httpclient.Cookie; 36 37 53 public class CookiePathComparator implements Comparator { 54 55 private String normalizePath(final Cookie cookie) { 56 String path = cookie.getPath(); 57 if (path == null) { 58 path = "/"; 59 } 60 if (!path.endsWith("/")) { 61 path = path + "/"; 62 } 63 return path; 64 } 65 66 public int compare(final Object o1, final Object o2) { 67 Cookie c1 = (Cookie) o1; 68 Cookie c2 = (Cookie) o2; 69 String path1 = normalizePath(c1); 70 String path2 = normalizePath(c2); 71 if (path1.equals(path2)) { 72 return 0; 73 } else if (path1.startsWith(path2)) { 74 return -1; 75 } else if (path2.startsWith(path1)) { 76 return 1; 77 } else { 78 return 0; 80 } 81 } 82 83 } 84 | Popular Tags |