Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AbstractFilmAnalyzer |
|
| 1.2142857142857142;1.214 |
1 | package org.jtheque.films.services.impl.utils.web.analyzers; | |
2 | ||
3 | /* | |
4 | * This file is part of JTheque. | |
5 | * | |
6 | * JTheque is free software: you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation, either version 3 of the License. | |
9 | * | |
10 | * JTheque is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | import org.jtheque.films.persistence.od.able.Film; | |
20 | import org.jtheque.films.services.impl.utils.EditArguments; | |
21 | import org.jtheque.primary.utils.web.analyzers.generic.Analyzer; | |
22 | ||
23 | import java.util.Scanner; | |
24 | ||
25 | /** | |
26 | * A film analyser. It analyze a line of the website to get the informations on it. | |
27 | * | |
28 | * @author Baptiste Wicht | |
29 | */ | |
30 | 0 | public abstract class AbstractFilmAnalyzer implements Analyzer { |
31 | private Film film; | |
32 | private Scanner scanner; | |
33 | ||
34 | private boolean resume; | |
35 | private boolean image; | |
36 | private boolean date; | |
37 | private boolean genre; | |
38 | private boolean duration; | |
39 | private boolean realizer; | |
40 | private boolean actors; | |
41 | ||
42 | /** | |
43 | * Return the film on which we work. | |
44 | * | |
45 | * @return The film | |
46 | */ | |
47 | final Film getFilm() { | |
48 | 0 | return film; |
49 | } | |
50 | ||
51 | /** | |
52 | * Set the film on which we work. | |
53 | * | |
54 | * @param film The film | |
55 | */ | |
56 | public final void setFilm(Film film) { | |
57 | 0 | this.film = film; |
58 | 0 | } |
59 | ||
60 | /** | |
61 | * Set the scanner on which we read the website. | |
62 | * | |
63 | * @param scanner The scanner. | |
64 | */ | |
65 | public final void setScanner(Scanner scanner) { | |
66 | 0 | this.scanner = scanner; |
67 | 0 | } |
68 | ||
69 | /** | |
70 | * Analyze a line of the website and extract all the informations. | |
71 | * | |
72 | * @param line The line we must analyze. | |
73 | */ | |
74 | public final void analyzeLine(String line) { | |
75 | 0 | findResume(line); |
76 | 0 | findImage(line); |
77 | 0 | findDate(line); |
78 | 0 | findKind(line); |
79 | 0 | findDuration(line); |
80 | 0 | findRealizer(line); |
81 | 0 | findActors(line); |
82 | 0 | } |
83 | ||
84 | /** | |
85 | * Indicate if the we have all the informations. | |
86 | * | |
87 | * @return <code>true</code> if we have extracted all the informations else <code>false</code>. | |
88 | */ | |
89 | public final boolean isNotComplete() { | |
90 | 0 | return !resume || |
91 | !image || | |
92 | !date || | |
93 | !genre || | |
94 | !duration || | |
95 | !realizer || | |
96 | !actors; | |
97 | } | |
98 | ||
99 | /** | |
100 | * Reset the analyzer. | |
101 | */ | |
102 | public final void reset() { | |
103 | 0 | resume = false; |
104 | 0 | image = false; |
105 | 0 | date = false; |
106 | 0 | genre = false; |
107 | 0 | duration = false; |
108 | 0 | realizer = false; |
109 | 0 | actors = false; |
110 | ||
111 | 0 | scanner.close(); |
112 | 0 | } |
113 | ||
114 | /** | |
115 | * Find the resume on the line. | |
116 | * | |
117 | * @param line The line on which we search. | |
118 | */ | |
119 | protected abstract void findResume(String line); | |
120 | ||
121 | /** | |
122 | * Find the image of the film on the line. | |
123 | * | |
124 | * @param line The line on which we search. | |
125 | */ | |
126 | protected abstract void findImage(String line); | |
127 | ||
128 | /** | |
129 | * Find the date on the line. | |
130 | * | |
131 | * @param line The line on which we search. | |
132 | */ | |
133 | protected abstract void findDate(String line); | |
134 | ||
135 | /** | |
136 | * Find the kind on the line. | |
137 | * | |
138 | * @param line The line on which we search. | |
139 | */ | |
140 | protected abstract void findKind(String line); | |
141 | ||
142 | /** | |
143 | * Find the duration on the line. | |
144 | * | |
145 | * @param line The line on which we search. | |
146 | */ | |
147 | protected abstract void findDuration(String line); | |
148 | ||
149 | /** | |
150 | * Find the realizer on the line. | |
151 | * | |
152 | * @param line The line on which we search. | |
153 | */ | |
154 | protected abstract void findRealizer(String line); | |
155 | ||
156 | /** | |
157 | * Find the actors of the film on the line. | |
158 | * | |
159 | * @param line The line on which we search. | |
160 | */ | |
161 | protected abstract void findActors(String line); | |
162 | ||
163 | /** | |
164 | * Set the state of the resume get. | |
165 | * | |
166 | * @param resume A boolean value indicate the state of the resume get. | |
167 | */ | |
168 | final void setResume(boolean resume) { | |
169 | 0 | this.resume = resume; |
170 | 0 | } |
171 | ||
172 | /** | |
173 | * Indicate if the resume is done or not. | |
174 | * | |
175 | * @return <code>true</code> if we have found the resume else <code>false</code>. | |
176 | */ | |
177 | final boolean isResumeDo() { | |
178 | 0 | return resume; |
179 | } | |
180 | ||
181 | /** | |
182 | * Set the state of the image get. | |
183 | * | |
184 | * @param image A boolean value indicate the state of the image get. | |
185 | */ | |
186 | final void setImage(boolean image) { | |
187 | 0 | this.image = image; |
188 | 0 | } |
189 | ||
190 | /** | |
191 | * Indicate if the image is done or not. | |
192 | * | |
193 | * @return <code>true</code> if we have found the image else <code>false</code>. | |
194 | */ | |
195 | final boolean isImageDo() { | |
196 | 0 | return image; |
197 | } | |
198 | ||
199 | /** | |
200 | * Set the state of the date get. | |
201 | * | |
202 | * @param date A boolean value indicate the state of the date get. | |
203 | */ | |
204 | final void setDate(boolean date) { | |
205 | 0 | this.date = date; |
206 | 0 | } |
207 | ||
208 | /** | |
209 | * Indicate if the date is done or not. | |
210 | * | |
211 | * @return <code>true</code> if we have found the date else <code>false</code>. | |
212 | */ | |
213 | final boolean isDateDo() { | |
214 | 0 | return date; |
215 | } | |
216 | ||
217 | /** | |
218 | * Set the state of the kind get. | |
219 | * | |
220 | * @param genre A boolean value indicate the state of the kind get. | |
221 | */ | |
222 | final void setKind(boolean genre) { | |
223 | 0 | this.genre = genre; |
224 | 0 | } |
225 | ||
226 | /** | |
227 | * Indicate if the kind is done or not. | |
228 | * | |
229 | * @return <code>true</code> if we have found the kind else <code>false</code>. | |
230 | */ | |
231 | final boolean isKindDo() { | |
232 | 0 | return genre; |
233 | } | |
234 | ||
235 | /** | |
236 | * Set the state of the duration get. | |
237 | * | |
238 | * @param duration A boolean value indicate the state of the duration get. | |
239 | */ | |
240 | final void setDuration(boolean duration) { | |
241 | 0 | this.duration = duration; |
242 | 0 | } |
243 | ||
244 | /** | |
245 | * Indicate if the duration is done or not. | |
246 | * | |
247 | * @return <code>true</code> if we have found the duration else <code>false</code>. | |
248 | */ | |
249 | final boolean isDurationDo() { | |
250 | 0 | return duration; |
251 | } | |
252 | ||
253 | /** | |
254 | * Set the realizer of the resume get. | |
255 | * | |
256 | * @param realizer A boolean value indicate the state of the realizer get. | |
257 | */ | |
258 | final void setRealizer(boolean realizer) { | |
259 | 0 | this.realizer = realizer; |
260 | 0 | } |
261 | ||
262 | /** | |
263 | * Indicate if the realizer is done or not. | |
264 | * | |
265 | * @return <code>true</code> if we have found the realizer else <code>false</code>. | |
266 | */ | |
267 | final boolean isRealizerDo() { | |
268 | 0 | return realizer; |
269 | } | |
270 | ||
271 | /** | |
272 | * Set the state of the actors get. | |
273 | * | |
274 | * @param actors A boolean value indicate the state of the actors get. | |
275 | */ | |
276 | public final void setActors(boolean actors) { | |
277 | 0 | this.actors = actors; |
278 | 0 | } |
279 | ||
280 | /** | |
281 | * Indicate if the actors is done or not. | |
282 | * | |
283 | * @return <code>true</code> if we have found the actors else <code>false</code>. | |
284 | */ | |
285 | final boolean isActorsDo() { | |
286 | 0 | return actors; |
287 | } | |
288 | ||
289 | /** | |
290 | * Configure the scanner with the arguments of the edit. When we doesn't edit something we pass the state to | |
291 | * <code>true</code> to indicate that we mustn't edit this field. | |
292 | * | |
293 | * @param args The arguments of the edit | |
294 | */ | |
295 | public final void configureWithEditArgs(EditArguments args) { | |
296 | 0 | actors = !args.isEditActors(); |
297 | 0 | date = !args.isEditYear(); |
298 | 0 | duration = !args.isEditDuration(); |
299 | 0 | image = !args.isEditImage(); |
300 | 0 | genre = !args.isEditKind(); |
301 | 0 | realizer = !args.isEditRealizer(); |
302 | 0 | resume = !args.isEditResume(); |
303 | 0 | } |
304 | } |