From 440734b4330b08cfad3ee1ee1cf75607ebc08d11 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Mon, 2 May 2016 14:27:24 +0200 Subject: ImageCollection : Store a FIle instead of the given String --- src/ch/epfl/xblast/client/ImageCollection.java | 34 +++++++++----------------- 1 file changed, 12 insertions(+), 22 deletions(-) (limited to 'src/ch/epfl') 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; public final class ImageCollection { /** - * Relative directory. + * Directory. */ - private final String directory; - - /** - * Get the directory Object from the relative directory Name using Java Resource. - * - * @param directoryName the relative name of the directory - * @throws NoSuchElementException - * @return the File Object related to the directory - */ - private static File getDirectory(String directoryName) { - try { // Ugly! Probably a better way... - return new File(ImageCollection.class - .getClassLoader() - .getResource(directoryName) - .toURI()); - } catch (java.net.URISyntaxException e) { - throw new NoSuchElementException(); - } - } + private final File directory; /** * Maps the directory's files with IDs parsed from their names. @@ -43,7 +25,7 @@ public final class ImageCollection { private Map mapFilesId() { HashMap mappedFiles = new HashMap<>(); - for (File file : this.getDirectory(this.directory).listFiles()) { + for (File file : this.directory.listFiles()) { mappedFiles.put(Integer.parseInt(file.getName()), file); } @@ -53,10 +35,18 @@ public final class ImageCollection { /** * Instantiates a new ImageCollection. * + * @throws NoSuchElementException * @param directory the relative directory name. */ public ImageCollection(String directory) { - this.directory = directory; + try { // Ugly! Probably a better way... + this.directory = new File(ImageCollection.class + .getClassLoader() + .getResource(directory) + .toURI()); + } catch (java.net.URISyntaxException e) { + throw new NoSuchElementException(); + } } /** -- cgit v1.2.3