Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

45
LINES

< > BotCompany Repo | #1022312 // CalculatedConceptFieldIndex

JavaX fragment (include)

sclass CalculatedConceptFieldIndex<A extends Concept, Val> implements IConceptIndex {
  Class<A> cc;
  IF1<A, Val> f;
  new HashMap<A, Val> objectToValue;
  new MultiMap<Val, A> valueToObject;
  
  *() {}
  *(Class<A> cc, IF1<A, Val> f) { this(db_mainConcepts(), cc, f); }
  
  *(Concepts concepts, Class<A> *cc, IF1<A, Val> *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<A> getAll(Val value) {
    ret valueToObject.get(value);
  }
}

Author comment

Began life as a copy of #1014416

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1022312
Snippet name: CalculatedConceptFieldIndex
Eternal ID of this version: #1022312/7
Text MD5: 249ab17efcd8907307254b19f4ca3983
Author: stefan
Category: javax / concepts
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-03-13 06:12:09
Source code size: 1214 bytes / 45 lines
Pitched / IR pitched: No / No
Views / Downloads: 199 / 659
Version history: 6 change(s)
Referenced in: [show references]