4 package eu
.etaxonomy
.cdm
.io
.common
;
6 import java
.util
.HashMap
;
7 import java
.util
.HashSet
;
9 import java
.util
.Collection
;
11 import java
.util
.UUID
;
14 import org
.apache
.log4j
.Logger
;
16 import eu
.etaxonomy
.cdm
.api
.service
.IService
;
17 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
23 public class MapWrapper
<T
extends CdmBase
> {
24 private static Logger logger
= Logger
.getLogger(MapWrapper
.class);
26 private Map internalMap
;
27 private IService
<CdmBase
> service
= null;
29 public MapWrapper(IService
<CdmBase
> service
){
33 public void put(Object id
, T cdmBase
){
35 throw new RuntimeException();
37 internalMap
.put(id
, cdmBase
);
41 public void put(Object id
, UUID uuid
){
43 throw new RuntimeException();
46 //service.save(cdmBase);
47 internalMap
.put(id
, uuid
);
51 public T
get(Object id
){
54 result
= (T
)internalMap
.get(id
);
56 result
= getObjectFromService(id
);
62 * Returns all values that are either stored in the wrapper or the the database.
63 * If <code>service</code> is null then only the elements stored in the wrapper are returned.
66 public Set
<T
> getAllValues(){
67 Set
<T
> result
= new HashSet
<T
>();
69 result
.addAll(internalMap
.values());
71 result
.addAll(internalMap
.values());
72 logger
.warn("getAll not yet implemented !!");
73 //TODO Set<T> persitentAll = service.getAll();
74 //result.addAll(persistentALl);
79 public boolean containsId(Object id
){
80 return internalMap
.containsKey(id
);
83 public Collection
<T
> objects(){
85 return (Collection
<T
>)internalMap
.values();
88 private T
getObjectFromService(Object id
){
90 throw new RuntimeException("no service defined");
93 UUID uuid
= (UUID
)internalMap
.get(id
);
99 //result = (T)service.getObjectUuid(uuid); //.getCdmObjectByUuid(uuid);// taxonService.getTaxonByUuid(taxonUuid);
105 public boolean makeEmpty(){
106 return makeNewMap(service
);
109 public boolean makeNewMap(IService
<CdmBase
> service
){
110 if (service
== null){
111 internalMap
= new HashMap
<Integer
, CdmBase
>();
113 this.service
= service
;
114 internalMap
= new HashMap
<Integer
, UUID
>();