From 0a6e3351cce03350b59d9af91cbe38f3233ca0ff Mon Sep 17 00:00:00 2001 From: rama-huawei Date: Thu, 28 Sep 2017 14:11:07 +0530 Subject: [PATCH] Used entrySet instead of keySet Issue-id: CIMAN-65 Change-Id: I58cba3d30e6866050801fb94426cdc0b26a2f75f Signed-off-by: rama-huawei --- .../onap/aai/datarouter/entity/AaiEventEntity.java | 11 +++++------ .../aai/datarouter/entity/AggregationEntity.java | 22 ++++++++++++++-------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/onap/aai/datarouter/entity/AaiEventEntity.java b/src/main/java/org/onap/aai/datarouter/entity/AaiEventEntity.java index c32cd6f..0391ae3 100644 --- a/src/main/java/org/onap/aai/datarouter/entity/AaiEventEntity.java +++ b/src/main/java/org/onap/aai/datarouter/entity/AaiEventEntity.java @@ -72,9 +72,9 @@ public class AaiEventEntity implements DocumentStoreDataEntity, Serializable { protected String entityType; protected String entityPrimaryKeyName; protected String entityPrimaryKeyValue; - protected ArrayList searchTagCollection = new ArrayList(); - protected ArrayList searchTagIdCollection = new ArrayList(); - protected ArrayList crossEntityReferenceCollection = new ArrayList(); + protected ArrayList searchTagCollection = new ArrayList<>(); + protected ArrayList searchTagIdCollection = new ArrayList<>(); + protected ArrayList crossEntityReferenceCollection = new ArrayList<>(); protected String lastmodTimestamp; protected String link; @@ -95,7 +95,7 @@ public class AaiEventEntity implements DocumentStoreDataEntity, Serializable { private static String convertBytesToHexString(byte[] bytesToConvert) { - StringBuffer hexString = new StringBuffer(); + StringBuilder hexString = new StringBuilder(); for (int i = 0; i < bytesToConvert.length; i++) { hexString.append(Integer.toHexString(0xFF & bytesToConvert[i])); } @@ -104,13 +104,12 @@ public class AaiEventEntity implements DocumentStoreDataEntity, Serializable { private static String concatArray(List list, char delimiter) { - if (list == null || list.size() == 0) { + if (list == null || list.isEmpty()) { return ""; } StringBuilder result = new StringBuilder(64); - int listSize = list.size(); boolean firstValue = true; for (String item : list) { diff --git a/src/main/java/org/onap/aai/datarouter/entity/AggregationEntity.java b/src/main/java/org/onap/aai/datarouter/entity/AggregationEntity.java index 44927eb..56ef6fd 100644 --- a/src/main/java/org/onap/aai/datarouter/entity/AggregationEntity.java +++ b/src/main/java/org/onap/aai/datarouter/entity/AggregationEntity.java @@ -49,6 +49,8 @@ public class AggregationEntity implements DocumentStoreDataEntity, Serializable public void setLink(String link) { this.link = link; } + + @Override public String getId() { // make sure that deliveFields() is called before getting the id return id; @@ -66,7 +68,7 @@ public class AggregationEntity implements DocumentStoreDataEntity, Serializable } - Map attributes = new HashMap(); + Map attributes = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); /** @@ -86,20 +88,22 @@ public class AggregationEntity implements DocumentStoreDataEntity, Serializable while (nodes.hasNext()) { Map.Entry entry = (Map.Entry) nodes.next(); - if (!entry.getKey().equalsIgnoreCase("relationship-list")){ + if (!"relationship-list".equalsIgnoreCase(entry.getKey())){ attributes.put(entry.getKey(), entry.getValue().asText()); } } } public void copyAttributeKeyValuePair(Map map){ - for(String key: map.keySet()){ - if (!key.equalsIgnoreCase("relationship-list")){ // ignore relationship data which is not required in aggregation - this.attributes.put(key, map.get(key).toString()); // not sure if entity attribute can contain an object as value + for(Map.Entry entry: map.entrySet()){ + String key = entry.getKey(); + Object value = entry.getValue(); + if (!"relationship-list".equalsIgnoreCase(key)){ // ignore relationship data which is not required in aggregation + this.attributes.put(key, value.toString()); // not sure if entity attribute can contain an object as value } } } - + public void addAttributeKeyValuePair(String key, String value){ this.attributes.put(key, value); } @@ -108,8 +112,10 @@ public class AggregationEntity implements DocumentStoreDataEntity, Serializable ObjectNode rootNode = mapper.createObjectNode(); rootNode.put("link", this.getLink()); rootNode.put("lastmodTimestamp", lastmodTimestamp); - for (String key: this.attributes.keySet()){ - rootNode.put(key, this.attributes.get(key)); + for (Map.Entry entry: this.attributes.entrySet()){ + String key = entry.getKey(); + String value = entry.getValue(); + rootNode.put(key, value); } return rootNode.toString(); } -- 2.16.6