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

42
LINES

< > BotCompany Repo | #1000989 // class SnippetDB (snapshot of snippet DB in memory)

JavaX fragment (include)

static class SnippetDB {
  static List<S> fields;
  static List<List<S>> rows;
  
  *() {}
  
  *(S snippetIDOfGzippedMysqlDump) {
    importMySQLDump(gunzipToText(snippetIDOfGzippedMysqlDump));
  }
  
  void importMySQLDump(String dump) {
    System.out.println("Importing " + dump.length() + " chars.");
    Class importer = hotwire("#1000660");
    set(importer, "in", dump);
    callMain(importer);
    Map<String, List> tables = (Map) get(importer, "tables");
    Map<String, List> tableFields = (Map) get(importer, "tableFields");
    fields = tableFields.get("snippets_public");
    rows = tables.get("snippets_public");
  }
  
  S getField(List<S> row, S field) {
    int i = fields.indexOf(field);
    return i < 0 ? null : row.get(i);
  }
  
  List<List<S>> rowsOrderedBy(S field) {
    final int i = fields.indexOf(field);
    List<List<S>> list = new ArrayList<List<S>>(rows);
    sort(list, new Comparator<List<S>>() {
      public int compare(List<S> rowA, List<S> rowB) {
        S a = rowA.get(i), b = rowB.get(i);
        return a.compareTo(b);
      }
    });      
    return list;
  }
  
  public void finalize() {
    System.err.println("Note: SnippetDB released from memory.");
  }
}

Author comment

Began life as a copy of #1000678

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: #1000989
Snippet name: class SnippetDB (snapshot of snippet DB in memory)
Eternal ID of this version: #1000989/1
Text MD5: 8cef8825fd15e40f67288d860a5f4d60
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-09-15 18:14:59
Source code size: 1246 bytes / 42 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 522 / 1969
Referenced in: [show references]