diff options
Diffstat (limited to 'src/ch/epfl')
-rw-r--r-- | src/ch/epfl/xblast/client/ImageCollection.java | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/src/ch/epfl/xblast/client/ImageCollection.java b/src/ch/epfl/xblast/client/ImageCollection.java index 231d84c..1efe5e1 100644 --- a/src/ch/epfl/xblast/client/ImageCollection.java +++ b/src/ch/epfl/xblast/client/ImageCollection.java | |||
@@ -13,27 +13,9 @@ import java.util.NoSuchElementException; | |||
13 | public final class ImageCollection { | 13 | public final class ImageCollection { |
14 | 14 | ||
15 | /** | 15 | /** |
16 | * Relative directory. | 16 | * Directory. |
17 | */ | 17 | */ |
18 | private final String directory; | 18 | private final File directory; |
19 | |||
20 | /** | ||
21 | * Get the directory Object from the relative directory Name using Java Resource. | ||
22 | * | ||
23 | * @param directoryName the relative name of the directory | ||
24 | * @throws NoSuchElementException | ||
25 | * @return the File Object related to the directory | ||
26 | */ | ||
27 | private static File getDirectory(String directoryName) { | ||
28 | try { // Ugly! Probably a better way... | ||
29 | return new File(ImageCollection.class | ||
30 | .getClassLoader() | ||
31 | .getResource(directoryName) | ||
32 | .toURI()); | ||
33 | } catch (java.net.URISyntaxException e) { | ||
34 | throw new NoSuchElementException(); | ||
35 | } | ||
36 | } | ||
37 | 19 | ||
38 | /** | 20 | /** |
39 | * Maps the directory's files with IDs parsed from their names. | 21 | * Maps the directory's files with IDs parsed from their names. |
@@ -43,7 +25,7 @@ public final class ImageCollection { | |||
43 | private Map<Integer, File> mapFilesId() { | 25 | private Map<Integer, File> mapFilesId() { |
44 | HashMap<Integer, File> mappedFiles = new HashMap<>(); | 26 | HashMap<Integer, File> mappedFiles = new HashMap<>(); |
45 | 27 | ||
46 | for (File file : this.getDirectory(this.directory).listFiles()) { | 28 | for (File file : this.directory.listFiles()) { |
47 | mappedFiles.put(Integer.parseInt(file.getName()), file); | 29 | mappedFiles.put(Integer.parseInt(file.getName()), file); |
48 | } | 30 | } |
49 | 31 | ||
@@ -53,10 +35,18 @@ public final class ImageCollection { | |||
53 | /** | 35 | /** |
54 | * Instantiates a new ImageCollection. | 36 | * Instantiates a new ImageCollection. |
55 | * | 37 | * |
38 | * @throws NoSuchElementException | ||
56 | * @param directory the relative directory name. | 39 | * @param directory the relative directory name. |
57 | */ | 40 | */ |
58 | public ImageCollection(String directory) { | 41 | public ImageCollection(String directory) { |
59 | this.directory = directory; | 42 | try { // Ugly! Probably a better way... |
43 | this.directory = new File(ImageCollection.class | ||
44 | .getClassLoader() | ||
45 | .getResource(directory) | ||
46 | .toURI()); | ||
47 | } catch (java.net.URISyntaxException e) { | ||
48 | throw new NoSuchElementException(); | ||
49 | } | ||
60 | } | 50 | } |
61 | 51 | ||
62 | /** | 52 | /** |