1111import java .util .List ;
1212
1313/**
14+ * This class is used to load all the files in the given package as to the given extension.
15+ *
1416 * @author oshan
17+ * @version 1.0
1518 */
1619public class FileLoader {
1720
1821 private SceneManager manager ;
1922
2023 private String dir ="" , ext ;
2124
25+ /**
26+ * <p>
27+ * IMPORTANT : <b>
28+ * This DOES NOT GUARANTEE to be executed the way expected and should be avoided unless in testing.
29+ * Use another constructor instead.
30+ * </b>
31+ * Calling this constructor will create a FileLoader object which can load the type of files of the given extension (ext)
32+ * from the same package of the class the constructor was called.
33+ * Ex : If the constructor was called from "Foo.class", this will create a FileLoader which is able to load the specific
34+ * files from the same directory "Foo.class" file is located.
35+ * </p>
36+ *
37+ * <p>
38+ * <b>NOTE :</b> This constructor is specifically created to be used with SceneManager. If used separately, this will not
39+ * work properly and will be unable to load the files. (Since this uses getStackTrace()[3] argument and if called directly,
40+ * it should probably be changed to getStackTrace()[1]).
41+ * </p>
42+ *
43+ * @param ext extension of the type of files needed to be loaded
44+ */
2245 public FileLoader (String ext ) {
2346 this .ext = ext ;
2447 try {
@@ -31,11 +54,30 @@ public FileLoader(String ext) {
3154
3255 }
3356
57+ /**
58+ * <p>
59+ * This is same as {@link #FileLoader(String ext)}. The only difference is that this constructor will initialize the
60+ * SceneManager property which can be used later (through the given SceneManager object)
61+ *</p>
62+ *
63+ * @param ext extension of the type of files needed to be loaded
64+ * @param manager SceneManager object which is going to access this FileLoader object
65+ */
3466 public FileLoader (String ext , SceneManager manager ){
3567 this (ext );
3668 this .manager =manager ;
3769 }
3870
71+ /**
72+ * <p>
73+ * This is used to make the FileLoader eligible to load the given type of files from the directory of the URL provides.
74+ * Ex : {@code new FileLoader(getClass().getResource("/path/to/file/myfile.fxml")),"fxml")}
75+ * Will make the FileLoader eligible to load file with ".fxml" extension from the "/path/to/file" directory.
76+ * </p>
77+ *
78+ * @param url URL of a class to determine the package which needs to be lookup for files to load
79+ * @param ext extension of the type of files needed to be loaded
80+ */
3981 public FileLoader (URL url , String ext ){
4082 String [] content = url .toString ().replace ("file:/" ,"" ).replace ("%20" ," " ).split ("/" );
4183
@@ -49,21 +91,51 @@ public FileLoader(URL url, String ext){
4991 this .ext = ext ;
5092 }
5193
94+ /**
95+ * <p>
96+ * This is same as {@link #FileLoader(URL, String)}. The only difference is that this constructor will initialize the
97+ * SceneManager property which can be used later (through the given SceneManager object)
98+ * </p>
99+ *
100+ * @param url URL of a class to determine the package which needs to be lookup for files to load
101+ * @param ext extension of the type of files needed to be loaded
102+ * @param manager SceneManager object which is going to access this FileLoader object
103+ */
52104 public FileLoader (URL url , String ext , SceneManager manager ){
53105 this (url , ext );
54106 this .manager = manager ;
55107 }
56108
109+ /**
110+ * <p>
111+ * This is used to make the FileLoader eligible to load the given type of files from the directory given in String format.
112+ * </p>
113+ *
114+ * @param dir directory path
115+ * @param ext extension of the type of files needed to be loaded
116+ */
57117 public FileLoader (String dir , String ext ) {
58118 this .dir =dir ;
59119 this .ext =ext ;
60120 }
61121
122+ /**
123+ * See {@link #FileLoader(String, String, SceneManager)}
124+ *
125+ * @param dir directory path
126+ * @param ext extension of the type of files needed to be loaded
127+ * @param manager SceneManager object which is going to access this FileLoader object
128+ */
62129 public FileLoader (String dir , String ext , SceneManager manager ){
63130 this (dir , ext );
64131 this .manager =manager ;
65132 }
66133
134+ /**
135+ * Collects the set of files with the given extension and inside the given directory for the FileLoader.
136+ *
137+ * @return the loaded available files.
138+ */
67139 public List <File > collect (){
68140
69141 List <File > files = new ArrayList <>();
0 commit comments