Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ContainFactory |
|
| 1.0;1 | ||||
ContainFactory$1 |
|
| 1.0;1 | ||||
ContainFactory$Contain |
|
| 1.0;1 |
1 | package org.jtheque.primary.utils.web.analyzers.generic.condition; | |
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.jdom.Element; | |
20 | import org.jtheque.core.utils.file.XMLException; | |
21 | import org.jtheque.core.utils.file.XMLReader; | |
22 | import org.jtheque.primary.utils.web.analyzers.generic.Factory; | |
23 | ||
24 | /** | |
25 | * @author Baptiste Wicht | |
26 | */ | |
27 | 0 | final class ContainFactory implements Factory<Condition> { |
28 | @Override | |
29 | public boolean canFactor(Element element, XMLReader reader) throws XMLException{ | |
30 | 0 | return "contains".equals(element.getName()); |
31 | } | |
32 | ||
33 | @Override | |
34 | public Condition factor(Element element, XMLReader reader){ | |
35 | 0 | return new Contain(element.getText()); |
36 | } | |
37 | ||
38 | /** | |
39 | * A contains condition. It seems a condition who test if the line contains a certain text or not. | |
40 | * | |
41 | * @author Baptiste Wicht | |
42 | */ | |
43 | 0 | private static final class Contain implements Condition { |
44 | private final String text; | |
45 | ||
46 | /** | |
47 | * Construct a new Contain. | |
48 | * | |
49 | * @param text The text the line must contain to match the condition. | |
50 | */ | |
51 | private Contain(String text){ | |
52 | 0 | super(); |
53 | ||
54 | 0 | this.text = text; |
55 | 0 | } |
56 | ||
57 | @Override | |
58 | public boolean match(String line){ | |
59 | 0 | return line.contains(text); |
60 | } | |
61 | ||
62 | @Override | |
63 | public String toString(){ | |
64 | 0 | return "Contain{" + |
65 | "text='" + text + '\'' + | |
66 | '}'; | |
67 | } | |
68 | } | |
69 | } |