From ff9dfa14ecc880d13dfc1ce4648fc4baee9f7d99 Mon Sep 17 00:00:00 2001 From: surya-huawei Date: Wed, 20 Sep 2017 16:50:20 +0530 Subject: Use entrySet instead of keySet *Iterating over map entries with entrySet This is done because both key and value are needed and iterating over entryset is more efficient than keyset Issue-Id: CCSDK-87 Change-Id: I31d14239c8f7300ff2d3a629683e00b42e61ad86 Signed-off-by: surya-huawei --- .../ccsdk/sli/plugins/restapicall/XmlJsonUtil.java | 25 +++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'restapi-call-node/provider/src') diff --git a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlJsonUtil.java b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlJsonUtil.java index b94f0a63..4a04d97d 100644 --- a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlJsonUtil.java +++ b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlJsonUtil.java @@ -132,23 +132,24 @@ public final class XmlJsonUtil { if (o instanceof Map) { StringBuilder ss = new StringBuilder(); Map mm = (Map) o; - for (String k : mm.keySet()) { - Object v = mm.get(k); + for (Map.Entry entry: mm.entrySet()) { + Object v = entry.getValue(); + String key = entry.getKey(); if (v instanceof String) { String s = escape ? escapeXml((String) v) : (String) v; - ss.append(pad(indent)).append('<').append(k).append('>'); + ss.append(pad(indent)).append('<').append(key).append('>'); ss.append(s); - ss.append("').append('\n'); + ss.append("').append('\n'); } else if (v instanceof Map) { - ss.append(pad(indent)).append('<').append(k).append('>').append('\n'); + ss.append(pad(indent)).append('<').append(key).append('>').append('\n'); ss.append(generateXml(v, indent + 1, escape)); - ss.append(pad(indent)).append("').append('\n'); + ss.append(pad(indent)).append("').append('\n'); } else if (v instanceof List) { List ll = (List) v; for (Object o1 : ll) { - ss.append(pad(indent)).append('<').append(k).append('>').append('\n'); + ss.append(pad(indent)).append('<').append(key).append('>').append('\n'); ss.append(generateXml(o1, indent + 1, escape)); - ss.append(pad(indent)).append("').append('\n'); + ss.append(pad(indent)).append("').append('\n'); } } } @@ -185,13 +186,13 @@ public final class XmlJsonUtil { ss.append("{\n"); boolean first = true; - for (String k : mm.keySet()) { + for (Map.Entry entry : mm.entrySet()) { if (!first) ss.append(",\n"); first = false; - - Object v = mm.get(k); - ss.append(pad(indent + 1)).append('"').append(k).append("\": "); + Object v = entry.getValue(); + String key = entry.getKey(); + ss.append(pad(indent + 1)).append('"').append(key).append("\": "); generateJson(ss, v, indent + 1, false, escape); } -- cgit 1.2.3-korg