< prev index next >

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

Print this page
rev 52979 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: TBD


 392 
 393     /**
 394      * Returns a hashcode calculated from the hashcode of the
 395      * actions String and the url string.
 396      */
 397     public int hashCode() {
 398         return getActions().hashCode()
 399             + scheme.hashCode()
 400             + authority.hashCode()
 401             + (path == null ? 0 : path.hashCode());
 402     }
 403 
 404 
 405     private List<String> normalizeMethods(String methods) {
 406         List<String> l = new ArrayList<>();
 407         StringBuilder b = new StringBuilder();
 408         for (int i=0; i<methods.length(); i++) {
 409             char c = methods.charAt(i);
 410             if (c == ',') {
 411                 String s = b.toString();
 412                 if (s.length() > 0)
 413                     l.add(s);
 414                 b = new StringBuilder();
 415             } else if (c == ' ' || c == '\t') {
 416                 throw new IllegalArgumentException(
 417                     "White space not allowed in methods: \"" + methods + "\"");
 418             } else {
 419                 if (c >= 'a' && c <= 'z') {
 420                     c += 'A' - 'a';
 421                 }
 422                 b.append(c);
 423             }
 424         }
 425         String s = b.toString();
 426         if (s.length() > 0)
 427             l.add(s);
 428         return l;
 429     }
 430 
 431     private List<String> normalizeHeaders(String headers) {
 432         List<String> l = new ArrayList<>();
 433         StringBuilder b = new StringBuilder();
 434         boolean capitalizeNext = true;
 435         for (int i=0; i<headers.length(); i++) {
 436             char c = headers.charAt(i);
 437             if (c >= 'a' && c <= 'z') {
 438                 if (capitalizeNext) {
 439                     c += 'A' - 'a';
 440                     capitalizeNext = false;
 441                 }
 442                 b.append(c);
 443             } else if (c == ' ' || c == '\t') {
 444                 throw new IllegalArgumentException(
 445                     "White space not allowed in headers: \"" + headers + "\"");
 446             } else if (c == '-') {
 447                     capitalizeNext = true;
 448                 b.append(c);
 449             } else if (c == ',') {
 450                 String s = b.toString();
 451                 if (s.length() > 0)
 452                     l.add(s);
 453                 b = new StringBuilder();
 454                 capitalizeNext = true;
 455             } else {
 456                 capitalizeNext = false;
 457                 b.append(c);
 458             }
 459         }
 460         String s = b.toString();
 461         if (s.length() > 0)
 462             l.add(s);
 463         return l;
 464     }
 465 
 466     private void parseURI(String url) {
 467         int len = url.length();
 468         int delim = url.indexOf(':');
 469         if (delim == -1 || delim + 1 == len) {
 470             throw new IllegalArgumentException(
 471                 "Invalid URL string: \"" + url + "\"");
 472         }
 473         scheme = url.substring(0, delim).toLowerCase();
 474         this.ssp = url.substring(delim + 1);
 475 
 476         if (!ssp.startsWith("//")) {
 477             if (!ssp.equals("*")) {
 478                 throw new IllegalArgumentException(
 479                     "Invalid URL string: \"" + url + "\"");
 480             }
 481             this.authority = new Authority(scheme, "*");




 392 
 393     /**
 394      * Returns a hashcode calculated from the hashcode of the
 395      * actions String and the url string.
 396      */
 397     public int hashCode() {
 398         return getActions().hashCode()
 399             + scheme.hashCode()
 400             + authority.hashCode()
 401             + (path == null ? 0 : path.hashCode());
 402     }
 403 
 404 
 405     private List<String> normalizeMethods(String methods) {
 406         List<String> l = new ArrayList<>();
 407         StringBuilder b = new StringBuilder();
 408         for (int i=0; i<methods.length(); i++) {
 409             char c = methods.charAt(i);
 410             if (c == ',') {
 411                 String s = b.toString();
 412                 if (!s.isEmpty())
 413                     l.add(s);
 414                 b = new StringBuilder();
 415             } else if (c == ' ' || c == '\t') {
 416                 throw new IllegalArgumentException(
 417                     "White space not allowed in methods: \"" + methods + "\"");
 418             } else {
 419                 if (c >= 'a' && c <= 'z') {
 420                     c += 'A' - 'a';
 421                 }
 422                 b.append(c);
 423             }
 424         }
 425         String s = b.toString();
 426         if (!s.isEmpty())
 427             l.add(s);
 428         return l;
 429     }
 430 
 431     private List<String> normalizeHeaders(String headers) {
 432         List<String> l = new ArrayList<>();
 433         StringBuilder b = new StringBuilder();
 434         boolean capitalizeNext = true;
 435         for (int i=0; i<headers.length(); i++) {
 436             char c = headers.charAt(i);
 437             if (c >= 'a' && c <= 'z') {
 438                 if (capitalizeNext) {
 439                     c += 'A' - 'a';
 440                     capitalizeNext = false;
 441                 }
 442                 b.append(c);
 443             } else if (c == ' ' || c == '\t') {
 444                 throw new IllegalArgumentException(
 445                     "White space not allowed in headers: \"" + headers + "\"");
 446             } else if (c == '-') {
 447                     capitalizeNext = true;
 448                 b.append(c);
 449             } else if (c == ',') {
 450                 String s = b.toString();
 451                 if (!s.isEmpty())
 452                     l.add(s);
 453                 b = new StringBuilder();
 454                 capitalizeNext = true;
 455             } else {
 456                 capitalizeNext = false;
 457                 b.append(c);
 458             }
 459         }
 460         String s = b.toString();
 461         if (!s.isEmpty())
 462             l.add(s);
 463         return l;
 464     }
 465 
 466     private void parseURI(String url) {
 467         int len = url.length();
 468         int delim = url.indexOf(':');
 469         if (delim == -1 || delim + 1 == len) {
 470             throw new IllegalArgumentException(
 471                 "Invalid URL string: \"" + url + "\"");
 472         }
 473         scheme = url.substring(0, delim).toLowerCase();
 474         this.ssp = url.substring(delim + 1);
 475 
 476         if (!ssp.startsWith("//")) {
 477             if (!ssp.equals("*")) {
 478                 throw new IllegalArgumentException(
 479                     "Invalid URL string: \"" + url + "\"");
 480             }
 481             this.authority = new Authority(scheme, "*");


< prev index next >