diff options
author | Timothée Floure | 2016-05-08 14:12:39 +0200 |
---|---|---|
committer | Timothée Floure | 2016-05-08 14:12:39 +0200 |
commit | b5b09a7130b9f7e50c540ab99e298a676ecfbe29 (patch) | |
tree | 0819eb890bf4d9274c82d8e0df70dac1d9a035cb | |
parent | 4c7d7b9d422b043503a70c23e48bd39883c8ee20 (diff) | |
download | xblast-b5b09a7130b9f7e50c540ab99e298a676ecfbe29.tar.gz |
Fix bug in ImageCollection (now able to fetch an image ID from its filename)
-rw-r--r-- | src/ch/epfl/xblast/client/ImageCollection.java | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/ch/epfl/xblast/client/ImageCollection.java b/src/ch/epfl/xblast/client/ImageCollection.java index 1efe5e1..4f54f3b 100644 --- a/src/ch/epfl/xblast/client/ImageCollection.java +++ b/src/ch/epfl/xblast/client/ImageCollection.java | |||
@@ -11,9 +11,14 @@ import java.util.NoSuchElementException; | |||
11 | * @author Timothée FLOURE (257420) | 11 | * @author Timothée FLOURE (257420) |
12 | */ | 12 | */ |
13 | public final class ImageCollection { | 13 | public final class ImageCollection { |
14 | /** | ||
15 | * Bounds of the file ID in the filename. | ||
16 | */ | ||
17 | private final int FILENAME_ID_BEGIN_INDEX = 0; | ||
18 | private final int FILENAME_ID_END_INDEX = 2; | ||
14 | 19 | ||
15 | /** | 20 | /** |
16 | * Directory. | 21 | * Directory related to the ImageCollection. |
17 | */ | 22 | */ |
18 | private final File directory; | 23 | private final File directory; |
19 | 24 | ||
@@ -26,7 +31,7 @@ public final class ImageCollection { | |||
26 | HashMap<Integer, File> mappedFiles = new HashMap<>(); | 31 | HashMap<Integer, File> mappedFiles = new HashMap<>(); |
27 | 32 | ||
28 | for (File file : this.directory.listFiles()) { | 33 | for (File file : this.directory.listFiles()) { |
29 | mappedFiles.put(Integer.parseInt(file.getName()), file); | 34 | mappedFiles.put(Integer.parseInt(file.getName().substring(FILENAME_ID_BEGIN_INDEX,FILENAME_ID_END_INDEX)), file); |
30 | } | 35 | } |
31 | 36 | ||
32 | return mappedFiles; | 37 | return mappedFiles; |
@@ -35,8 +40,8 @@ public final class ImageCollection { | |||
35 | /** | 40 | /** |
36 | * Instantiates a new ImageCollection. | 41 | * Instantiates a new ImageCollection. |
37 | * | 42 | * |
38 | * @throws NoSuchElementException | 43 | * @throws NoSuchElementException if the requested directory is not valid |
39 | * @param directory the relative directory name. | 44 | * @param directory the relative directory name |
40 | */ | 45 | */ |
41 | public ImageCollection(String directory) { | 46 | public ImageCollection(String directory) { |
42 | try { // Ugly! Probably a better way... | 47 | try { // Ugly! Probably a better way... |
@@ -44,7 +49,7 @@ public final class ImageCollection { | |||
44 | .getClassLoader() | 49 | .getClassLoader() |
45 | .getResource(directory) | 50 | .getResource(directory) |
46 | .toURI()); | 51 | .toURI()); |
47 | } catch (java.net.URISyntaxException e) { | 52 | } catch (Exception e) { |
48 | throw new NoSuchElementException(); | 53 | throw new NoSuchElementException(); |
49 | } | 54 | } |
50 | } | 55 | } |