-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add second level to generate files * extend File in IronFile
- Loading branch information
Showing
3 changed files
with
81 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
|
||
package main.java; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* This class extends the java File class and returns the filename for toString() | ||
*/ | ||
public class IronFile extends File { | ||
private boolean isRoot = true; | ||
|
||
public IronFile(String pathname) { | ||
super(pathname); | ||
isRoot = (getParent() == null); | ||
|
||
} | ||
public IronFile(File file) { | ||
super(file.getPath()); | ||
isRoot = (getParent() == null); | ||
} | ||
|
||
@Override | ||
public IronFile[] listFiles() { | ||
return convertFiles(super.listFiles()); | ||
} | ||
|
||
/** | ||
* Return the available hard drive disks. | ||
* */ | ||
public static IronFile[] listRoots() { | ||
return convertFiles(File.listRoots()); | ||
} | ||
|
||
public static IronFile[] convertFiles(File[] files) { | ||
IronFile[] ironFiles = new IronFile[files.length]; | ||
for (int i = 0; i < files.length; i++) { | ||
ironFiles[i] = new IronFile(files[i]); | ||
} | ||
return ironFiles; | ||
} | ||
|
||
public boolean isRoot() { | ||
return isRoot; | ||
} | ||
|
||
public void setRoot(boolean root) { | ||
isRoot = root; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
if (isRoot) { | ||
return this.getAbsolutePath(); | ||
} else { | ||
return this.getName(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters