The Class MapChanges is responsible for tracking changes to a map so that the changes can be committed or rolled back at a later stage. Items can be added to the map, removed from the map or the map can be cleared.
| 30 | * |
| 31 | */ |
| 32 | public class MapChanges<K, V> |
| 33 | { |
| 34 | private final Map<K, V> positive; |
| 35 | private final Map<K, V> negative; |
| 36 | private final boolean clear; |
| 37 | |
| 38 | /** |
| 39 | * Instantiates a new map changes object. |
| 40 | * |
| 41 | * @param added the map of items added |
| 42 | * @param removed the map of items removed |
| 43 | * @param globallyCleared has the map been cleared |
| 44 | */ |
| 45 | public MapChanges(Map<K, V> added, Map<K, V> removed, boolean globallyCleared) |
| 46 | { |
| 47 | positive = added; |
| 48 | negative = removed; |
| 49 | clear = globallyCleared; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Includes global clear. |
| 54 | * |
| 55 | * @return true, if the map was cleared |
| 56 | */ |
| 57 | public boolean includesGlobalClear() |
| 58 | { |
| 59 | return clear; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Checks if the change set is empty. |
| 64 | * |
| 65 | * @return true, if is empty |
| 66 | */ |
| 67 | public boolean isEmpty() |
| 68 | { |
| 69 | return !clear && !hasAddedItems() && !hasRemovedItems(); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Gets the map of added items. |
| 74 | * |
| 75 | * @return the added items |
| 76 | */ |
| 77 | public Map<K, V> getAdded() |
| 78 | { |
| 79 | return positive; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Checks for added items. |
| 84 | * |
| 85 | * @return true, if there are items to add |
| 86 | */ |
| 87 | public boolean hasAddedItems() |
| 88 | { |
| 89 | return positive != null && !positive.isEmpty(); |
nothing calls this directly
no outgoing calls
no test coverage detected