for (final Object element : r)
if (element instanceof TrackHeader)
anzHeader++;
// 2. Durchgang: Tracks bauen
Track[] tracks = new Track[anzHeader];
Track t = null;
i = 0;
for (final Object element : r)
if (element instanceof TrackHeader) {
t = new Track((TrackHeader) element);
tracks[i++] = t;
}
else {
if (t == null) {
tracks = new Track[1];
t = new Track();
}
t.addTrackPoint((TrackPoint) element);
}
return tracks;
}
else if (_name.equals(CommandName.TRANSFER_ROUTES)) {
// 1. Durchgang: Zählen der Header
int anzHeader = 0;
for (final Object element : r)
if (element instanceof RouteHeader)
anzHeader++;
// 2. Durchgang: Routes bauen
final Route[] routes = new Route[anzHeader];
Route t = null;
List<Waypoint> waypoints = null;
List<RouteLink> links = null;
i = 0;
for (final Object element : r)
if (element instanceof RouteHeader) {
if (t != null) {
t.setWaypoints(waypoints);
if (links.size() > 0)
t.setLinks(links);
}
t = new Route((RouteHeader) element);
routes[i++] = t;
waypoints = new ArrayList<Waypoint>();
links = new ArrayList<RouteLink>();
}
else if (element instanceof Waypoint)
waypoints.add((Waypoint) element);
else if (element instanceof RouteLink)
links.add((RouteLink) element);
if (t != null) {
t.setWaypoints(waypoints);
if (links.size() > 0)
t.setLinks(links);
}
return routes;
}
else
return r;