Article View: aus.computers.java
Article #28Re: Concurrent modification
From: windytummy
Date: Tue, 17 Aug 2004 16:07
Date: Tue, 17 Aug 2004 16:07
53 lines
2534 bytes
2534 bytes
> The generic cycle should be aware of the change that has been made and
> go on until the parse method
> How would I do that? I see that HT doesn't see any changes made to
> itself inside a cycle.
Haven't touch Java for a while but I hope I can help. I believe you're
on the right track. To make your HT "see" changes, store its key-value
pairs to a text file. If your HT compares itself with URLs in the text
file, then it can update itself properly.
I personally prefer HashMap as it's faster compared to HashTable like
what I used here (assuming you have the text file):
class Sample
{
//Instance variables
private HashMap map;
private BufferedReader reader;
private String line;
//Constructor
public Sample(String theFile) throws IOException
{
map = new HashMap();
reader = new BufferedReader(new FileReader(theFile));
line = reader.readLine();
while (line != null)
{
map.put(line.toUpperCase(), line.toUpperCase());
line = reader.readLine();
}
}
/**
* Checks if a particular word is in the file
* @param word
* @return true if word exists in dictionary
*/
public boolean wordExist(String word)
{
if (map.containsKey(word))
{
return true;
}
else
{
return false;
}
}
}
cheers,
wt.
Technical Details
Message-ID:
<41222d2f@dnews.tpgi.com.au>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed.freenet.de!nntp.gblx.net!nntp3.phx1!dnews.tpgi.com.au!tpg.com.au!not-for-mailReferences:
<8qfuh0treqoarja44hh958p293g1ajjg85@4ax.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10d6db,e6864c5a77839819 X-Google-Attributes: gid10d6db,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Wed, 18 Aug 2004 02:07:09 +1000 From: windytummy <windytummyDONTINCLUDETHIS@hotmail.com> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5b) Gecko/20030901 Thunderbird/0.2 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: aus.computers.java Subject: Re: Concurrent modification References: <8qfuh0treqoarja44hh958p293g1ajjg85@4ax.com> In-Reply-To: <8qfuh0treqoarja44hh958p293g1ajjg85@4ax.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 203.213.103.140 X-Original-NNTP-Posting-Host: 203.213.103.140 Message-ID: <41222d2f@dnews.tpgi.com.au> X-Trace: dnews.tpgi.com.au!tpg.com.au 1092758831 203.213.103.140 (18 Aug 2004 02:07:11 +1000) Lines: 54 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed.freenet.de!nntp.gblx.net!nntp3.phx1!dnews.tpgi.com.au!tpg.com.au!not-for-mail