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

53
LINES

< > BotCompany Repo | #1001495 // AList (a synchronized object list with history)

JavaX fragment (include)

1  
!include #1001196 // Lisp
2  
3  
static class AList<A> implements Iterable<A> {
4  
  new L<A> data; // don't access this from outside
5  
  
6  
  // these are ok to access (but not change) from outside
7  
  final S id = randomID(8);
8  
  final L<Lisp> history = synchroList();
9  
  
10  
  public synchronized void add(A a) {
11  
    data.add(a);
12  
    history.add(lisp("add", structure(a)));
13  
  }
14  
  
15  
  public synchronized void clear() {
16  
    data.clear();
17  
    history.add(lisp("clear"));
18  
  }
19  
  
20  
  public synchronized void remove(int i) {
21  
    data.remove(i);
22  
    history.add(lisp("remove", "" + i));
23  
  }
24  
  
25  
  public synchronized void remove(A a) {
26  
    int i = data.indexOf(a);
27  
    if (i >= 0) remove(i);
28  
  }
29  
  
30  
  public synchronized int indexOf(A a) {
31  
    return data.indexOf(a);
32  
  }
33  
  
34  
  public synchronized A get(int i) {
35  
    return data.get(i);
36  
  }
37  
  
38  
  public S getID() {
39  
    return id;
40  
  }
41  
  
42  
  public synchronized int size() {
43  
    return data.size();
44  
  }
45  
  
46  
  public synchronized Iterator<A> iterator() {
47  
    ret new ArrayList<A>(data).iterator();
48  
  }
49  
  
50  
  public synchronized List<A> shoot() {
51  
    ret new ArrayList<A>(data);
52  
  }
53  
}

Author comment

Began life as a copy of #1001414

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001495
Snippet name: AList (a synchronized object list with history)
Eternal ID of this version: #1001495/1
Text MD5: 8ec9f01afcc0ce6630453be106f5bca6
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-10-20 23:50:49
Source code size: 1152 bytes / 53 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 617 / 775
Referenced in: [show references]