我一眼通過official db4o tutorial的部分,我想做出修改的代碼時,他們給你運行原生查詢:問題使用db4o(JAVA)運行查詢
//the original
List<Pilot> pilots = db.query(new Predicate<Pilot>() {
public boolean match(Pilot pilot) {
return pilot.getPoints() == 100;
}
});
//modified
List<Pilot> pilots = db.query(new Predicate<Pilot>() {
public boolean match(Pilot pilot) {
return pilot.getGames() >= 100;
}
});
我已經添加到了他們試點班:
//in declarations
private ArrayList<String> games;
//modified constructors
public Pilot() {
this.name=null;
this.points=0;
}
public Pilot(String name,int points) {
this.name=name;
this.points=points;
this.games = new ArrayList<String>();
int numGames = (int) (Math.random() * 1000 + 1);
for(int i=0;i<numGames;i++) {
this.games.add(name=" vs Computer");
}
}
//new method
public int getGames() {
return games.size();
}
我已經填充了使用第二個構造500個對象的數據庫,並在數據庫中的所有數據正確與OME月食插件。我測試了getGames()並且它按預期工作。
我的問題是,當我運行修改後的查詢時,它返回數據庫中的所有對象,我不明白爲什麼。我試着改變查詢來包含一個更爲標準的如果是真的,否則錯誤的結構和改變查詢包括需要一定數量的點無濟於事。無論我做什麼,似乎總是評估(pilot.getGames()> = 100)爲真。
任何人都可以幫我理解爲什麼嗎?
非常感謝,先生! – fusion2004