/[projects]/android/TrainInfo/src/dk/thoerup/traininfo/provider/ProviderFactory.java
ViewVC logotype

Contents of /android/TrainInfo/src/dk/thoerup/traininfo/provider/ProviderFactory.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1160 - (show annotations) (download)
Mon Oct 4 08:42:12 2010 UTC (13 years, 7 months ago) by torben
File size: 1941 byte(s)
Make cache cleanup code a little more elegant
1 package dk.thoerup.traininfo.provider;
2
3
4
5
6 public class ProviderFactory {
7 private static DepartureProvider departureProvider = null;
8 private static StationProvider stationProvider = null;
9 private static TimetableProvider timetableProvider = null;
10 private static MetroProvider metroProvider = null;
11
12 private static final boolean DEBUG = false;
13
14 //TODO: this one really doesn't belong here ... but where should it go ?
15 public static void purgeOldEntries() {
16 synchronized (ProviderFactory.class) {
17 if (stationProvider != null ) {
18 stationProvider.purgeOldEntries();
19 }
20
21 if (departureProvider != null ) {
22 departureProvider.purgeOldEntries();
23 }
24
25 if (timetableProvider != null ) {
26 timetableProvider.purgeOldEntries();
27 }
28 if (metroProvider != null ) {
29 metroProvider.purgeOldEntries();
30 }
31
32 }
33
34 }
35
36 public static DepartureProvider getDepartureProvider() {
37 if (departureProvider == null) {
38 if (!DEBUG) {
39 departureProvider = new XmlDepartureProvider();
40 } else {
41 departureProvider = new DebugProvider();
42 }
43 }
44
45 return departureProvider;
46 }
47
48 public static StationProvider getStationProvider() {
49 if (stationProvider == null) {
50 if (!DEBUG) {
51 stationProvider = new XmlStationProvider();
52 } else {
53 stationProvider = new DebugProvider();
54 }
55 }
56
57 return stationProvider;
58 }
59
60 public static TimetableProvider getTimetableProvider() {
61 if (timetableProvider == null) {
62 if (!DEBUG) {
63 timetableProvider = new XmlTimetableProvider();
64 } else {
65 timetableProvider = new DebugProvider();
66 }
67 }
68 return timetableProvider;
69 }
70
71 public static MetroProvider getMetroProvider() {
72 if (metroProvider == null) {
73 if (!DEBUG) {
74 metroProvider = new XmlMetroProvider();
75 } else {
76 metroProvider = new DebugProvider();
77 }
78 }
79 return metroProvider;
80 }
81 }

  ViewVC Help
Powered by ViewVC 1.1.20