< prev index next >

src/java.base/share/classes/jdk/internal/loader/URLClassPath.java

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


 173 
 174     /**
 175      * Constructs a URLClassPath from a class path string.
 176      *
 177      * @param cp the class path string
 178      * @param skipEmptyElements indicates if empty elements are ignored or
 179      *        treated as the current working directory
 180      *
 181      * @apiNote Used to create the application class path.
 182      */
 183     URLClassPath(String cp, boolean skipEmptyElements) {
 184         ArrayList<URL> path = new ArrayList<>();
 185         if (cp != null) {
 186             // map each element of class path to a file URL
 187             int off = 0, next;
 188             do {
 189                 next = cp.indexOf(File.pathSeparator, off);
 190                 String element = (next == -1)
 191                     ? cp.substring(off)
 192                     : cp.substring(off, next);
 193                 if (element.length() > 0 || !skipEmptyElements) {
 194                     URL url = toFileURL(element);
 195                     if (url != null) path.add(url);
 196                 }
 197                 off = next + 1;
 198             } while (next != -1);
 199         }
 200 
 201         // can't use ArrayDeque#addAll or new ArrayDeque(Collection);
 202         // it's too early in the bootstrap to trigger use of lambdas
 203         int size = path.size();
 204         ArrayDeque<URL> unopenedUrls = new ArrayDeque<>(size);
 205         for (int i = 0; i < size; i++)
 206             unopenedUrls.add(path.get(i));
 207 
 208         this.unopenedUrls = unopenedUrls;
 209         this.path = path;
 210         this.jarHandler = null;
 211         this.acc = null;
 212     }
 213 




 173 
 174     /**
 175      * Constructs a URLClassPath from a class path string.
 176      *
 177      * @param cp the class path string
 178      * @param skipEmptyElements indicates if empty elements are ignored or
 179      *        treated as the current working directory
 180      *
 181      * @apiNote Used to create the application class path.
 182      */
 183     URLClassPath(String cp, boolean skipEmptyElements) {
 184         ArrayList<URL> path = new ArrayList<>();
 185         if (cp != null) {
 186             // map each element of class path to a file URL
 187             int off = 0, next;
 188             do {
 189                 next = cp.indexOf(File.pathSeparator, off);
 190                 String element = (next == -1)
 191                     ? cp.substring(off)
 192                     : cp.substring(off, next);
 193                 if (!element.isEmpty() || !skipEmptyElements) {
 194                     URL url = toFileURL(element);
 195                     if (url != null) path.add(url);
 196                 }
 197                 off = next + 1;
 198             } while (next != -1);
 199         }
 200 
 201         // can't use ArrayDeque#addAll or new ArrayDeque(Collection);
 202         // it's too early in the bootstrap to trigger use of lambdas
 203         int size = path.size();
 204         ArrayDeque<URL> unopenedUrls = new ArrayDeque<>(size);
 205         for (int i = 0; i < size; i++)
 206             unopenedUrls.add(path.get(i));
 207 
 208         this.unopenedUrls = unopenedUrls;
 209         this.path = path;
 210         this.jarHandler = null;
 211         this.acc = null;
 212     }
 213 


< prev index next >