File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed
application/src/main/java/org/opentripplanner/apis/transmodel Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 9
9
import static org .opentripplanner .apis .transmodel .model .EnumTypes .MULTI_MODAL_MODE ;
10
10
import static org .opentripplanner .apis .transmodel .model .EnumTypes .TRANSPORT_MODE ;
11
11
import static org .opentripplanner .apis .transmodel .model .scalars .DateTimeScalarFactory .createMillisecondsSinceEpochAsDateTimeStringScalar ;
12
+ import static org .opentripplanner .apis .transmodel .support .GqlUtil .toListNullSafe ;
12
13
import static org .opentripplanner .model .projectinfo .OtpProjectInfo .projectInfo ;
13
14
14
15
import graphql .Scalars ;
@@ -1310,11 +1311,11 @@ private GraphQLSchema create() {
1310
1311
);
1311
1312
var privateCodes = FilterValues .ofEmptyIsEverything (
1312
1313
"privateCodes" ,
1313
- environment .<List <String >>getArgument ("privateCodes" )
1314
+ toListNullSafe ( environment .<List <String >>getArgument ("privateCodes" ) )
1314
1315
);
1315
1316
var activeServiceDates = FilterValues .ofEmptyIsEverything (
1316
1317
"activeDates" ,
1317
- environment .<List <LocalDate >>getArgument ("activeDates" )
1318
+ toListNullSafe ( environment .<List <LocalDate >>getArgument ("activeDates" ) )
1318
1319
);
1319
1320
1320
1321
TripRequest tripRequest = TripRequest
Original file line number Diff line number Diff line change 6
6
import graphql .schema .GraphQLInputObjectField ;
7
7
import graphql .schema .GraphQLList ;
8
8
import graphql .schema .GraphQLNonNull ;
9
+ import java .util .Collection ;
9
10
import java .util .List ;
10
11
import java .util .Locale ;
12
+ import java .util .Objects ;
13
+ import javax .annotation .Nullable ;
11
14
import org .opentripplanner .apis .transmodel .TransmodelRequestContext ;
12
15
import org .opentripplanner .apis .transmodel .mapping .TransitIdMapper ;
13
16
import org .opentripplanner .framework .graphql .GraphQLUtils ;
18
21
19
22
/**
20
23
* Provide some of the commonly used "chain" of methods. Like all ids should be created the same
21
- * wayThis
24
+ * way.
22
25
*/
23
26
public class GqlUtil {
24
27
@@ -96,4 +99,15 @@ public static Locale getLocale(DataFetchingEnvironment environment) {
96
99
? GraphQLUtils .getLocale (environment , lang )
97
100
: GraphQLUtils .getLocale (environment );
98
101
}
102
+
103
+ /**
104
+ * Null-safe handling of a collection of type T. Returns an empty list if the collection is null.
105
+ * Null elements are filtered out.
106
+ */
107
+ public static <T > List <T > toListNullSafe (@ Nullable Collection <T > args ) {
108
+ if (args == null ) {
109
+ return List .of ();
110
+ }
111
+ return args .stream ().filter (Objects ::nonNull ).toList ();
112
+ }
99
113
}
You can’t perform that action at this time.
0 commit comments