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

80
LINES

< > BotCompany Repo | #1003041 // Rain / Coat (Vessel)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1059L/7K/24K).

1  
!752
2  
3  
sclass Vessel {
4  
  new L<S> data;
5  
  int index;
6  
7  
  *() {}
8  
  *(L<S> *data, int *index) {}
9  
10  
  void add(S s) {
11  
    data.add(simplify(s));
12  
  }
13  
14  
  bool consume(S s) {
15  
    if (end()) ret false;
16  
    
17  
    s = simplify(s);
18  
    
19  
    /*if (same(next(), s)) {
20  
      ++index;
21  
      ret true;
22  
    }
23  
    ret false;*/
24  
    
25  
    //++index;
26  
    
27  
    if (!same(next(), s)) {
28  
      --index;
29  
      ret false;
30  
    }
31  
    ret true;
32  
  }
33  
34  
  void restart() {
35  
    index = 0;
36  
  }
37  
38  
  // may be null if index after end
39  
  S next() {
40  
    ret end() ? null : get(data, index++);
41  
  }
42  
  
43  
  bool end() {
44  
    ret index >= l(data);
45  
  }
46  
47  
  public Vessel clone() {
48  
    ret new Vessel(cloneList(data), index);
49  
  }
50  
}
51  
52  
static S simplify(S s) {
53  
  ret s.trim().toUpperCase();
54  
}
55  
56  
static bool same(S a, S b) {
57  
  ret eq(a, b);
58  
}
59  
60  
static new L<Vessel> vessels;
61  
62  
p {
63  
  new Vessel v;
64  
  v.add("There is RAIN");
65  
  v.add("I need a COAT");
66  
  vessels.add(v);
67  
}
68  
69  
synchronized answer {
70  
  if (!tb()) null;
71  
  
72  
  for (Vessel v : vessels) {
73  
    if (v.consume(s)) {
74  
      S answer = v.next();
75  
      v.restart();
76  
      if (nempty(answer))
77  
        ret answer;
78  
    }
79  
  }
80  
}

Author comment

Began life as a copy of #1003040

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: #1003041
Snippet name: Rain / Coat (Vessel)
Eternal ID of this version: #1003041/1
Text MD5: 2b758d5e374a508cf6fdf14b73c47a37
Transpilation MD5: dba08909d2457b46d152f8d179569031
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-04-24 03:07:16
Source code size: 1188 bytes / 80 lines
Pitched / IR pitched: No / No
Views / Downloads: 555 / 607
Referenced in: [show references]