01: package net.javacoding.jspider.core.storage.memory;
02:
03: import net.javacoding.jspider.core.storage.spi.EMailAddressDAOSPI;
04: import net.javacoding.jspider.core.storage.spi.StorageSPI;
05: import net.javacoding.jspider.core.model.*;
06:
07: import java.util.*;
08:
09: /**
10: * $Id: EMailAddressDAOImpl.java,v 1.2 2003/04/11 16:37:06 vanrogu Exp $
11: */
12: class EMailAddressDAOImpl implements EMailAddressDAOSPI {
13:
14: protected StorageSPI storage;
15:
16: protected Map byResource;
17: protected Map addresses;
18:
19: public EMailAddressDAOImpl(StorageSPI storage) {
20: this .storage = storage;
21: this .byResource = new HashMap();
22: this .addresses = new HashMap();
23: }
24:
25: public void register(ResourceInternal resource,
26: EMailAddressInternal address) {
27: Map map = (Map) byResource.get(new Integer(resource.getId()));
28: if (map == null) {
29: map = new HashMap();
30: byResource.put(new Integer(resource.getId()), map);
31: }
32:
33: EMailAddressReferenceInternal reference = (EMailAddressReferenceInternal) map
34: .get(address.getAddress());
35: if (reference == null) {
36: reference = new EMailAddressReferenceInternal(storage,
37: resource.getId(), address.getAddress(), 0);
38: map.put(address.getAddress(), reference);
39: }
40: reference.incrementCount();
41: addresses.put(address.getAddress(), address);
42: }
43:
44: public EMailAddressInternal[] findByResource(
45: ResourceInternal resource) {
46: EMailAddressReferenceInternal[] refs = findReferencesByResource(resource);
47: ArrayList al = new ArrayList();
48: for (int i = 0; i < refs.length; i++) {
49: EMailAddressReferenceInternal ref = refs[i];
50: al.add(ref.getEMailAddress());
51: }
52: return (EMailAddressInternal[]) al
53: .toArray(new EMailAddressInternal[al.size()]);
54: }
55:
56: public EMailAddressReferenceInternal[] findReferencesByResource(
57: ResourceInternal resource) {
58: Map map = (Map) byResource.get(new Integer(resource.getId()));
59: if (map == null) {
60: return new EMailAddressReferenceInternal[0];
61: } else {
62: return (EMailAddressReferenceInternal[]) map.values()
63: .toArray(
64: new EMailAddressReferenceInternal[map
65: .size()]);
66: }
67: }
68:
69: public EMailAddressInternal find(String address) {
70: return (EMailAddressInternal) addresses.get(address);
71: }
72: }
|