* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2018 Nokia.
+ * Modifications Copyright (c) 2019 Samsung
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Spliterator;
public final class JsonUtilForPnfCorrelationId {
- private static final String JSON_PNF_CORRELATION_ID_FIELD_NAME = "pnfCorrelationId";
+ private static final String JSON_PNF_CORRELATION_ID_FIELD_NAME = "correlationId";
- static List<String> parseJsonToGelAllPnfCorrelationId(String json) {
- JsonElement je = new JsonParser().parse(json);
- JsonArray array = je.getAsJsonArray();
- List<String> list = new ArrayList<>();
- Spliterator<JsonElement> spliterator = array.spliterator();
- spliterator.forEachRemaining(jsonElement -> {
- handleEscapedCharacters(jsonElement)
- .ifPresent(jsonObject -> getPnfCorrelationId(jsonObject)
- .ifPresent(pnfCorrelationId -> list.add(pnfCorrelationId)));
- });
- return list;
+ private JsonUtilForPnfCorrelationId() {
+ throw new IllegalStateException("Utility class");
+ }
+
+ static List<String> parseJsonToGelAllPnfCorrelationId(List<String> list) {
+ if (list == null || list.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+ List<String> newList = new ArrayList<>();
+ list.forEach(je -> handleEscapedCharacters(new JsonParser().parse(je))
+ .ifPresent(jsonObject -> getPnfCorrelationId(jsonObject)
+ .ifPresent(pnfCorrelationId -> newList.add(pnfCorrelationId))));
+ return newList;
}
private static Optional<JsonObject> handleEscapedCharacters(JsonElement jsonElement) {