2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.core;
23 import java.io.Serializable;
24 import java.util.HashMap;
26 import java.util.stream.Collectors;
28 import com.fasterxml.jackson.annotation.JsonProperty;
31 * An object that stores data for rollbacks. Data is organized by type. A type is simply a string
32 * identifier. Multiple types of data may be stored in the same object for separate rollback
35 public class RollbackData implements Serializable {
37 private static final long serialVersionUID = 1L;
40 private final Map<String, Map<String, Serializable>> dictionary = new HashMap<>();
43 * Returns true if the specified type is stored in this object.
45 * @param type the data type
47 public boolean hasType(final String type) {
48 return dictionary.containsKey(type);
52 * Stores a single item.
54 * @param type the data type
56 * @param value the value
58 public void put(final String type, final String key, final String value) {
59 final Map<String, Serializable> mapForType = dictionary.computeIfAbsent(type, k -> new HashMap<>());
61 mapForType.put(key, value);
67 * @param type the data type
69 * @return the item or null if there is no item for the specified type and key
71 public Serializable get(final String type, final String key) {
72 final Map<String, Serializable> mapForType = dictionary.get(type);
74 if (mapForType == null) {
78 return mapForType.get(key);
82 * Gets a map containing all items associated with the specified data type.
84 * @param type the data type
85 * @return a map, or null if there are no items associated with the specified data type
87 public Map<String, Serializable> get(final String type) {
88 return dictionary.get(type);
92 * Returns a string representation of this object.
95 public String toString() {
96 return dictionary.entrySet().stream().map(entry -> entry.getKey() + entry.getValue())
97 .collect(Collectors.joining(",", "[", "]"));