1 | sclass CalculatedConceptFieldIndex<A extends Concept, Val> implements IConceptIndex { |
2 | Class<A> cc; |
3 | IF1<A, Val> f; |
4 | new HashMap<A, Val> objectToValue; |
5 | new MultiMap<Val, A> valueToObject; |
6 | |
7 | *() {} |
8 | *(Class<A> cc, IF1<A, Val> f) { this(db_mainConcepts(), cc, f); } |
9 | |
10 | *(Concepts concepts, Class<A> *cc, IF1<A, Val> *f) { |
11 | concepts.addConceptIndex(this); |
12 | for (A c : list(concepts, cc)) |
13 | updateImpl(c); |
14 | } |
15 | |
16 | public void update(Concept c) { |
17 | if (!isInstance(cc, c)) ret; |
18 | updateImpl((A) c); |
19 | } |
20 | |
21 | synchronized void updateImpl(A c) { |
22 | Val newValue = callF(f, c); |
23 | Val oldValue = objectToValue.get(c); |
24 | if (neq(newValue, oldValue)) { |
25 | valueToObject.remove(oldValue, (A) c); |
26 | valueToObject.put(newValue, (A) c); |
27 | objectToValue.put((A) c, newValue); |
28 | } |
29 | } |
30 | |
31 | public synchronized void remove(Concept c) { |
32 | if (!isInstance(cc, c)) ret; |
33 | Val value = callF(f, (A) c); |
34 | objectToValue.remove(c); |
35 | valueToObject.remove(value, (A) c); |
36 | } |
37 | |
38 | synchronized A get(Val value) { |
39 | ret valueToObject.getFirst(value); |
40 | } |
41 | |
42 | public synchronized L<A> getAll(Val value) { |
43 | ret valueToObject.get(value); |
44 | } |
45 | } |
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: | 264 / 731 |
Version history: | 6 change(s) |
Referenced in: | [show references] |