0
我想比較數據庫轉儲到xml和* .sql。在debagge toRemove
和toAdd
僅在尺寸上有所不同。 toRemove
的大小爲3,toAdd
的大小爲4.但是在運行代碼後,removeAll
,toRemove
的大小爲3,toAdd
的大小爲4.出現了什麼問題?removeAll from Interface Set
final DBHashSet fromdb = new DBHashSet(strURL, strUser, strPassword);
final DBHashSet fromxml = new DBHashSet(namefile);
Set<DBRecord> toRemove = new HashSet<DBRecord>(fromdb);
toRemove.removeAll(fromxml);
Set<DBRecord> toAdd = new HashSet<DBRecord>(fromxml);
toAdd.removeAll(fromdb);
更新:
public class DBRecord {
public String depcode;
public String depjob;
public String description;
public DBRecord(String newdepcode, String newdepjobe, String newdesc) {
this.depcode = newdepcode;
this.depjob = newdepjobe;
this.description = newdesc;
}
public String getKey() {
return depcode + depjob;
}
public boolean IsEqualsKey(DBRecord rec) {
return (this.getKey().equals(rec.getKey()));
}
public boolean equals(Object o) {
if (o == this)
return true;
if (o == null)
return false;
if (!(getClass() == o.getClass()))
return false;
else {
DBRecord rec = (DBRecord) o;
if ((rec.depcode.equals(this.depcode)) && (rec.depjob.equals(this.depjob)))
return true;
else
return false;
}
}
}
檢查您的'hashCode'和'equals()'實現。 –
我們可以看到你的DBRecord類嗎? – Marcelo
帶有DBrecord類的更新文章 – user1755546