sclass CalculatedConceptFieldIndex implements IConceptIndex {
Class cc;
IF1 f;
new HashMap objectToValue;
new MultiMap valueToObject;
*() {}
*(Class cc, IF1 f) { this(db_mainConcepts(), cc, f); }
*(Concepts concepts, Class *cc, IF1 *f) {
concepts.addConceptIndex(this);
for (A c : list(concepts, cc))
updateImpl(c);
}
public void update(Concept c) {
if (!isInstance(cc, c)) ret;
updateImpl((A) c);
}
synchronized void updateImpl(A c) {
Val newValue = callF(f, c);
Val oldValue = objectToValue.get(c);
if (neq(newValue, oldValue)) {
valueToObject.remove(oldValue, (A) c);
valueToObject.put(newValue, (A) c);
objectToValue.put((A) c, newValue);
}
}
public synchronized void remove(Concept c) {
if (!isInstance(cc, c)) ret;
Val value = callF(f, (A) c);
objectToValue.remove(c);
valueToObject.remove(value, (A) c);
}
synchronized A get(Val value) {
ret valueToObject.getFirst(value);
}
public synchronized L getAll(Val value) {
ret valueToObject.get(value);
}
}