Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AbstractFilmResultAnalyzer |
|
| 1.0;1 |
1 | package org.jtheque.films.services.impl.utils.web.analyzers; | |
2 | ||
3 | import org.jtheque.films.services.impl.utils.web.FilmResult; | |
4 | import org.jtheque.primary.utils.web.analyzers.generic.Analyzer; | |
5 | ||
6 | import java.util.ArrayList; | |
7 | import java.util.Collection; | |
8 | import java.util.Scanner; | |
9 | ||
10 | /* | |
11 | * This file is part of JTheque. | |
12 | * | |
13 | * JTheque is free software: you can redistribute it and/or modify | |
14 | * it under the terms of the GNU General Public License as published by | |
15 | * the Free Software Foundation, either version 3 of the License. | |
16 | * | |
17 | * JTheque is distributed in the hope that it will be useful, | |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | * GNU General Public License for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU General Public License | |
23 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
24 | */ | |
25 | ||
26 | /** | |
27 | * An abstract film result analyzer. | |
28 | * | |
29 | * @author Baptiste Wicht | |
30 | */ | |
31 | 0 | public abstract class AbstractFilmResultAnalyzer implements Analyzer { |
32 | private Scanner scanner; | |
33 | ||
34 | private boolean complete; | |
35 | ||
36 | 0 | private final Collection<FilmResult> results = new ArrayList<FilmResult>(10); |
37 | ||
38 | /** | |
39 | * Return all the results. | |
40 | * | |
41 | * @return The results of the research. | |
42 | */ | |
43 | public final Collection<FilmResult> getResults() { | |
44 | 0 | return results; |
45 | } | |
46 | ||
47 | /** | |
48 | * Set the scanner on which we read the website. | |
49 | * | |
50 | * @param scanner The scanner. | |
51 | */ | |
52 | public final void setScanner(Scanner scanner) { | |
53 | 0 | this.scanner = scanner; |
54 | 0 | } |
55 | ||
56 | /** | |
57 | * Analyze a line of the website and extract all the informations. | |
58 | * | |
59 | * @param line The line we must analyze. | |
60 | */ | |
61 | public final void analyzeLine(String line) { | |
62 | 0 | findFilms(line); |
63 | 0 | } |
64 | ||
65 | /** | |
66 | * Indicate if the we have all the informations. | |
67 | * | |
68 | * @return <code>true</code> if we have extracted all the informations else <code>false</code>. | |
69 | */ | |
70 | public final boolean isNotComplete() { | |
71 | 0 | return !complete; |
72 | } | |
73 | ||
74 | /** | |
75 | * Reset the analyzer. | |
76 | */ | |
77 | public final void reset() { | |
78 | 0 | complete = false; |
79 | ||
80 | 0 | results.clear(); |
81 | ||
82 | 0 | scanner.close(); |
83 | 0 | } |
84 | ||
85 | /** | |
86 | * Set the complete flag. | |
87 | * | |
88 | * @param complete true if the process is finish else false. | |
89 | */ | |
90 | final void setComplete(boolean complete) { | |
91 | 0 | this.complete = complete; |
92 | 0 | } |
93 | ||
94 | /** | |
95 | * Find films in the line. | |
96 | * | |
97 | * @param line The line to analyze. | |
98 | */ | |
99 | abstract void findFilms(String line); | |
100 | } |