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

56
LINES

< > BotCompany Repo | #1026155 // ConceptFieldIndexDesc - backup before MultiSetMap

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (13012L/87K).

1  
sclass ConceptFieldIndexDesc<A extends Concept, Val> implements IConceptIndex, IFieldIndex<A, Val> {
2  
  Class<A> cc;
3  
  S field;
4  
  new HashMap<A, Val> objectToValue;
5  
  MultiMap<Val, A> valueToObject;
6  
  
7  
  *() { valueToObject = treeMultiMap(reverseOrder()); }
8  
  *(Class<A> cc, S field) { this(mainConcepts, cc, field); }
9  
  *(Concepts concepts, Class<A> *cc, S *field) {
10  
    this();
11  
    concepts.addConceptIndex(this);
12  
    for (A c : list(concepts, cc))
13  
      updateImpl(c);
14  
    concepts.addFieldIndex(cc, field, this);
15  
  }
16  
  
17  
  public void update(Concept c) {
18  
    if (!isInstance(cc, c)) ret;
19  
    updateImpl(c);
20  
  }
21  
  
22  
  synchronized void updateImpl(Concept c) {
23  
    Val newValue = cast cget(c, field);
24  
    Val oldValue = objectToValue.get(c);
25  
    if (newValue == null || newValue != oldValue) {
26  
      valueToObject.remove(oldValue, (A) c);
27  
      valueToObject.put(newValue, (A) c);
28  
      objectToValue.put((A) c, newValue);
29  
    }
30  
  }
31  
  
32  
  public synchronized void remove(Concept c) {
33  
    if (!isInstance(cc, c)) ret;
34  
    Val value = cast cget(c, field);
35  
    objectToValue.remove(c);
36  
    valueToObject.remove(value, (A) c);
37  
  }
38  
  
39  
  synchronized A get(Val value) {
40  
    ret valueToObject.getFirst(value);
41  
  }
42  
  
43  
  public synchronized L<A> getAll(Val value) {
44  
    ret valueToObject.get(value);
45  
  }
46  
  
47  
  public synchronized L<Val> allValues() { ret cloneKeys_noSync(valueToObject.data); }
48  
  
49  
  IterableIterator<A> objectIterator() {
50  
    ret navigableMultiMapValuesIterator(valueToObject);
51  
  }
52  
  
53  
  public synchronized MultiSet<Val> allValues_multiSet() {
54  
    ret multiMapToMultiSet(valueToObject);
55  
  }
56  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1026155
Snippet name: ConceptFieldIndexDesc - backup before MultiSetMap
Eternal ID of this version: #1026155/1
Text MD5: 8ea85b576329ecc7e0bf77a7b856407f
Transpilation MD5: 3e5f49d95768da901cfb38bcae07593c
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-11-27 13:24:50
Source code size: 1652 bytes / 56 lines
Pitched / IR pitched: No / No
Views / Downloads: 196 / 287
Referenced in: [show references]