2727public interface CallWrapper {
2828 /**
2929 * Parse and validate all calls from an {@link EstimatedVehicleJourney}. Each call must have a
30- * non-empty stop point ref and exactly one of Order or VisitNumber. All calls must use the same
31- * strategy (all Order or all VisitNumber). The returned list is sorted by sort order.
30+ * non-empty stop point ref and at least one of Order or VisitNumber (Order is preferred when both
31+ * are present). All calls must use the same strategy (all Order or all VisitNumber). The returned
32+ * list is sorted by sort order.
3233 *
3334 * @return a successful sorted list of calls, or a failure with the appropriate error type
3435 */
3536 static List <CallWrapper > of (EstimatedVehicleJourney estimatedVehicleJourney )
3637 throws UpdateException {
3738 List <CallWrapper > result = new ArrayList <>();
38- boolean hasOrderCalls = false ;
39- boolean hasVisitNumberCalls = false ;
39+ boolean hasCallWithOrder = false ;
40+ boolean hasCallWithoutOrder = false ;
4041
4142 if (estimatedVehicleJourney .getRecordedCalls () != null ) {
4243 for (var call : estimatedVehicleJourney .getRecordedCalls ().getRecordedCalls ()) {
@@ -45,8 +46,9 @@ static List<CallWrapper> of(EstimatedVehicleJourney estimatedVehicleJourney)
4546 call .getOrder (),
4647 call .getVisitNumber ()
4748 );
48- hasOrderCalls |= call .getOrder () != null ;
49- hasVisitNumberCalls |= call .getVisitNumber () != null ;
49+ var hasOrder = call .getOrder () != null ;
50+ hasCallWithOrder |= hasOrder ;
51+ hasCallWithoutOrder |= !hasOrder ;
5052 result .add (new RecordedCallWrapper (call , sortOrder ));
5153 }
5254 }
@@ -58,16 +60,14 @@ static List<CallWrapper> of(EstimatedVehicleJourney estimatedVehicleJourney)
5860 call .getOrder (),
5961 call .getVisitNumber ()
6062 );
61- hasOrderCalls |= call .getOrder () != null ;
62- hasVisitNumberCalls |= call .getVisitNumber () != null ;
63+ var hasOrder = call .getOrder () != null ;
64+ hasCallWithOrder |= hasOrder ;
65+ hasCallWithoutOrder |= !hasOrder ;
6366 result .add (new EstimatedCallWrapper (call , sortOrder ));
6467 }
6568 }
6669
67- // we reject messages that contain both Order and VisitNumber since we do not see any obvious
68- // use case that requires both, and making them mutually exclusive make the implementation
69- // simpler. We can relax this validation rule later if valid use cases are identified.
70- if (hasOrderCalls && hasVisitNumberCalls ) {
70+ if (hasCallWithOrder && hasCallWithoutOrder ) {
7171 throw UpdateException .of (UpdateErrorType .MIXED_CALL_ORDER_AND_VISIT_NUMBER );
7272 }
7373
@@ -90,9 +90,6 @@ private static int validateCall(
9090 if (order == null && visitNumber == null ) {
9191 throw UpdateException .of (UpdateErrorType .MISSING_CALL_ORDER );
9292 }
93- if (order != null && visitNumber != null ) {
94- throw UpdateException .of (UpdateErrorType .MIXED_CALL_ORDER_AND_VISIT_NUMBER );
95- }
9693 return order != null ? order .intValueExact () : visitNumber .intValueExact ();
9794 }
9895
0 commit comments