- private SquarePair<BufferedImage> loadSquares(String name, File boardPath) throws ImageException {
- BufferedImage dark = null, light = null;
- File[] images = boardPath.listFiles(new ImageFilter(SQUARE_NAMES));
- if (images != null) {
- for (File image : images) {
- if (image.isFile()) {
- String filename = image.getName();
- try {
- switch (filename.substring(0, filename.lastIndexOf('.'))) {
- case SQUARE_DARK:
- dark = ImageIO.read(image);
- break;
- case SQUARE_LIGHT:
- light = ImageIO.read(image);
- break;
- }
- } catch (IOException e) {
- throw new ImageException(e.getMessage()); // todo: locale
- }
- }
- }
- }
- return (dark != null && light != null) ? SquarePair.create(dark, light) : null;
+ private SquarePair<BufferedImage> loadSquares(String boardPath) throws ImageException {
+ Map<String, BufferedImage> images =
+ loadImages(
+ boardPath,
+ new ImageFilter(SQUARE_NAMES)
+ );
+ BufferedImage dark = images.get(SQUARE_DARK);
+ BufferedImage light = images.get(SQUARE_LIGHT);
+ return (dark != null && light != null)
+ ? SquarePair.create(dark, light)
+ : null; // todo: ImageException