LOG.debug("Building lookup Map for del.icio.us posts");
LOG.debug("Building lookup Map for "+allDelPosts.size()+" del.icio.us posts");
    private void syncDelicious(Delicious delicious, Registry registry, Date lastSync)                        throws Exception    {        Configuration conf = registry.getConfiguration();                String deletePropStr = conf.getProperty(PROP_DELICIOUS_DELETE, "true");        boolean deleteProp = "true".equalsIgnoreCase(deletePropStr) ? true : false;                LOG.debug("Getting all Posts from del.icio.us now");        List allDelPosts = delicious.getAllPosts(); // remote call        LOG.debug("Fetched "+allDelPosts.size()+" from del.icio.us");        EntryStore store = (EntryStore) registry.getPlugin(Constants.PLUGIN_STORE);        EntryList allRsstEntries = store.getAllEntries(0, Integer.MAX_VALUE, false);                  // parse del.icio.us posts into map, to allow easy access by URL        LOG.debug("Building lookup Map for del.icio.us posts");        Map allPostsMap = new HashMap();        for (int i = 0; i < allDelPosts.size(); i++) {            Post post = (Post) allDelPosts.get(i);            fixPost(post);            allPostsMap.put(post.getHref(), post);        }                        List volatileDelicious = new ArrayList(); // contains Post objects        List volatileRoosster = new ArrayList(); // contains Entry objects                List deleteDelicious = new ArrayList(); // contains Post objects        List deleteRoosster = new ArrayList(); // contains Entry objects                List updateDelicious = new ArrayList(); // contains Post objects        List updateRoosster = new ArrayList(); // contains Entry objects        Map addToRoosster = new HashMap(); // contains Entry objects, keyed by URL                LOG.debug("Looping over "+allRsstEntries.size()+" roosster entries");        for (int i = 0; i < allRsstEntries.size(); i++) {            Entry entry = (Entry) allRsstEntries.get(i);            Post post = (Post) allPostsMap.get(entry.getUrl().toString());                        if ( post != null ) {                if ( !equal(post, entry) ) {                    merge(post, entry);                    updateRoosster.add(entry);                                        // only post to del.icio.us if it's a public bookmark                    if ( entry.getPublic() ) {                        updateDelicious.add(post);                        LOG.debug(post.getHref()+" is public! Will be added/updated in del.icio.us!");                    }                } else {                      LOG.debug(entry+" didn't change! No action needed!");                }                                    if ( entry.getPublic() )                     allPostsMap.remove(entry.getUrl().toString());             } else {                volatileRoosster.add(entry);            }        }                volatileDelicious.addAll(allPostsMap.values());                // for entries/posts in volatile*, determine if they are deletes or         // adds and act accordingly                for(int i = 0; i < volatileRoosster.size(); i++) {            Entry entry = (Entry) volatileRoosster.get(i);            if ( lastSync.after(entry.getAdded()) && entry.getPublic() ) {                LOG.debug(entry+" was deleted from del.icio.us! Will be deleted from roosster!\n");                deleteRoosster.add(entry);            } else if ( entry.getPublic() ) {                LOG.debug(entry+" was added to roosster and is public! Will be added to del.icio.us\n");                updateDelicious.add( entry2Post(entry) );            }        }                        for(int i = 0; i < volatileDelicious.size(); i++) {            Post post = (Post) volatileDelicious.get(i);            if ( lastSync.after(post.getTimeAsDate()) ) {                LOG.debug(post.getHref()+" -- was deleted from roosster! Will be deleted from del.icio.us!\nAdded: "+post.getTimeAsDate()+"\n");                deleteDelicious.add(post);            } else {                LOG.debug(post.getHref()+" -- was added to del.icio.us! Will be added to roosster!\n Added: "+post.getTimeAsDate()+"\n");                Entry entry = post2Entry(post);                 addToRoosster.put(entry.getUrl().toString(), entry);            }        }        //         // write now to delicious        //        for(int i = 0; i < updateDelicious.size(); i++) {            Post post = (Post) updateDelicious.get(i);                        LOG.debug("Updating/Adding <"+post.getHref()+"> to del.icio.us!");                        // fulfill Joshua's restriction by posting calling API once per second             Thread.sleep(1000);            boolean added = delicious.addPost(post.getHref(), post.getDescription(),                                               post.getExtended(), post.getTag(),                                               post.getTimeAsDate());            if ( !added )                LOG.warn("Failed to post "+post.getHref()+" to del.icious");        }                        // write changed entries to roosster        store.addEntries((Entry[]) updateRoosster.toArray(new Entry[0]), true);                 // fetch contents of new URLs and add Entries to roosster        String[] urls = (String[]) addToRoosster.keySet().toArray(new String[0]);                if ( urls.length > 0 ) {            UrlFetcher fetcher = (UrlFetcher) registry.getPlugin(Constants.PLUGIN_FETCHER);                        for ( int i = 0; i < urls.length; i++ ) {                Entry[] fetchedEntries =  fetcher.fetch( new URL[] {new URL(urls[i])} );                                for ( int k = 0; k < fetchedEntries.length; k++ ) {                    Entry entry = (Entry) addToRoosster.get(fetchedEntries[k].getUrl().toString());                    if ( entry != null )                         fetchedEntries[k].overwrite(entry);                }                store.addEntries(fetchedEntries, true);            }        }             // should we delete?        if ( deleteProp ) {                      // delete from del.icio.us            for(int i = 0; i < deleteDelicious.size(); i++) {                Post post = (Post) deleteDelicious.get(i);                                        LOG.debug("DELETING "+post.getHref()+" from del.icio.us!");                                            // fulfill Joshua's restriction by posting calling API once per second                 Thread.sleep(1000);                if ( !delicious.deletePost(post.getHref()) )                    LOG.warn("Failed to DELETE "+post.getHref()+" from del.icious");            }                        // delete from roosster            LOG.debug("Deleting "+deleteRoosster.size()+" Entries from roosster now\n\n");            store.deleteEntries((Entry[]) deleteRoosster.toArray(new Entry[0]));        }            }