java/copy-image-resizer/src/cz/frantovo/copyImageResizer/RecursiveOptions.java
author František Kučera <franta-hg@frantovo.cz>
Mon, 17 Nov 2014 20:05:57 +0100
changeset 12 27e41d7f5e8d
parent 7 8e9983260624
child 14 dec0dd934a64
permissions -rw-r--r--
counters, logging
franta-hg@3
     1
/**
franta-hg@3
     2
 * copy-image-resizer
franta-hg@3
     3
 * Copyright © 2014 František Kučera (frantovo.cz)
franta-hg@3
     4
 *
franta-hg@3
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@3
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@3
     7
 * the Free Software Foundation, either version 3 of the License, or
franta-hg@3
     8
 * (at your option) any later version.
franta-hg@3
     9
 *
franta-hg@3
    10
 * This program is distributed in the hope that it will be useful,
franta-hg@3
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@3
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@3
    13
 * GNU General Public License for more details.
franta-hg@3
    14
 *
franta-hg@3
    15
 * You should have received a copy of the GNU General Public License
franta-hg@3
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@3
    17
 */
franta-hg@5
    18
package cz.frantovo.copyImageResizer;
franta-hg@3
    19
franta-hg@3
    20
import java.io.File;
franta-hg@3
    21
import java.util.ArrayList;
franta-hg@3
    22
import java.util.Collection;
franta-hg@3
    23
franta-hg@3
    24
/**
franta-hg@6
    25
 *
franta-hg@3
    26
 * @author Ing. František Kučera (frantovo.cz)
franta-hg@3
    27
 */
franta-hg@5
    28
public class RecursiveOptions {
franta-hg@3
    29
franta-hg@3
    30
	/**
franta-hg@3
    31
	 * Source directory
franta-hg@3
    32
	 */
franta-hg@3
    33
	private File input;
franta-hg@3
    34
	/**
franta-hg@3
    35
	 * Output directory
franta-hg@3
    36
	 */
franta-hg@3
    37
	private File output;
franta-hg@3
    38
	/**
franta-hg@3
    39
	 * Image resolutions to create
franta-hg@3
    40
	 */
franta-hg@3
    41
	private final Collection<SizeSpecification> sizes = new ArrayList<>();
franta-hg@3
    42
franta-hg@6
    43
	public File getInput() {
franta-hg@3
    44
		return input;
franta-hg@3
    45
	}
franta-hg@3
    46
franta-hg@3
    47
	public void setInput(File input) {
franta-hg@3
    48
		this.input = input;
franta-hg@3
    49
	}
franta-hg@3
    50
franta-hg@6
    51
	public File getOutput() {
franta-hg@3
    52
		return output;
franta-hg@3
    53
	}
franta-hg@3
    54
franta-hg@3
    55
	public void setOutput(File output) {
franta-hg@3
    56
		this.output = output;
franta-hg@3
    57
	}
franta-hg@3
    58
franta-hg@3
    59
	public Collection<SizeSpecification> getSizes() {
franta-hg@3
    60
		return sizes;
franta-hg@3
    61
	}
franta-hg@3
    62
franta-hg@3
    63
	public void addSize(SizeSpecification size) {
franta-hg@3
    64
		sizes.add(size);
franta-hg@3
    65
	}
franta-hg@12
    66
franta-hg@12
    67
	public void validate() throws InvalidOptionsException {
franta-hg@12
    68
		InvalidOptionsException e = new InvalidOptionsException();
franta-hg@12
    69
franta-hg@12
    70
		if (input == null) {
franta-hg@12
    71
			e.addProblem(new InvalidOptionsException.OptionProblem("input directory must be specified"));
franta-hg@12
    72
		} else if (!input.isDirectory()) {
franta-hg@12
    73
			e.addProblem(new InvalidOptionsException.OptionProblem("input directory must exist and be a directory: " + input));
franta-hg@12
    74
		}
franta-hg@12
    75
franta-hg@12
    76
		if (output == null) {
franta-hg@12
    77
			e.addProblem(new InvalidOptionsException.OptionProblem("output directory must be specified"));
franta-hg@12
    78
		}
franta-hg@12
    79
franta-hg@12
    80
		if (sizes.isEmpty()) {
franta-hg@12
    81
			e.addProblem(new InvalidOptionsException.OptionProblem("at least one size (output resolution) must be specified"));
franta-hg@12
    82
		}
franta-hg@12
    83
franta-hg@12
    84
		if (e.hasProblems()) {
franta-hg@12
    85
			throw e;
franta-hg@12
    86
		}
franta-hg@12
    87
	}
franta-hg@3
    88
}