Skip to content

Commit

Permalink
Fix preserving sorted order of a collection (#845)
Browse files Browse the repository at this point in the history
  • Loading branch information
chanseokoh committed Sep 20, 2021
1 parent 6a9f329 commit 98b891f
Showing 1 changed file with 9 additions and 11 deletions.
Expand Up @@ -115,8 +115,8 @@ public static GapicContext parse(CodeGeneratorRequest request) {
boolean willGenerateMetadata = PluginArgumentParser.hasMetadataFlag(request);

Optional<String> serviceConfigPathOpt = PluginArgumentParser.parseJsonConfigPath(request);
String serviceConfigPath = serviceConfigPathOpt.isPresent() ? serviceConfigPathOpt.get() : null;
Optional<GapicServiceConfig> serviceConfigOpt = ServiceConfigParser.parse(serviceConfigPath);
Optional<GapicServiceConfig> serviceConfigOpt =
ServiceConfigParser.parse(serviceConfigPathOpt.orElse(null));
if (serviceConfigOpt.isPresent()) {
GapicServiceConfig serviceConfig = serviceConfigOpt.get();
serviceConfig.setLroRetrySettings(lroRetrySettingsOpt);
Expand All @@ -128,9 +128,7 @@ public static GapicContext parse(CodeGeneratorRequest request) {
Optional<String> serviceYamlConfigPathOpt =
PluginArgumentParser.parseServiceYamlConfigPath(request);
Optional<com.google.api.Service> serviceYamlProtoOpt =
serviceYamlConfigPathOpt.isPresent()
? ServiceYamlParser.parse(serviceYamlConfigPathOpt.get())
: Optional.empty();
serviceYamlConfigPathOpt.flatMap(ServiceYamlParser::parse);

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

// Include all resource names present in message types for backwards-compatibility with the
// monolith. In the future, this should be removed on a client library major semver update.
Expand Down Expand Up @@ -202,9 +200,9 @@ public static GapicContext parse(CodeGeneratorRequest request) {
.setMessages(messages)
.setResourceNames(resourceNames)
.setHelperResourceNames(outputArgResourceNames)
.setServiceConfig(serviceConfigOpt.isPresent() ? serviceConfigOpt.get() : null)
.setServiceConfig(serviceConfigOpt.orElse(null))
.setGapicMetadataEnabled(willGenerateMetadata)
.setServiceYamlProto(serviceYamlProtoOpt.isPresent() ? serviceYamlProtoOpt.get() : null)
.setServiceYamlProto(serviceYamlProtoOpt.orElse(null))
.setTransport(transport)
.build();
}
Expand Down Expand Up @@ -378,7 +376,7 @@ public static List<Service> parseServices(
outputMixinServices.addAll(
outputMixinServiceSet.stream()
.sorted((s1, s2) -> s2.name().compareTo(s1.name()))
.collect(Collectors.toSet()));
.collect(Collectors.toList()));
return services;
}

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

private static Map<String, Message> parseMessages(
Descriptor messageDescriptor, Set<ResourceReference> outputResourceReferencesSeen) {
return parseMessages(messageDescriptor, outputResourceReferencesSeen, new ArrayList<String>());
return parseMessages(messageDescriptor, outputResourceReferencesSeen, new ArrayList<>());
}

private static Map<String, Message> parseMessages(
Expand Down Expand Up @@ -829,7 +827,7 @@ static String parsePageSizeFieldName(

@VisibleForTesting
static String sanitizeDefaultHost(String rawDefaultHost) {
if (rawDefaultHost.indexOf(COLON) >= 0) {
if (rawDefaultHost.contains(COLON)) {
// A port is already present, just return the existing string.
return rawDefaultHost;
}
Expand Down

0 comments on commit 98b891f

Please sign in to comment.