From b5b09a7130b9f7e50c540ab99e298a676ecfbe29 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Sun, 8 May 2016 14:12:39 +0200 Subject: Fix bug in ImageCollection (now able to fetch an image ID from its filename) --- src/ch/epfl/xblast/client/ImageCollection.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src') 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; * @author Timothée FLOURE (257420) */ public final class ImageCollection { + /** + * Bounds of the file ID in the filename. + */ + private final int FILENAME_ID_BEGIN_INDEX = 0; + private final int FILENAME_ID_END_INDEX = 2; /** - * Directory. + * Directory related to the ImageCollection. */ private final File directory; @@ -26,7 +31,7 @@ public final class ImageCollection { HashMap mappedFiles = new HashMap<>(); for (File file : this.directory.listFiles()) { - mappedFiles.put(Integer.parseInt(file.getName()), file); + mappedFiles.put(Integer.parseInt(file.getName().substring(FILENAME_ID_BEGIN_INDEX,FILENAME_ID_END_INDEX)), file); } return mappedFiles; @@ -35,8 +40,8 @@ public final class ImageCollection { /** * Instantiates a new ImageCollection. * - * @throws NoSuchElementException - * @param directory the relative directory name. + * @throws NoSuchElementException if the requested directory is not valid + * @param directory the relative directory name */ public ImageCollection(String directory) { try { // Ugly! Probably a better way... @@ -44,7 +49,7 @@ public final class ImageCollection { .getClassLoader() .getResource(directory) .toURI()); - } catch (java.net.URISyntaxException e) { + } catch (Exception e) { throw new NoSuchElementException(); } } -- cgit v1.2.3