Libraryless. Click here for Pure Java version (12615L/85K).
1 | sclass ConceptFieldIndexCI<A extends Concept> implements IConceptIndex, IFieldIndex<A, S>, IConceptCounter { |
2 | Class<A> cc; |
3 | S field; |
4 | new HashMap<A, S> objectToValue; |
5 | MultiMap<S, A> valueToObject = ciMultiMap(); |
6 | |
7 | *() {} |
8 | *(Class<A> cc, S field) { this(db_mainConcepts(), cc, field); } |
9 | *(Concepts concepts, Class<A> *cc, S *field) { |
10 | concepts.addConceptIndex(this); |
11 | for (A c : list(concepts, cc)) |
12 | updateImpl(c); |
13 | concepts.addCIFieldIndex(cc, field, this); |
14 | } |
15 | |
16 | public void update(Concept c) { |
17 | if (!isInstance(cc, c)) ret; |
18 | updateImpl(c); |
19 | } |
20 | |
21 | synchronized void updateImpl(Concept c) { |
22 | S newValue = cast cget(c, field); |
23 | S oldValue = objectToValue.get(c); |
24 | if (newValue == null || 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 | S value = cast cget(c, field); |
34 | objectToValue.remove(c); |
35 | valueToObject.remove(value, (A) c); |
36 | } |
37 | |
38 | synchronized A get(S value) { |
39 | ret valueToObject.getFirst(value); |
40 | } |
41 | |
42 | public synchronized L<A> getAll(S value) { |
43 | ret valueToObject.get(value); |
44 | } |
45 | |
46 | public Class<? extends Concept> conceptClass() { ret cc; } |
47 | public int countConcepts() { ret l(objectToValue); } |
48 | |
49 | // Note: NOT SORTED |
50 | public Collection<Concept> allConcepts() { ret (Collection) keys(objectToValue); } |
51 | |
52 | public synchronized LS allValues() { ret cloneKeys_noSync(valueToObject.data); } |
53 | |
54 | public synchronized MultiSet<S> allValues_multiSet() { |
55 | ret multiMapToMultiSet(valueToObject); |
56 | } |
57 | |
58 | // SORTED |
59 | IterableIterator<A> objectIterator() { |
60 | ret navigableMultiMapValuesIterator(valueToObject); |
61 | } |
62 | } |
Began life as a copy of #1014416
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: | #1024457 |
Snippet name: | ConceptFieldIndexCI - backup before MultiSetMap |
Eternal ID of this version: | #1024457/1 |
Text MD5: | 5aa44d3899059a57a7cf87a37973f24c |
Transpilation MD5: | 3b8f70d250d848cf99322cf644e37c63 |
Author: | stefan |
Category: | javax / concepts |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-08-13 12:10:24 |
Source code size: | 1850 bytes / 62 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 229 / 332 |
Referenced in: | [show references] |