package dk.thoerup.android.traininfo.common; import java.io.Serializable; import org.simpleframework.xml.Element; import org.simpleframework.xml.Root; @Root(name="train") public class DepartureEntry implements Comparable, Serializable { @Element private String time; @Element private int updated; @Element(name="trainnumber") private String trainNumber; @Element private String destination; @Element private String origin; @Element(required=false) private String location; @Element(required=false) private String status; @Element(required=false) private String note; @Element private String type; public String getTime() { return time; } public void setTime(String time) { this.time = time; } public int getUpdated() { return updated; } public void setUpdated(int updated) { this.updated = updated; } public String getTrainNumber() { return trainNumber; } public void setTrainNumber(String trainNumber) { this.trainNumber = trainNumber; } public String getDestination() { return destination; } public void setDestination(String destination) { this.destination = destination; } public String getOrigin() { return origin; } public void setOrigin(String origin) { this.origin = origin; } public String getLocation() { return location; } public void setLocation(String location) { this.location = location; } public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } public String getNote() { return note; } public void setNote(String note) { this.note = note; } public String getType() { return type; } public void setType(String type) { this.type = type; } @Override public int compareTo(DepartureEntry otherBean) { String timeStr1 = time.replace(":","").trim(); String timeStr2 = otherBean.time.replace(":","").trim(); int time1 = 0; int time2 = 0; if (timeStr1.length() > 0) time1 = Integer.parseInt(timeStr1); if (timeStr2.length() > 0) time2 = Integer.parseInt(timeStr2); //work correctly when clock wraps around at midnight if (Math.abs(time1-time2) < 1200) { if (time1 > time2) return 1; else return -1; } else { if (time1 < time2) return 1; else return -1; } } }