1 | static class AIEngine {
|
2 | new L<S> sentences; |
3 | new Set<S> sentenceSet; |
4 | new Map<S, O> objects; |
5 | new IdentityHashMap<O, S> objectToID; |
6 | long objectIDCounter; |
7 | |
8 | S addObject(O o) {
|
9 | S id = objectToID.get(o); |
10 | if (id == null) {
|
11 | id = "o" + ++objectIDCounter; |
12 | objects.put(id, o); |
13 | objectToID.put(o, id); |
14 | } |
15 | return id; |
16 | } |
17 | |
18 | S remember(S sentence) {
|
19 | if (!sentenceSet.contains(sentence)) {
|
20 | sentenceSet.add(sentence); |
21 | sentences.add(sentence); |
22 | return addObject(sentence); |
23 | } |
24 | return null; |
25 | } |
26 | |
27 | void show() {
|
28 | for (S s : sentences) |
29 | print(" " + s);
|
30 | } |
31 | |
32 | <A> A findObjectOfType(Class<A> c) {
|
33 | for (O o : objects.values()) |
34 | if (o.getClass() == c) |
35 | return (A) o; |
36 | return null; |
37 | } |
38 | } |
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: | #1001107 |
| Snippet name: | class AIEngine |
| Eternal ID of this version: | #1001107/1 |
| Text MD5: | 11a739dfe06c6e0366a7c9ddc68799f1 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-09-21 17:51:36 |
| Source code size: | 808 bytes / 38 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 865 / 1092 |
| Referenced in: | [show references] |