Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PlatformManager |
|
| 1.5;1.5 |
1 | package org.codeforamerica.open311.internals.platform; | |
2 | ||
3 | import org.codeforamerica.open311.internals.caching.AndroidCache; | |
4 | import org.codeforamerica.open311.internals.caching.Cache; | |
5 | import org.codeforamerica.open311.internals.caching.NoCache; | |
6 | import org.codeforamerica.open311.internals.caching.RegularJavaCache; | |
7 | import org.codeforamerica.open311.internals.logging.AndroidLogger; | |
8 | import org.codeforamerica.open311.internals.logging.Logger; | |
9 | import org.codeforamerica.open311.internals.logging.RegularJavaLogger; | |
10 | ||
11 | /** | |
12 | * Builds some objects which implementation depends of the execution | |
13 | * environment. | |
14 | * | |
15 | * @author Santiago MunĂn <santimunin@gmail.com> | |
16 | * | |
17 | */ | |
18 | public class PlatformManager { | |
19 | /** | |
20 | * Unique instance. | |
21 | */ | |
22 | 1 | private static PlatformManager instance = new PlatformManager(); |
23 | private boolean androidPlatform; | |
24 | ||
25 | /** | |
26 | * Prevents other objects to instantiate instances of this class. | |
27 | */ | |
28 | 1 | private PlatformManager() { |
29 | 1 | androidPlatform = System.getProperty("java.vm.name").equalsIgnoreCase( |
30 | "Dalvik"); | |
31 | 1 | } |
32 | ||
33 | /** | |
34 | * Returns the unique instance of the class. | |
35 | * | |
36 | * @return The unique instance of the class. | |
37 | */ | |
38 | public static PlatformManager getInstance() { | |
39 | 24 | return instance; |
40 | } | |
41 | ||
42 | /** | |
43 | * Builds a cache instance taking care of the execution environment. | |
44 | * | |
45 | * @return {@link NoCache} under Android, {@link RegularJavaCache} | |
46 | * otherwise. {@link AndroidCache} has to be built explicitly. | |
47 | */ | |
48 | public Cache buildCache() { | |
49 | 23 | return androidPlatform ? new NoCache() : RegularJavaCache.getInstance(); |
50 | } | |
51 | ||
52 | /** | |
53 | * Builds a logger instance taking care of the execution environment. | |
54 | * | |
55 | * @return {@link AndroidLogger} under Android. {@link RegularJavaLogger} | |
56 | * otherwise. | |
57 | */ | |
58 | public Logger buildLogger() { | |
59 | 1 | return androidPlatform ? new AndroidLogger() : new RegularJavaLogger(); |
60 | } | |
61 | ||
62 | } |