1 | // Jomic - a viewer for comic book archives. |
2 | // Copyright (C) 2004-2011 Thomas Aglassinger |
3 | // |
4 | // This program is free software: you can redistribute it and/or modify |
5 | // it under the terms of the GNU General Public License as published by |
6 | // the Free Software Foundation, either version 3 of the License, or |
7 | // (at your option) any later version. |
8 | // |
9 | // This program is distributed in the hope that it will be useful, |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | // GNU General Public License for more details. |
13 | // |
14 | // You should have received a copy of the GNU General Public License |
15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | package net.sf.jomic.comic; |
17 | |
18 | import java.io.File; |
19 | |
20 | import net.sf.jomic.tools.FileTools; |
21 | |
22 | /** |
23 | * Specifies source, target and size of a comic to be converted. |
24 | * |
25 | * @author Thomas Aglassinger |
26 | */ |
27 | public class ComicToConvert implements Comparable |
28 | { |
29 | private long fileSize; |
30 | private File sourceComicFile; |
31 | private File targetComicFile; |
32 | |
33 | /** |
34 | * Create a new comic to be converted from source directory <code>sourceDir</code> to the |
35 | * target directory <code>targetDir</code> with the comic file being located in <code>relativeComicPath</code> |
36 | * relative to these directories. |
37 | * |
38 | * @param sourceDir the directory relative to which the original comic is located |
39 | * @param targetDir the target dir relative to which the converted comic should end up |
40 | * @param relativeComicPath the relative path of the comic in sourceDir and targetDir |
41 | * @param targetSuffix the new suffix of the target comic ("cbz" or "pdf") |
42 | */ |
43 | public ComicToConvert(File sourceDir, File targetDir, String relativeComicPath, String targetSuffix) { |
44 | assert sourceDir != null; |
45 | assert targetDir != null; |
46 | assert relativeComicPath != null; |
47 | assert targetSuffix != null; |
48 | FileTools fileTools = FileTools.instance(); |
49 | String relativeTargetPath = fileTools.getWithoutLastSuffix(relativeComicPath) + "." + targetSuffix; |
50 | |
51 | sourceComicFile = new File(sourceDir, relativeComicPath); |
52 | targetComicFile = new File(targetDir, relativeTargetPath); |
53 | fileSize = sourceComicFile.length(); |
54 | } |
55 | |
56 | public long getFileSize() { |
57 | return fileSize; |
58 | } |
59 | |
60 | public File getSourceComicFile() { |
61 | return sourceComicFile; |
62 | } |
63 | |
64 | public File getTargetComicFile() { |
65 | return targetComicFile; |
66 | } |
67 | |
68 | public int compareTo(Object other) { |
69 | int result; |
70 | |
71 | if ((other == null) || !(other instanceof ComicToConvert)) { |
72 | result = 1; |
73 | } else { |
74 | ComicToConvert otherComic = (ComicToConvert) other; |
75 | |
76 | result = getTargetComicFile().compareTo(otherComic.getTargetComicFile()); |
77 | } |
78 | return result; |
79 | } |
80 | |
81 | /** |
82 | * Does <code>other</code> result in the same target comic? |
83 | */ |
84 | public boolean equals(Object other) { |
85 | boolean result; |
86 | |
87 | if ((other == null) || !(other instanceof ComicToConvert)) { |
88 | result = super.equals(other); |
89 | } else { |
90 | ComicToConvert otherComic = (ComicToConvert) other; |
91 | |
92 | result = getTargetComicFile().equals(otherComic.getTargetComicFile()); |
93 | } |
94 | return result; |
95 | } |
96 | |
97 | public int hashCode() { |
98 | int result; |
99 | File file = getTargetComicFile(); |
100 | |
101 | if (file == null) { |
102 | result = 0; |
103 | } else { |
104 | result = file.hashCode(); |
105 | } |
106 | return result; |
107 | } |
108 | } |