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

66
LINES

< > BotCompany Repo | #1031515 // ConceptFieldIndexBase (backup)

JavaX fragment (include)

1  
asclass ConceptFieldIndexBase<A extends Concept, Val> implements IConceptIndex, IFieldIndex<A, Val>, IConceptCounter {
2  
  Concepts concepts;
3  
  Class<A> cc;
4  
  S field;
5  
  new HashMap<A, Val> objectToValue;
6  
  MultiSetMap<Val, A> valueToObject; // initialized in subclass
7  
  
8  
  *() { init(); }
9  
  *(Class<A> cc, S field) { this(db_mainConcepts(), cc, field); }
10  
  *(Concepts *concepts, Class<A> *cc, S *field) {
11  
    this();
12  
    concepts.addConceptIndex(this);
13  
    for (A c : list(concepts, cc))
14  
      updateImpl(c);
15  
    register();
16  
  }
17  
  
18  
  abstract void init();
19  
  abstract void register();
20  
  
21  
  public void update(Concept c) {
22  
    if (!isInstance(cc, c)) ret;
23  
    updateImpl(c);
24  
  }
25  
  
26  
  synchronized void updateImpl(Concept c) {
27  
    Val newValue = cast cget(c, field);
28  
    Val oldValue = objectToValue.get(c);
29  
    if (newValue == null || newValue != oldValue) {
30  
      valueToObject.remove(oldValue, (A) c);
31  
      valueToObject.put(newValue, (A) c);
32  
      syncPut(objectToValue, (A) c, newValue);
33  
    }
34  
  }
35  
  
36  
  public synchronized void remove(Concept c) {
37  
    if (!isInstance(cc, c)) ret;
38  
    Val value = cast cget(c, field);
39  
    syncRemove(objectToValue, (A) c);
40  
    valueToObject.remove(value, (A) c);
41  
  }
42  
  
43  
  synchronized A get(Val value) {
44  
    ret valueToObject.getFirst(value);
45  
  }
46  
  
47  
  public synchronized Cl<A> getAll(Val value) {
48  
    ret valueToObject.get(value);
49  
  }
50  
  
51  
  public synchronized L<Val> allValues() { ret cloneKeys_noSync(valueToObject.data); }
52  
  
53  
  IterableIterator<A> objectIterator() {
54  
    ret navigableMultiSetMapValuesIterator_concurrent(valueToObject, this);
55  
  }
56  
  
57  
  public synchronized MultiSet<Val> allValues_multiSet() {
58  
    ret multiSetMapToMultiSet(valueToObject);
59  
  }
60  
  
61  
  public Class<? extends Concept> conceptClass() { ret cc; }
62  
  public int countConcepts() { ret l(objectToValue); }
63  
  public Cl<Concept> allConcepts() { ret (Cl) keys(objectToValue); }
64  
  
65  
  O mutex() { this; }
66  
}

Author comment

Began life as a copy of #1031103

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1031515
Snippet name: ConceptFieldIndexBase (backup)
Eternal ID of this version: #1031515/1
Text MD5: 67a2f0c6b2c05d4d4be4a0a5724043f1
Author: stefan
Category: javax / concepts
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-17 07:15:08
Source code size: 1976 bytes / 66 lines
Pitched / IR pitched: No / No
Views / Downloads: 78 / 108
Referenced in: [show references]