Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DataParserFactory |
|
| 2.3333333333333335;2.333 |
1 | package org.codeforamerica.open311.internals.parsing; | |
2 | ||
3 | import org.codeforamerica.open311.facade.Format; | |
4 | ||
5 | /** | |
6 | * Builds instances of {@link DataParser}. | |
7 | * | |
8 | * Singleton class. | |
9 | * | |
10 | * @author Santiago MunĂn <santimunin@gmail.com> | |
11 | * | |
12 | */ | |
13 | public class DataParserFactory { | |
14 | ||
15 | 1 | private static DataParserFactory instance = new DataParserFactory(); |
16 | ||
17 | 1 | private DataParserFactory() { |
18 | 1 | } |
19 | ||
20 | public static DataParserFactory getInstance() { | |
21 | 7 | return instance; |
22 | } | |
23 | ||
24 | /** | |
25 | * Builds a data parser taking care of the desired format. | |
26 | * | |
27 | * @param format | |
28 | * Desired format. | |
29 | * @return an instance of {@link DataParser} of <code>null</code> if the | |
30 | * given format is not supported. | |
31 | */ | |
32 | public DataParser buildDataParser(Format format) { | |
33 | 7 | if (format == Format.XML) { |
34 | 7 | return new XMLParser(); |
35 | } | |
36 | 0 | if (format == Format.JSON) { |
37 | 0 | return new JSONParser(); |
38 | } | |
39 | 0 | return null; |
40 | } | |
41 | } |