< prev index next >

src/java.base/unix/classes/java/io/UnixFileSystem.java

Print this page
rev 52881 : 8214971: Replace use of string.equals("") with isEmpty()


  86        This way we iterate through the whole pathname string only once. */
  87     public String normalize(String pathname) {
  88         int n = pathname.length();
  89         char prevChar = 0;
  90         for (int i = 0; i < n; i++) {
  91             char c = pathname.charAt(i);
  92             if ((prevChar == '/') && (c == '/'))
  93                 return normalize(pathname, n, i - 1);
  94             prevChar = c;
  95         }
  96         if (prevChar == '/') return normalize(pathname, n, n - 1);
  97         return pathname;
  98     }
  99 
 100     public int prefixLength(String pathname) {
 101         if (pathname.length() == 0) return 0;
 102         return (pathname.charAt(0) == '/') ? 1 : 0;
 103     }
 104 
 105     public String resolve(String parent, String child) {
 106         if (child.equals("")) return parent;
 107         if (child.charAt(0) == '/') {
 108             if (parent.equals("/")) return child;
 109             return parent + child;
 110         }
 111         if (parent.equals("/")) return parent + child;
 112         return parent + '/' + child;
 113     }
 114 
 115     public String getDefaultParent() {
 116         return "/";
 117     }
 118 
 119     public String fromURIPath(String path) {
 120         String p = path;
 121         if (p.endsWith("/") && (p.length() > 1)) {
 122             // "/foo/" --> "/foo", but "/" --> "/"
 123             p = p.substring(0, p.length() - 1);
 124         }
 125         return p;
 126     }




  86        This way we iterate through the whole pathname string only once. */
  87     public String normalize(String pathname) {
  88         int n = pathname.length();
  89         char prevChar = 0;
  90         for (int i = 0; i < n; i++) {
  91             char c = pathname.charAt(i);
  92             if ((prevChar == '/') && (c == '/'))
  93                 return normalize(pathname, n, i - 1);
  94             prevChar = c;
  95         }
  96         if (prevChar == '/') return normalize(pathname, n, n - 1);
  97         return pathname;
  98     }
  99 
 100     public int prefixLength(String pathname) {
 101         if (pathname.length() == 0) return 0;
 102         return (pathname.charAt(0) == '/') ? 1 : 0;
 103     }
 104 
 105     public String resolve(String parent, String child) {
 106         if (child.isEmpty()) return parent;
 107         if (child.charAt(0) == '/') {
 108             if (parent.equals("/")) return child;
 109             return parent + child;
 110         }
 111         if (parent.equals("/")) return parent + child;
 112         return parent + '/' + child;
 113     }
 114 
 115     public String getDefaultParent() {
 116         return "/";
 117     }
 118 
 119     public String fromURIPath(String path) {
 120         String p = path;
 121         if (p.endsWith("/") && (p.length() > 1)) {
 122             // "/foo/" --> "/foo", but "/" --> "/"
 123             p = p.substring(0, p.length() - 1);
 124         }
 125         return p;
 126     }


< prev index next >