Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CutFactory |
|
| 1.0;1 | ||||
CutFactory$1 |
|
| 1.0;1 | ||||
CutFactory$Cut |
|
| 1.0;1 |
1 | package org.jtheque.primary.utils.web.analyzers.generic.transform; | |
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.XMLReader; | |
21 | import org.jtheque.primary.utils.web.analyzers.generic.Factory; | |
22 | ||
23 | /** | |
24 | * @author Baptiste Wicht | |
25 | */ | |
26 | 0 | final class CutFactory implements Factory<Transformer> { |
27 | @Override | |
28 | public boolean canFactor(Element element, XMLReader reader){ | |
29 | 0 | return "cut".equals(element.getName()); |
30 | } | |
31 | ||
32 | @Override | |
33 | public Transformer factor(Element element, XMLReader reader){ | |
34 | 0 | return new Cut(Integer.parseInt(element.getText())); |
35 | } | |
36 | ||
37 | /** | |
38 | * A Transformer who take only the X first chars. | |
39 | * | |
40 | * @author Baptiste Wicht | |
41 | */ | |
42 | 0 | private static final class Cut implements Transformer { |
43 | private final int cut; | |
44 | ||
45 | /** | |
46 | * Construct a new Cut object. | |
47 | * | |
48 | * @param cut The number of characters to take. | |
49 | */ | |
50 | private Cut(int cut){ | |
51 | 0 | super(); |
52 | ||
53 | 0 | this.cut = cut; |
54 | 0 | } |
55 | ||
56 | @Override | |
57 | public String transform(String value){ | |
58 | 0 | return value.substring(0, value.length() - cut); |
59 | } | |
60 | ||
61 | @Override | |
62 | public String toString(){ | |
63 | 0 | return "Cut{" + |
64 | "cut=" + cut + | |
65 | '}'; | |
66 | } | |
67 | } | |
68 | } |