diff options
author | Seshu Kumar M <seshu.kumar.m@huawei.com> | 2018-02-06 11:52:48 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-02-06 11:52:48 +0000 |
commit | 5bb91300baa2cf0c819d0cb23dcdeaf30b19f279 (patch) | |
tree | c3f49ae57fa80eef21cd2f6730b596f009626ccb /bpmn/MSOCoreBPMN/src/main | |
parent | d27b2b875e0e52b8a2d66f27eca4aee2eb8213e1 (diff) | |
parent | ebd504c48d03d25e5b77d9094f4baa31581ee0f1 (diff) |
Merge "Added unittests for RollbackData"
Diffstat (limited to 'bpmn/MSOCoreBPMN/src/main')
-rw-r--r-- | bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/RollbackData.java | 127 |
1 files changed, 60 insertions, 67 deletions
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/RollbackData.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/RollbackData.java index 7ece05ea9e..64068d2b90 100644 --- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/RollbackData.java +++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/RollbackData.java @@ -23,6 +23,7 @@ package org.openecomp.mso.bpmn.core; import java.io.Serializable; import java.util.HashMap; import java.util.Map; +import java.util.stream.Collectors; /** * An object that stores data for rollbacks. Data is organized by type. A @@ -30,80 +31,72 @@ import java.util.Map; * in the same object for separate rollback operations. */ public class RollbackData implements Serializable { - private static final long serialVersionUID = 1L; - private Map<String, Map<String, Serializable>> dictionary = - new HashMap<String, Map<String, Serializable>>(); - - /** - * Returns true if the specified type is stored in this object. - * @param type the data type - */ - public boolean hasType(String type) { - return dictionary.containsKey(type); - } + private static final long serialVersionUID = 1L; - /** - * Stores a single item. - * @param type the data type - * @param key the key - * @param value the value - */ - public void put(String type, String key, String value) { - Map<String, Serializable> mapForType = dictionary.get(type); + private Map<String, Map<String, Serializable>> dictionary = + new HashMap<String, Map<String, Serializable>>(); - if (mapForType == null) { - mapForType = new HashMap<String, Serializable>(); - dictionary.put(type, mapForType); - } + /** + * Returns true if the specified type is stored in this object. + * + * @param type the data type + */ + public boolean hasType(String type) { + return dictionary.containsKey(type); + } - mapForType.put(key, value); - } + /** + * Stores a single item. + * + * @param type the data type + * @param key the key + * @param value the value + */ + public void put(String type, String key, String value) { + Map<String, Serializable> mapForType = dictionary.get(type); - /** - * Gets a single item. - * @param type the data type - * @param key the key - * @return the item or null if there is no item for the specified type and key - */ - public Serializable get(String type, String key) { - Map<String, Serializable> mapForType = dictionary.get(type); + if (mapForType == null) { + mapForType = new HashMap<String, Serializable>(); + dictionary.put(type, mapForType); + } - if (mapForType == null) { - return null; - } + mapForType.put(key, value); + } - return mapForType.get(key); - } + /** + * Gets a single item. + * + * @param type the data type + * @param key the key + * @return the item or null if there is no item for the specified type and key + */ + public Serializable get(String type, String key) { + Map<String, Serializable> mapForType = dictionary.get(type); - /** - * Gets a map containing all items associated with the specified data type. - * @param type the data type - * @return a map, or null if there are no items associated with the specified - * data type - */ - public Map<String, Serializable> get(String type) { - return dictionary.get(type); - } + if (mapForType == null) { + return null; + } - /** - * Returns a string representation of this object. - */ - @Override - public String toString() { - StringBuilder out = new StringBuilder(); - out.append(getClass().getSimpleName()); - out.append('['); - boolean hasOne = false; - for (String type : dictionary.keySet()) { - if (hasOne) { - out.append(','); - } - out.append(type); - out.append(dictionary.get(type)); - hasOne = true; - } - out.append(']'); - return out.toString(); - } + return mapForType.get(key); + } + + /** + * Gets a map containing all items associated with the specified data type. + * + * @param type the data type + * @return a map, or null if there are no items associated with the specified data type + */ + public Map<String, Serializable> get(String type) { + return dictionary.get(type); + } + + /** + * Returns a string representation of this object. + */ + @Override + public String toString() { + return dictionary.entrySet().stream().map(entry -> entry.getKey() + entry.getValue()) + .collect(Collectors.joining(",", "[", "]")); + } } |