aboutsummaryrefslogtreecommitdiff
path: root/src/ch
diff options
context:
space:
mode:
authorTimothée Floure2016-05-02 14:27:24 +0200
committerTimothée Floure2016-05-02 14:27:24 +0200
commit440734b4330b08cfad3ee1ee1cf75607ebc08d11 (patch)
tree73f4a1db5a40b3422ed6abd95587441be9d15895 /src/ch
parent0769993db09bbcfe328d3611405151cfb09357e8 (diff)
downloadxblast-440734b4330b08cfad3ee1ee1cf75607ebc08d11.tar.gz
ImageCollection : Store a FIle instead of the given String
Diffstat (limited to 'src/ch')
-rw-r--r--src/ch/epfl/xblast/client/ImageCollection.java34
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;
13public final class ImageCollection { 13public 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 /**