< prev index next >

src/java.base/share/classes/java/net/URLPermission.java

Print this page
rev 51919 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: dfuchs, alanb


 366 
 367     /**
 368      * Returns a hashcode calculated from the hashcode of the
 369      * actions String and the url string.
 370      */
 371     public int hashCode() {
 372         return getActions().hashCode()
 373             + scheme.hashCode()
 374             + authority.hashCode()
 375             + (path == null ? 0 : path.hashCode());
 376     }
 377 
 378 
 379     private List<String> normalizeMethods(String methods) {
 380         List<String> l = new ArrayList<>();
 381         StringBuilder b = new StringBuilder();
 382         for (int i=0; i<methods.length(); i++) {
 383             char c = methods.charAt(i);
 384             if (c == ',') {
 385                 String s = b.toString();
 386                 if (s.length() > 0)
 387                     l.add(s);
 388                 b = new StringBuilder();
 389             } else if (c == ' ' || c == '\t') {
 390                 throw new IllegalArgumentException(
 391                     "White space not allowed in methods: \"" + methods + "\"");
 392             } else {
 393                 if (c >= 'a' && c <= 'z') {
 394                     c += 'A' - 'a';
 395                 }
 396                 b.append(c);
 397             }
 398         }
 399         String s = b.toString();
 400         if (s.length() > 0)
 401             l.add(s);
 402         return l;
 403     }
 404 
 405     private List<String> normalizeHeaders(String headers) {
 406         List<String> l = new ArrayList<>();
 407         StringBuilder b = new StringBuilder();
 408         boolean capitalizeNext = true;
 409         for (int i=0; i<headers.length(); i++) {
 410             char c = headers.charAt(i);
 411             if (c >= 'a' && c <= 'z') {
 412                 if (capitalizeNext) {
 413                     c += 'A' - 'a';
 414                     capitalizeNext = false;
 415                 }
 416                 b.append(c);
 417             } else if (c == ' ' || c == '\t') {
 418                 throw new IllegalArgumentException(
 419                     "White space not allowed in headers: \"" + headers + "\"");
 420             } else if (c == '-') {
 421                     capitalizeNext = true;
 422                 b.append(c);
 423             } else if (c == ',') {
 424                 String s = b.toString();
 425                 if (s.length() > 0)
 426                     l.add(s);
 427                 b = new StringBuilder();
 428                 capitalizeNext = true;
 429             } else {
 430                 capitalizeNext = false;
 431                 b.append(c);
 432             }
 433         }
 434         String s = b.toString();
 435         if (s.length() > 0)
 436             l.add(s);
 437         return l;
 438     }
 439 
 440     private void parseURI(String url) {
 441         int len = url.length();
 442         int delim = url.indexOf(':');
 443         if (delim == -1 || delim + 1 == len) {
 444             throw new IllegalArgumentException(
 445                 "Invalid URL string: \"" + url + "\"");
 446         }
 447         scheme = url.substring(0, delim).toLowerCase();
 448         this.ssp = url.substring(delim + 1);
 449 
 450         if (!ssp.startsWith("//")) {
 451             if (!ssp.equals("*")) {
 452                 throw new IllegalArgumentException(
 453                     "Invalid URL string: \"" + url + "\"");
 454             }
 455             this.authority = new Authority(scheme, "*");




 366 
 367     /**
 368      * Returns a hashcode calculated from the hashcode of the
 369      * actions String and the url string.
 370      */
 371     public int hashCode() {
 372         return getActions().hashCode()
 373             + scheme.hashCode()
 374             + authority.hashCode()
 375             + (path == null ? 0 : path.hashCode());
 376     }
 377 
 378 
 379     private List<String> normalizeMethods(String methods) {
 380         List<String> l = new ArrayList<>();
 381         StringBuilder b = new StringBuilder();
 382         for (int i=0; i<methods.length(); i++) {
 383             char c = methods.charAt(i);
 384             if (c == ',') {
 385                 String s = b.toString();
 386                 if (!s.isEmpty())
 387                     l.add(s);
 388                 b = new StringBuilder();
 389             } else if (c == ' ' || c == '\t') {
 390                 throw new IllegalArgumentException(
 391                     "White space not allowed in methods: \"" + methods + "\"");
 392             } else {
 393                 if (c >= 'a' && c <= 'z') {
 394                     c += 'A' - 'a';
 395                 }
 396                 b.append(c);
 397             }
 398         }
 399         String s = b.toString();
 400         if (!s.isEmpty())
 401             l.add(s);
 402         return l;
 403     }
 404 
 405     private List<String> normalizeHeaders(String headers) {
 406         List<String> l = new ArrayList<>();
 407         StringBuilder b = new StringBuilder();
 408         boolean capitalizeNext = true;
 409         for (int i=0; i<headers.length(); i++) {
 410             char c = headers.charAt(i);
 411             if (c >= 'a' && c <= 'z') {
 412                 if (capitalizeNext) {
 413                     c += 'A' - 'a';
 414                     capitalizeNext = false;
 415                 }
 416                 b.append(c);
 417             } else if (c == ' ' || c == '\t') {
 418                 throw new IllegalArgumentException(
 419                     "White space not allowed in headers: \"" + headers + "\"");
 420             } else if (c == '-') {
 421                     capitalizeNext = true;
 422                 b.append(c);
 423             } else if (c == ',') {
 424                 String s = b.toString();
 425                 if (!s.isEmpty())
 426                     l.add(s);
 427                 b = new StringBuilder();
 428                 capitalizeNext = true;
 429             } else {
 430                 capitalizeNext = false;
 431                 b.append(c);
 432             }
 433         }
 434         String s = b.toString();
 435         if (!s.isEmpty())
 436             l.add(s);
 437         return l;
 438     }
 439 
 440     private void parseURI(String url) {
 441         int len = url.length();
 442         int delim = url.indexOf(':');
 443         if (delim == -1 || delim + 1 == len) {
 444             throw new IllegalArgumentException(
 445                 "Invalid URL string: \"" + url + "\"");
 446         }
 447         scheme = url.substring(0, delim).toLowerCase();
 448         this.ssp = url.substring(delim + 1);
 449 
 450         if (!ssp.startsWith("//")) {
 451             if (!ssp.equals("*")) {
 452                 throw new IllegalArgumentException(
 453                     "Invalid URL string: \"" + url + "\"");
 454             }
 455             this.authority = new Authority(scheme, "*");


< prev index next >