I use cqengine for collection indexation:
Attribute<UtilizationEntry, LocalDate> startDateAttr = new SimpleAttribute<UtilizationEntry, LocalDate>() {
@Override
public LocalDate getValue(UtilizationEntry object, QueryOptions queryOptions) {
return object.getStartDate();
}
};
IndexedCollection<UtilizationEntry> entries = new ConcurrentIndexedCollection<>();
entries.addIndex(NavigableIndex.onAttribute(startDateAttr)); // compilation error in this line
This code isn't compiled because:
Error:(61, 70) java: no suitable method found for onAttribute(com.googlecode.cqengine.attribute.Attribute<entities.UtilizationEntry,java.time.LocalDate>)
method com.googlecode.cqengine.index.navigable.NavigableIndex.<A,O>onAttribute(com.googlecode.cqengine.attribute.Attribute<O,A>) is not applicable
(inferred type does not conform to equality constraint(s)
inferred: java.time.chrono.ChronoLocalDate
equality constraints(s): java.time.chrono.ChronoLocalDate,java.time.LocalDate)
method com.googlecode.cqengine.index.navigable.NavigableIndex.<A,O>onAttribute(com.googlecode.cqengine.index.support.Factory<java.util.concurrent.ConcurrentNavigableMap<A,com.googlecode.cqengine.resultset.stored.StoredResultSet<O>>>,com.googlecode.cqengine.index.support.Factory<com.googlecode.cqengine.resultset.stored.StoredResultSet<O>>,com.googlecode.cqengine.attribute.Attribute<O,A>) is not applicable
(cannot infer type-variable(s) A,O
(actual and formal argument lists differ in length))
Probably, it's a lack of library design: LocalDate
implements ChronoLocalDate
that extends Comparable<ChronoLocalDate>
, it means that it's necessary to use wildcard bounds in generic method declaration. I guess, creating of LocalDate
wrapper that implements Comparable<>
is a workaround in this case.
Perhaps, there are some other solutions of this problem?