Method for public duration of a trip can return null.

This commit is contained in:
Andreas Schildbach 2015-02-04 17:34:40 +01:00
parent 76458296a0
commit 24e921e547

View file

@ -113,7 +113,11 @@ public final class Trip implements Serializable
return null; return null;
} }
/** Duration of whole trip in milliseconds, including leading and trailing individual legs. */ /**
* Duration of whole trip in milliseconds, including leading and trailing individual legs.
*
* @return duration in ms
*/
public long getDuration() public long getDuration()
{ {
final Date first = getFirstDepartureTime(); final Date first = getFirstDepartureTime();
@ -124,12 +128,17 @@ public final class Trip implements Serializable
/** /**
* Duration of the public leg part in milliseconds. This includes individual legs between public legs, but excludes * Duration of the public leg part in milliseconds. This includes individual legs between public legs, but excludes
* individual legs that lead or trail the trip. * individual legs that lead or trail the trip.
*
* @return duration in ms, or null if there are no public legs
*/ */
public long getPublicDuration() public Long getPublicDuration()
{ {
final Date first = getFirstPublicLegDepartureTime(); final Date first = getFirstPublicLegDepartureTime();
final Date last = getLastPublicLegArrivalTime(); final Date last = getLastPublicLegArrivalTime();
return last.getTime() - first.getTime(); if (first != null && last != null)
return last.getTime() - first.getTime();
else
return null;
} }
/** Minimum time occuring in this trip. */ /** Minimum time occuring in this trip. */