Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix preserving sorted order of a collection #845

Merged
merged 3 commits into from
Sep 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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