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

53
LINES

< > BotCompany Repo | #1015833 // Google (Dyn Module, v1, old)

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

Download Jar. Libraryless. Click here for Pure Java version (9733L/70K).

1  
!7
2  
3  
static S query;
4  
static L<SS> result;
5  
static volatile bool calculating;
6  
static NotTooOften notTooOften = onlyEvery10Secs();
7  
static WaitForStableValue<S> waitForStableValue = new(5.0);
8  
static Q q;
9  
static int maxInputLength = 120;
10  
11  
static transient JTable table;
12  
static transient ReliableSingleThread rst;
13  
14  
static JComponent visualize() { ret dataToTable_uneditable(result, table = sexyTable()); }
15  
static void unvisualize2() { table = null; }  
16  
17  
p {
18  
  q = startQ();
19  
  doEvery(1000, r update);
20  
}
21  
22  
svoid update {
23  
  lock programLock();
24  
  S s = (S) callOpt(creator(), 'getInterestingString);
25  
  if (nempty(s) && l(s) <= maxInputLength) { // TODO: more quality checks?
26  
    waitForStableValue.set(s);
27  
  }
28  
  
29  
  fS q = waitForStableValue!;
30  
  if (nempty(q) && neq(q, query) && allowedToGoogleSomething())
31  
    main.q.add(r { calc(q) });
32  
}
33  
34  
static void calc(S q) {
35  
  if (eq(query, q)) ret;
36  
  query = q; result = null;
37  
  calculating = true;
38  
  try {
39  
    L<T3<S>> l = quickGoogle2(q);
40  
    result = map(l, func(T3<S> t) -> SS {
41  
      litorderedmap("Result" := second(t), "Desc" := third(t), "Link" := first(t))
42  
    });
43  
    JTable t = table;
44  
    if (t != null)
45  
      dataToTable_uneditable(result, t);
46  
  } finally {
47  
    calculating = false;
48  
  }
49  
}
50  
51  
sbool allowedToGoogleSomething() {
52  
  ret notTooOften.canDoAgain_willDoIfTrue();
53  
}

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: #1015833
Snippet name: Google (Dyn Module, v1, old)
Eternal ID of this version: #1015833/27
Text MD5: 7895c86f200e13e50f4eaadd906852ab
Transpilation MD5: cef0ba1542d65e3dbfd308472dcc63e5
Author: stefan
Category:
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-06-01 00:10:58
Source code size: 1367 bytes / 53 lines
Pitched / IR pitched: No / No
Views / Downloads: 357 / 1109
Version history: 26 change(s)
Referenced in: [show references]