< prev index next >

src/share/classes/javax/swing/filechooser/FileSystemView.java

Print this page
rev 1527 : 6727662: Code improvement and warnings removing from swing packages
Summary: Removed unnecessary castings and other warnings
Reviewed-by: malenkov

@@ -129,12 +129,12 @@
         if (f == null || !f.isAbsolute()) {
             return false;
         }
 
         File[] roots = getRoots();
-        for (int i = 0; i < roots.length; i++) {
-            if (roots[i].equals(f)) {
+        for (File root : roots) {
+            if (root.equals(f)) {
                 return true;
             }
         }
         return false;
     }

@@ -245,12 +245,12 @@
                 File parent = file.getParentFile();
                 if (parent != null && parent.equals(folder)) {
                     return true;
                 }
             File[] children = getFiles(folder, false);
-            for (int i = 0; i < children.length; i++) {
-                if (file.equals(children[i])) {
+            for (File child : children) {
+                if (file.equals(child)) {
                     return true;
                 }
             }
             return false;
         } else {

@@ -269,13 +269,13 @@
      * @since 1.4
      */
     public File getChild(File parent, String fileName) {
         if (parent instanceof ShellFolder) {
             File[] children = getFiles(parent, false);
-            for (int i = 0; i < children.length; i++) {
-                if (children[i].getName().equals(fileName)) {
-                    return children[i];
+            for (File child : children) {
+                if (child.getName().equals(fileName)) {
+                    return child;
                 }
             }
         }
         return createFileObject(parent, fileName);
     }

@@ -437,11 +437,11 @@
 
     /**
      * Gets the list of shown (i.e. not hidden) files.
      */
     public File[] getFiles(File dir, boolean useFileHiding) {
-        Vector files = new Vector();
+        Vector<File> files = new Vector<File>();
 
 
         // add all files in dir
         File[] names;
             if (!(dir instanceof ShellFolder)) {

@@ -476,11 +476,11 @@
             if (!useFileHiding || !isHiddenFile(f)) {
                 files.addElement(f);
             }
         }
 
-        return (File[])files.toArray(new File[files.size()]);
+        return files.toArray(new File[files.size()]);
     }
 
 
 
     /**

@@ -583,11 +583,11 @@
      */
     public File createNewFolder(File containingDir) throws IOException {
         if(containingDir == null) {
             throw new IOException("Containing directory is null:");
         }
-        File newFolder = null;
+        File newFolder;
         // Unix - using OpenWindows' default folder name. Can't find one for Motif/CDE.
         newFolder = createFileObject(containingDir, newFolderString);
         int i = 1;
         while (newFolder.exists() && (i < 100)) {
             newFolder = createFileObject(containingDir, MessageFormat.format(

@@ -607,15 +607,11 @@
     public boolean isFileSystemRoot(File dir) {
         return (dir != null && dir.getAbsolutePath().equals("/"));
     }
 
     public boolean isDrive(File dir) {
-        if (isFloppyDrive(dir)) {
-            return true;
-        } else {
-            return false;
-        }
+        return isFloppyDrive(dir);
     }
 
     public boolean isFloppyDrive(File dir) {
         // Could be looking at the path for Solaris, but wouldn't be reliable.
         // For example:

@@ -694,13 +690,12 @@
      */
     public File createNewFolder(File containingDir) throws IOException {
         if(containingDir == null) {
             throw new IOException("Containing directory is null:");
         }
-        File newFolder = null;
         // Using NT's default folder name
-        newFolder = createFileObject(containingDir, newFolderString);
+        File newFolder = createFileObject(containingDir, newFolderString);
         int i = 2;
         while (newFolder.exists() && (i < 100)) {
             newFolder = createFileObject(containingDir, MessageFormat.format(
                 newFolderNextString, new Object[] { new Integer(i) }));
             i++;

@@ -764,13 +759,12 @@
      */
     public File createNewFolder(File containingDir) throws IOException {
         if(containingDir == null) {
             throw new IOException("Containing directory is null:");
         }
-        File newFolder = null;
         // Using NT's default folder name
-        newFolder = createFileObject(containingDir, newFolderString);
+        File newFolder = createFileObject(containingDir, newFolderString);
 
         if(newFolder.exists()) {
             throw new IOException("Directory already exists:" + newFolder.getAbsolutePath());
         } else {
             newFolder.mkdirs();
< prev index next >