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

78
LINES

< > BotCompany Repo | #1032783 // ConceptFieldIndexBase_certainValues

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

Libraryless. Click here for Pure Java version (18627L/114K).

1  
asclass ConceptFieldIndexBase_certainValues<A extends Concept, Val> implements IConceptIndex, IPartialFieldIndex<A, Val> {
2  
  Concepts concepts;
3  
  Class<A> cc;
4  
  S field;
5  
  Map<A, Val> objectToValue = syncHashMap();
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  
  public abstract bool isApplicableValue(Val value);
21  
22  
  public void update(Concept c) {
23  
    if (!isInstance(cc, c)) ret;
24  
    updateImpl((A) c);
25  
  }
26  
  
27  
  synchronized void updateImpl(A c) {
28  
    Val newValue = cast cget(c, field);
29  
    Val oldValue = objectToValue.get(c);
30  
    if (newValue == oldValue && (oldValue != null || objectToValue.containsKey(c))) ret;
31  
    valueToObject.remove(oldValue, c);
32  
    if (isApplicableValue(newValue)) {
33  
      valueToObject.put(newValue, c);
34  
      put(objectToValue, c, newValue);
35  
    } else
36  
      main remove(objectToValue, c);
37  
  }
38  
  
39  
  public synchronized void remove(Concept c) {
40  
    if (!isInstance(cc, c)) ret;
41  
    if (!objectToValue.containsKey(c)) ret;
42  
    Val value = objectToValue.get(c);
43  
    objectToValue.remove(c);
44  
    valueToObject.remove(value, (A) c);
45  
  }
46  
  
47  
  synchronized A get(Val value) {
48  
    ret valueToObject.getFirst(value);
49  
  }
50  
  
51  
  // older version - may return empty list as null
52  
  // should be phased out everywhere!
53  
  public synchronized Cl<A> getAll(Val value) {
54  
    ret valueToObject.get(value);
55  
  }
56  
  
57  
  // newer version - returns null iff it's not applicable
58  
  public synchronized Cl<A> getAllIfApplicable(Val value) {
59  
    if (!isApplicableValue(value)) null;
60  
    ret unnullForIteration(valueToObject.get(value));
61  
  }
62  
  
63  
  public synchronized L<Val> allValues() { ret cloneKeys_noSync(valueToObject.data); }
64  
  
65  
  IterableIterator<A> objectIterator() {
66  
    ret navigableMultiSetMapValuesIterator_concurrent(valueToObject, this);
67  
  }
68  
  
69  
  public synchronized MultiSet<Val> allValues_multiSet() {
70  
    ret multiSetMapToMultiSet(valueToObject);
71  
  }
72  
  
73  
  public Class<? extends Concept> conceptClass() { ret cc; }
74  
  public int countConcepts() { ret l(objectToValue); }
75  
  public Cl<Concept> allConcepts() { ret (Cl) keys(objectToValue); }
76  
  
77  
  O mutex() { this; }
78  
}

Author comment

Began life as a copy of #1031103

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1032783
Snippet name: ConceptFieldIndexBase_certainValues
Eternal ID of this version: #1032783/4
Text MD5: ab7a32a14d2d37220310e81fa28f098a
Transpilation MD5: 5cd5786f5f75567b9d33761a0d146bdb
Author: stefan
Category: javax / concepts
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-06 04:25:18
Source code size: 2492 bytes / 78 lines
Pitched / IR pitched: No / No
Views / Downloads: 97 / 190
Version history: 3 change(s)
Referenced in: [show references]