Skip to content

Commit 98b891f

Browse files
authored
Fix preserving sorted order of a collection (#845)
1 parent 6a9f329 commit 98b891f

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

  • src/main/java/com/google/api/generator/gapic/protoparser

src/main/java/com/google/api/generator/gapic/protoparser/Parser.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ public static GapicContext parse(CodeGeneratorRequest request) {
115115
boolean willGenerateMetadata = PluginArgumentParser.hasMetadataFlag(request);
116116

117117
Optional<String> serviceConfigPathOpt = PluginArgumentParser.parseJsonConfigPath(request);
118-
String serviceConfigPath = serviceConfigPathOpt.isPresent() ? serviceConfigPathOpt.get() : null;
119-
Optional<GapicServiceConfig> serviceConfigOpt = ServiceConfigParser.parse(serviceConfigPath);
118+
Optional<GapicServiceConfig> serviceConfigOpt =
119+
ServiceConfigParser.parse(serviceConfigPathOpt.orElse(null));
120120
if (serviceConfigOpt.isPresent()) {
121121
GapicServiceConfig serviceConfig = serviceConfigOpt.get();
122122
serviceConfig.setLroRetrySettings(lroRetrySettingsOpt);
@@ -128,9 +128,7 @@ public static GapicContext parse(CodeGeneratorRequest request) {
128128
Optional<String> serviceYamlConfigPathOpt =
129129
PluginArgumentParser.parseServiceYamlConfigPath(request);
130130
Optional<com.google.api.Service> serviceYamlProtoOpt =
131-
serviceYamlConfigPathOpt.isPresent()
132-
? ServiceYamlParser.parse(serviceYamlConfigPathOpt.get())
133-
: Optional.empty();
131+
serviceYamlConfigPathOpt.flatMap(ServiceYamlParser::parse);
134132

135133
// Collect the resource references seen in messages.
136134
Set<ResourceReference> outputResourceReferencesSeen = new HashSet<>();
@@ -171,7 +169,7 @@ public static GapicContext parse(CodeGeneratorRequest request) {
171169
Function<ResourceName, String> typeNameFn =
172170
r -> r.resourceTypeString().substring(r.resourceTypeString().indexOf("/") + 1);
173171
Function<Set<ResourceName>, Set<String>> typeStringSetFn =
174-
sr -> sr.stream().map(r -> typeNameFn.apply(r)).collect(Collectors.toSet());
172+
sr -> sr.stream().map(typeNameFn).collect(Collectors.toSet());
175173

176174
// Include all resource names present in message types for backwards-compatibility with the
177175
// monolith. In the future, this should be removed on a client library major semver update.
@@ -202,9 +200,9 @@ public static GapicContext parse(CodeGeneratorRequest request) {
202200
.setMessages(messages)
203201
.setResourceNames(resourceNames)
204202
.setHelperResourceNames(outputArgResourceNames)
205-
.setServiceConfig(serviceConfigOpt.isPresent() ? serviceConfigOpt.get() : null)
203+
.setServiceConfig(serviceConfigOpt.orElse(null))
206204
.setGapicMetadataEnabled(willGenerateMetadata)
207-
.setServiceYamlProto(serviceYamlProtoOpt.isPresent() ? serviceYamlProtoOpt.get() : null)
205+
.setServiceYamlProto(serviceYamlProtoOpt.orElse(null))
208206
.setTransport(transport)
209207
.build();
210208
}
@@ -378,7 +376,7 @@ public static List<Service> parseServices(
378376
outputMixinServices.addAll(
379377
outputMixinServiceSet.stream()
380378
.sorted((s1, s2) -> s2.name().compareTo(s1.name()))
381-
.collect(Collectors.toSet()));
379+
.collect(Collectors.toList()));
382380
return services;
383381
}
384382

@@ -533,7 +531,7 @@ public static Map<String, Message> parseMessages(
533531

534532
private static Map<String, Message> parseMessages(
535533
Descriptor messageDescriptor, Set<ResourceReference> outputResourceReferencesSeen) {
536-
return parseMessages(messageDescriptor, outputResourceReferencesSeen, new ArrayList<String>());
534+
return parseMessages(messageDescriptor, outputResourceReferencesSeen, new ArrayList<>());
537535
}
538536

539537
private static Map<String, Message> parseMessages(
@@ -829,7 +827,7 @@ static String parsePageSizeFieldName(
829827

830828
@VisibleForTesting
831829
static String sanitizeDefaultHost(String rawDefaultHost) {
832-
if (rawDefaultHost.indexOf(COLON) >= 0) {
830+
if (rawDefaultHost.contains(COLON)) {
833831
// A port is already present, just return the existing string.
834832
return rawDefaultHost;
835833
}

0 commit comments

Comments
 (0)