Skip to content

Commit 52e0270

Browse files
committed
Fix sonarqube issue
1 parent ba3976f commit 52e0270

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

codegen/src/main/java/software/amazon/awssdk/codegen/internal/ExampleMetadataProvider.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -203,27 +203,35 @@ private List<ExampleData> parseServiceExamples(JsonNode serviceNode) {
203203

204204
if (examplesNode != null && examplesNode.isArray()) {
205205
for (JsonNode example : examplesNode.asArray()) {
206-
JsonNode idNode = example.field("id").orElse(null);
207-
JsonNode titleNode = example.field("title").orElse(null);
208-
JsonNode categoryNode = example.field("category").orElse(null);
209-
JsonNode urlNode = example.field("url").orElse(null);
210-
211-
if (idNode != null && titleNode != null && urlNode != null) {
212-
String id = idNode.asString();
213-
String title = titleNode.asString();
214-
String category = categoryNode != null ? categoryNode.asString() : "Api";
215-
String url = urlNode.asString();
216-
217-
if (!id.isEmpty() && !title.isEmpty() && !url.isEmpty()) {
218-
examples.add(new ExampleData(id, title, category, url));
219-
}
220-
}
206+
createExampleData(example).ifPresent(examples::add);
221207
}
222208
}
223209

224210
return examples;
225211
}
226212

213+
private Optional<ExampleData> createExampleData(JsonNode example) {
214+
JsonNode idNode = example.field("id").orElse(null);
215+
JsonNode titleNode = example.field("title").orElse(null);
216+
JsonNode categoryNode = example.field("category").orElse(null);
217+
JsonNode urlNode = example.field("url").orElse(null);
218+
219+
if (idNode == null || titleNode == null || urlNode == null) {
220+
return Optional.empty();
221+
}
222+
223+
String id = idNode.asString();
224+
String title = titleNode.asString();
225+
String category = categoryNode != null ? categoryNode.asString() : "Api";
226+
String url = urlNode.asString();
227+
228+
if (id.isEmpty() || title.isEmpty() || url.isEmpty()) {
229+
return Optional.empty();
230+
}
231+
232+
return Optional.of(new ExampleData(id, title, category, url));
233+
}
234+
227235
public static final class ExampleData {
228236
private final String id;
229237
private final String title;

0 commit comments

Comments
 (0)