2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.persistence
.hibernate
;
12 import java
.util
.Collection
;
13 import java
.util
.HashMap
;
14 import java
.util
.HashSet
;
17 import java
.util
.Vector
;
19 import org
.apache
.log4j
.Logger
;
21 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeEvent
.EventType
;
28 public class CdmDataChangeMap
implements Map
<EventType
, Vector
<CdmDataChangeEvent
>>{
29 private static final Logger logger
= Logger
30 .getLogger(CdmDataChangeMap
.class);
32 private Map
<EventType
, Vector
<CdmDataChangeEvent
>> dataChangeMap
;
34 public CdmDataChangeMap(){
35 dataChangeMap
= new HashMap
<EventType
, Vector
<CdmDataChangeEvent
>>();
39 * @see java.util.Map#clear()
43 dataChangeMap
.clear();
47 * @see java.util.Map#containsKey(java.lang.Object)
50 public boolean containsKey(Object key
) {
51 return dataChangeMap
.containsKey(key
);
55 * @see java.util.Map#containsValue(java.lang.Object)
58 public boolean containsValue(Object value
) {
59 return dataChangeMap
.containsValue(value
);
63 * @see java.util.Map#entrySet()
66 public Set
entrySet() {
67 return dataChangeMap
.entrySet();
71 * @see java.util.Map#get(java.lang.Object)
74 public Vector
<CdmDataChangeEvent
> get(Object key
) {
75 return dataChangeMap
.get(key
);
79 * Returns events by type
84 public Vector
<CdmDataChangeEvent
> getEvents(EventType type
){
85 Vector
<CdmDataChangeEvent
> vector
= dataChangeMap
.get(type
);
87 vector
= new Vector
<>(0);
93 * @see java.util.Map#isEmpty()
96 public boolean isEmpty() {
97 return dataChangeMap
.isEmpty();
101 * @see java.util.Map#keySet()
104 public Set
keySet() {
105 return dataChangeMap
.keySet();
108 public void add(EventType type
, CdmDataChangeEvent event
){
109 Vector
<CdmDataChangeEvent
> vector
= getEvents(type
);
111 // lazy initialising the vectors
113 vector
= new Vector
<CdmDataChangeEvent
>();
118 dataChangeMap
.put(type
, vector
);
123 * @see java.util.Map#remove(java.lang.Object)
126 public Vector
<CdmDataChangeEvent
> remove(Object key
) {
127 return dataChangeMap
.remove(key
);
131 * @see java.util.Map#size()
135 return dataChangeMap
.size();
138 public int sizeByEventType(EventType type
){
139 Vector
<CdmDataChangeEvent
> vector
= getEvents(type
);
140 return vector
== null ?
0 : vector
.size();
144 * @see java.util.Map#values()
147 public Collection
<Vector
<CdmDataChangeEvent
>> values() {
148 return dataChangeMap
.values();
152 * Returns all change events stored in this change map
156 public Collection
<CdmDataChangeEvent
> getAllEvents(){
157 Collection
<CdmDataChangeEvent
> values
= new HashSet
<CdmDataChangeEvent
>();
158 for (EventType type
: EventType
.values()){
159 if(dataChangeMap
.get(type
) != null){
160 for(CdmDataChangeEvent event
: dataChangeMap
.get(type
)){
169 * @see java.util.Map#put(java.lang.Object, java.lang.Object)
172 public Vector
<CdmDataChangeEvent
> put(EventType key
,
173 Vector
<CdmDataChangeEvent
> value
) {
174 return dataChangeMap
.put(key
, value
);
178 * @see java.util.Map#putAll(java.util.Map)
182 Map
<?
extends EventType
, ?
extends Vector
<CdmDataChangeEvent
>> t
) {
183 dataChangeMap
.putAll(t
);