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

30
LINES

< > BotCompany Repo | #1002628 // manageStringList - convenient way of managing a list of unchecked strings

JavaX fragment (include)

1  
static synchronized S manageStringList(S s, S name, S varName, boolean canChange) {
2  
  L<S> list = (L) get(main.class, varName);
3  
  new Matches m;
4  
  
5  
  if (match("list " + plural(name), s))
6  
    ret structure(list);
7  
    
8  
  if (match("how many " + plural(name), s))
9  
    ret str(l(list));
10  
    
11  
  if (match("add " + name + " *", s, m)) {
12  
    if (!canChange) ret "Sorry. Not authorized";
13  
    S id = m.unq(0);
14  
    list.add(id);
15  
    save(varName);
16  
    ret "OK, " + name + " " + quote(id) + " added. List size now: " + l(list);
17  
  }
18  
  
19  
  if (match("remove " + name + " *", s, m)) {
20  
    if (!canChange) ret "Sorry. Not authorized";
21  
    S id = m.unq(0);
22  
    int idx = list.indexOf(id);
23  
    if (idx < 0) ret id + " is not a " + name;
24  
    list.remove(idx);
25  
    save(varName);
26  
    ret "OK, " + name + " " + quote(id) + " removed. List size now: " + l(list);
27  
  }
28  
  
29  
  ret null;
30  
}

Author comment

Began life as a copy of #1002457

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: #1002628
Snippet name: manageStringList - convenient way of managing a list of unchecked strings
Eternal ID of this version: #1002628/1
Text MD5: d0697e97e8d5fa512d261e8eba553eea
Author: stefan
Category: eleu
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-02-06 03:20:32
Source code size: 893 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 707 / 635
Referenced in: [show references]