/[projects]/android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureBean.java
ViewVC logotype

Diff of /android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureBean.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 307 by torben, Thu Sep 10 18:11:53 2009 UTC revision 373 by torben, Wed Sep 30 19:49:25 2009 UTC
# Line 1  Line 1 
1  package dk.thoerup.traininfoservice.banedk;  package dk.thoerup.traininfoservice.banedk;
2    
3  public class DepartureBean implements Comparable {  public class DepartureBean implements Comparable<DepartureBean> {
4          private String time;              private String time;    
5          private int updated;              private int updated;    
6          private String trainNumber;          private String trainNumber;
# Line 61  public class DepartureBean implements Co Line 61  public class DepartureBean implements Co
61          }          }
62                    
63          @Override          @Override
64          public int compareTo(Object arg0) {          public int compareTo(DepartureBean otherBean) {
65                  DepartureBean otherBean = (DepartureBean) arg0;                  String timeStr1 = time.replace(":","").trim();
66                    String timeStr2 = otherBean.time.replace(":","").trim();
67                                    
68                  int time1 = Integer.parseInt(time.replace(":", ""));                  int time1 = 0;
69                  int time2 = Integer.parseInt(otherBean.time.replace(":", ""));                  int time2 = 0;
70                  if (time1 > time2)                  
71                          return 1;                  if (timeStr1.length() > 0)
72                  else                          time1 = Integer.parseInt(timeStr1);
73                          return -1;                  
74                    if (timeStr2.length() > 0)
75                            time2 = Integer.parseInt(timeStr2);
76                    
77                    //work correctly when clock wraps around at midnight
78                    if (Math.abs(time1-time2) < 1200) {
79                            if (time1 > time2)
80                                    return 1;
81                            else
82                                    return -1;
83                    } else {
84                            if (time1 < time2)
85                                    return 1;
86                            else
87                                    return -1;
88    
89                    }
90                                    
91          }          }
92                    
93            public String getUpdatedString() {
94                    String updStr;
95                    
96                    switch (updated) {
97                    case 1:
98                            updStr = "&lt; 3 min";
99                            break;
100                    case 2:
101                            updStr = "3-10 min";
102                            break;
103                    case 3:
104                            updStr = "&gt; 10 min";
105                            break;
106                    case 4:
107                            updStr = "No info";
108                            break;
109                    default:
110                            updStr = "Unknown:" + updated;                  
111                    }
112                    
113                    return updStr;
114            }
115                    
116  }  }

Legend:
Removed from v.307  
changed lines
  Added in v.373

  ViewVC Help
Powered by ViewVC 1.1.20