Monday, 15 August 2011

java - HashSet is Adding Duplicate ChannelSftp.LsEntry -



java - HashSet is Adding Duplicate ChannelSftp.LsEntry -

i trying download files via sftp using jsch library. doing that, want download file if not downloaded. gathering list of entries, , trying implement hashset check , see if downloaded. problem is, adding duplicates hashset , redownloading of files. below code have written (well, of import parts).

vector<channelsftp.lsentry> list = sftpchannel.ls("*.gz"); (channelsftp.lsentry entry : list) { if (set.add(entry)) { sftpchannel.get(entry.getfilename(), filedestination); } }

this in method. so, when phone call method again, should download files didn't download previously. however, not doing that. suggestions? please allow me know if need clarify anything.

instead of entry add together entry.getfilename() set:

if (set.add(entry.getfilename())) { sftpchannel.get(entry.getfilename(), filedestination); }

what have assumed here getfilename returns string , application permits such set defined.

the reason works (if assumptions correct) because equals defined on string , not allow 2 same names (identical sequence of characters) end in same set.

however if can not modify set should override hashcode , equals on channelsftp.lsentry reflecting think makes 2 lsentry objects equal.

java hashset jsch

No comments:

Post a Comment