1 package net.javacoding.jspider.core.storage.memory; 2 3 import net.javacoding.jspider.core.storage.spi.SiteDAOSPI; 4 import net.javacoding.jspider.core.storage.spi.StorageSPI; 5 import net.javacoding.jspider.core.model.SiteInternal; 6 7 import java.net.URL ; 8 import java.util.HashMap ; 9 import java.util.Map ; 10 11 14 class SiteDAOImpl implements SiteDAOSPI { 15 16 protected StorageSPI storage; 17 protected Map byURL; 18 protected Map byId; 19 20 public SiteDAOImpl ( StorageSPI storage ) { 21 this.storage = storage; 22 this.byURL = new HashMap ( ); 23 this.byId = new HashMap ( ); 24 } 25 26 public SiteInternal find(int id) { 27 return (SiteInternal)byId.get(new Integer (id)); 28 } 29 30 public SiteInternal find(URL siteURL) { 31 return (SiteInternal)byURL.get(siteURL); 32 } 33 34 public void create(int id, SiteInternal site) { 35 byURL.put(site.getURL(), site); 36 byId.put(new Integer (id), site); 37 } 38 39 public void save(int id, SiteInternal site) { 40 URL siteURL = site.getURL(); 41 byURL.put(siteURL, site); 42 byId.put(new Integer (id), site); 43 } 44 45 public SiteInternal[] findAll() { 46 return (SiteInternal[]) byURL.values().toArray(new SiteInternal[byURL.size()]); 47 } 48 49 } 50 | Popular Tags |