Libraryless. Click here for Pure Java version (4091L/26K).
1 | sclass SimpleFactStore implements IFactStore { |
2 | L<Fact> facts = synchroList(); |
3 | transient bool verbose; |
4 | transient L<Runnable> onChange = syncList(); |
5 | |
6 | sclass Fact extends HasGlobalID { |
7 | long created = now(); |
8 | S text; |
9 | |
10 | *() {} |
11 | *(S *text) {} |
12 | |
13 | toString { ret text; } |
14 | } |
15 | |
16 | public void store(S fact) { |
17 | if (!any(facts, f -> eqic(f.text, fact))) { |
18 | facts.add(new Fact(fact)); |
19 | pcallFAll(onChange); |
20 | } |
21 | } |
22 | |
23 | public void deleteAll(IPred<S> filter) { |
24 | for (Fact f : cloneList(facts)) |
25 | if (filter.get(f.text)) { |
26 | if (verbose) |
27 | print("Deleting fact: " + f); |
28 | facts.remove(f); |
29 | pcallFAll(onChange); |
30 | } |
31 | } |
32 | |
33 | public LS facts() { ret map(facts, f -> f.text); } |
34 | |
35 | toString { |
36 | ret sfu(this); |
37 | } |
38 | |
39 | void onChange(Runnable r) { onChange.add(r); } |
40 | |
41 | void clear { facts.clear(); pcallFAll(onChange); } |
42 | } |
Began life as a copy of #1025750
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: | #1025752 |
Snippet name: | SimpleFactStore |
Eternal ID of this version: | #1025752/9 |
Text MD5: | ae98268a85fb2c5eb64a19fe2ad9b030 |
Transpilation MD5: | 51dcb4c293d13e872632f28ed569674f |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-10-17 23:48:59 |
Source code size: | 937 bytes / 42 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 233 / 663 |
Version history: | 8 change(s) |
Referenced in: | [show references] |