if (vj.getDirectionRef() != null)
affects.setDirectionId(vj.getDirectionRef().getValue());
List<VehicleJourneyRefStructure> tripRefs = vj.getVehicleJourneyRef();
Calls stopRefs = vj.getCalls();
boolean hasTripRefs = !CollectionsLibrary.isEmpty(tripRefs);
boolean hasStopRefs = stopRefs != null
&& !CollectionsLibrary.isEmpty(stopRefs.getCall());
if (!(hasTripRefs || hasStopRefs)) {
if (affects.hasRouteId())
serviceAlert.addAffects(affects);
} else if (hasTripRefs && hasStopRefs) {
for (VehicleJourneyRefStructure vjRef : vj.getVehicleJourneyRef()) {
AgencyAndId tripId = AgencyAndIdLibrary.convertFromString(vjRef.getValue());
affects.setTripId(ServiceAlertLibrary.id(tripId));
for (AffectedCallStructure call : stopRefs.getCall()) {
AgencyAndId stopId = AgencyAndIdLibrary.convertFromString(call.getStopPointRef().getValue());
affects.setStopId(ServiceAlertLibrary.id(stopId));
serviceAlert.addAffects(affects);
}
}
} else if (hasTripRefs) {
for (VehicleJourneyRefStructure vjRef : vj.getVehicleJourneyRef()) {
AgencyAndId tripId = AgencyAndIdLibrary.convertFromString(vjRef.getValue());
affects.setTripId(ServiceAlertLibrary.id(tripId));
serviceAlert.addAffects(affects);
}
} else {
for (AffectedCallStructure call : stopRefs.getCall()) {
AgencyAndId stopId = AgencyAndIdLibrary.convertFromString(call.getStopPointRef().getValue());
affects.setStopId(ServiceAlertLibrary.id(stopId));
serviceAlert.addAffects(affects);
}
}