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

48
LINES

< > BotCompany Repo | #1016241 // Universal Search [Dyn Module, dev.]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Libraryless. Click here for Pure Java version (15035L/106K).

!7

sclass UniversalSearch extends DynModule {
  S query;
  transient L<SS> result;
  
  transient Q q;
  transient int maxInputLength = 120;
  transient WaitForStableValue<S> waitForStableValue = new(1.0);
  transient volatile bool calculating;
  transient JTable table;
  transient SimpleLiveValue<S> lvQuery = stringLiveValue();
  
  JComponent visualize() {
    ret jLiveValueSection(lvQuery, dataToTable_uneditable(result, table = sexyTable()));
  }
  
  void unvisualize() { table = null; }  
  
  void start {
    lvQuery.set(query);
    q = startQ();
    ownTimer(doEvery(1000, r updateMe));
  }
  
  void update {
    S s = dm_getInterestingString();
    if (nempty(s) && l(s) <= maxInputLength) { // TODO: more quality checks?
      waitForStableValue.set(s);
    }
    
    fS q = waitForStableValue!;
    if (nempty(q) && neq(q, query))
      this.q.add(r { calc(q) });
  }
  
  void calc(S q) {
    if (eq(query, q)) ret;
    result = null;
    lvQuery.set(query = q);
    temp tempSetField(this, calculating := true);
    L<Pair<O, S>> l = dm_universalSearch(q);
    result = map(l, func(Pair<O, S> p) -> SS {
      litorderedmap("Result" := str(first(p)), "From Module" := second(p))
    });
    dataToTable_uneditable_ifHasTable(result, table);
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1016241
Snippet name: Universal Search [Dyn Module, dev.]
Eternal ID of this version: #1016241/4
Text MD5: c833d3aa768f58ce4b292dfe7ff8df52
Transpilation MD5: 1fab6eeaa340f5ee7e6e8741b5b1a781
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-06-11 20:00:40
Source code size: 1313 bytes / 48 lines
Pitched / IR pitched: No / No
Views / Downloads: 283 / 358
Version history: 3 change(s)
Referenced in: [show references]