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

45
LINES

< > BotCompany Repo | #1001414 // SList (a synchronized string list with history)

JavaX fragment (include)

!include #1001196 // Lisp

static class SList {
  new L<S> data; // don't access this from outside
  
  // these are ok to access (but not change) from outside
  final S id = randomID(8);
  final L<Lisp> history = synchroList();
  
  public synchronized void add(S a) {
    data.add(a);
    history.add(lisp("add", a));
  }
  
  public synchronized void clear() {
    data.clear();
    history.add(lisp("clear"));
  }
  
  public synchronized void remove(int i) {
    data.remove(i);
    history.add(lisp("remove", "" + i));
  }
  
  public synchronized void remove(S s) {
    int i = data.indexOf(s);
    if (i >= 0) remove(i);
  }
  
  public synchronized int indexOf(S s) {
    return data.indexOf(s);
  }
  
  public synchronized S get(int i) {
    return data.get(i);
  }
  
  public S getID() {
    return id;
  }
  
  public synchronized int size() {
    return data.size();
  }
}

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: #1001414
Snippet name: SList (a synchronized string list with history)
Eternal ID of this version: #1001414/1
Text MD5: 06b8da37a2ae0db2e4084d789c8b2bdd
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-10-15 18:18:42
Source code size: 931 bytes / 45 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 602 / 831
Referenced in: #1001415 - Test SList
#1001495 - AList (a synchronized object list with history)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)