1 | // a persistent list that only grows (or is clear()ed) |
2 | // Note: don't put in static initializer (programID not set yet) |
3 | static class PersistentLog<A> extends AbstractList<A> { |
4 | new L<A> l; |
5 | File file; |
6 | |
7 | PersistentLog(S fileName) { |
8 | this(getProgramFile(fileName)); |
9 | } |
10 | |
11 | PersistentLog(S progID, S fileName) { |
12 | this(getProgramFile(progID, fileName)); |
13 | } |
14 | |
15 | *(File *file) { |
16 | for (S s : scanLog(file)) pcall { |
17 | l.add((A) unstructure(s)); |
18 | } |
19 | } |
20 | |
21 | public synchronized int size() { |
22 | ret l.size(); |
23 | } |
24 | |
25 | public synchronized A get(int i) { |
26 | ret l.get(i); |
27 | } |
28 | |
29 | public synchronized bool add(A a) { |
30 | l.add(a); |
31 | logQuoted(file, structure(a)); |
32 | ret true; |
33 | } |
34 | |
35 | S fileContents() { |
36 | ret loadTextFile(file); |
37 | } |
38 | |
39 | public synchronized void clear() { |
40 | l.clear(); |
41 | file.delete(); |
42 | } |
43 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1001972 |
Snippet name: | PersistentLog (synchronized) |
Eternal ID of this version: | #1001972/1 |
Text MD5: | a5c8704e7f65abed300bd0a1481e8786 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-04-28 17:47:01 |
Source code size: | 876 bytes / 43 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 741 / 2269 |
Referenced in: | [show references] |