1
我試圖添加一個索引,其中我的覆蓋equals()
確定兩個對象是否相同。cqengine cant index by equals
Car.java
public static class Car {
final String id;
private String name;
public Car(String id, String name) {
this.id = id;
this.name = name;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public static final Attribute<Car, Car> CAR = new SimpleAttribute<Car, Car>() {
@Override
public Car getValue(Car car, QueryOptions queryOptions) {
return car;
}
};
@Override
public String toString() {
return "Car{" + "id=" + id + ", name=" + name + '}';
}
}
Fetcher.java
public static final ResultSet<Car> get(final IndexedCollection<Car> indexedCollection, final Car car) {
return indexedCollection.retrieve(QueryFactory.equal(Car.CAR, car));
}
Main.java
public static void main(String args[]) {
IndexedCollection<Car> cars = new ConcurrentIndexedCollection<>();
cars.addIndex(NavigableIndex.onAttribute(Car.CAR));
}
的proble m在這條線上cars.addIndex(NavigableIndex.onAttribute(Car.CAR));
其中錯誤消息是no suitable method found for onAttribute(Attribute<Car,Car>)
。我在這裏做錯了什麼,或者是否有另一個我應該使用的電話?
'IndexedCollection cars'需要一個'汽車
覆蓋在車等於'但'屬性 CAR'不是汽車。它就像一個SimpleEntry。嘗試調用'getValue();' –
asdf
@asdf:我在哪裏調用'getValue();'完全? – Hooli
看到這個例子:[Car](https://github.com/npgall/cqengine/blob/master/code/src/test/java/com/googlecode/cqengine/examples/introduction/Car.java)和[Introduction ](https://github.com/npgall/cqengine/blob/master/code/src/test/java/com/googlecode/cqengine/examples/introduction/Introduction.java) – asdf