jdk/src/share/classes/sun/awt/shell/ShellFolder.java
changeset 2817 f171f2417978
parent 2489 5052722686e2
child 3084 67ca55732362
equal deleted inserted replaced
2816:847399d5b5e9 2817:f171f2417978
   272         return new File(f.toURI().normalize());
   272         return new File(f.toURI().normalize());
   273     }
   273     }
   274 
   274 
   275     // Override File methods
   275     // Override File methods
   276 
   276 
   277     public static void sort(List<? extends File> files) {
   277     public static void sort(final List<? extends File> files) {
   278         if (files == null || files.size() <= 1) {
   278         if (files == null || files.size() <= 1) {
   279             return;
   279             return;
   280         }
   280         }
   281 
   281 
   282         // Check that we can use the ShellFolder.sortChildren() method:
   282         // To avoid loads of synchronizations with Invoker and improve performance we
   283         //   1. All files have the same non-null parent
   283         // synchronize the whole code of the sort method once
   284         //   2. All files is ShellFolders
   284         getInvoker().invoke(new Callable<Void>() {
   285         File commonParent = null;
   285             public Void call() throws Exception {
   286 
   286                 // Check that we can use the ShellFolder.sortChildren() method:
   287         for (File file : files) {
   287                 //   1. All files have the same non-null parent
   288             File parent = file.getParentFile();
   288                 //   2. All files is ShellFolders
   289 
   289                 File commonParent = null;
   290             if (parent == null || !(file instanceof ShellFolder)) {
   290 
   291                 commonParent = null;
   291                 for (File file : files) {
   292 
   292                     File parent = file.getParentFile();
   293                 break;
   293 
   294             }
   294                     if (parent == null || !(file instanceof ShellFolder)) {
   295 
   295                         commonParent = null;
   296             if (commonParent == null) {
   296 
   297                 commonParent = parent;
   297                         break;
   298             } else {
   298                     }
   299                 if (commonParent != parent && !commonParent.equals(parent)) {
   299 
   300                     commonParent = null;
   300                     if (commonParent == null) {
   301 
   301                         commonParent = parent;
   302                     break;
   302                     } else {
   303                 }
   303                         if (commonParent != parent && !commonParent.equals(parent)) {
   304             }
   304                             commonParent = null;
   305         }
   305 
   306 
   306                             break;
   307         if (commonParent instanceof ShellFolder) {
   307                         }
   308             ((ShellFolder) commonParent).sortChildren(files);
   308                     }
   309         } else {
   309                 }
   310             Collections.sort(files, FILE_COMPARATOR);
   310 
   311         }
   311                 if (commonParent instanceof ShellFolder) {
   312     }
   312                     ((ShellFolder) commonParent).sortChildren(files);
   313 
   313                 } else {
   314     public void sortChildren(List<? extends File> files) {
   314                     Collections.sort(files, FILE_COMPARATOR);
   315         Collections.sort(files, FILE_COMPARATOR);
   315                 }
       
   316 
       
   317                 return null;
       
   318             }
       
   319         });
       
   320     }
       
   321 
       
   322     public void sortChildren(final List<? extends File> files) {
       
   323         // To avoid loads of synchronizations with Invoker and improve performance we
       
   324         // synchronize the whole code of the sort method once
       
   325         getInvoker().invoke(new Callable<Void>() {
       
   326             public Void call() throws Exception {
       
   327                 Collections.sort(files, FILE_COMPARATOR);
       
   328 
       
   329                 return null;
       
   330             }
       
   331         });
   316     }
   332     }
   317 
   333 
   318     public boolean isAbsolute() {
   334     public boolean isAbsolute() {
   319         return (!isFileSystem() || super.isAbsolute());
   335         return (!isFileSystem() || super.isAbsolute());
   320     }
   336     }