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

43
LINES

< > BotCompany Repo | #1001984 // dataToTable_makeRow

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (5942L/35K).

1  
static ThreadLocal<Bool> dataToTable_useStruct = threadLocalWithDefault(true);
2  
3  
static void dataToTable_dynSet(L l, int i, O s) {
4  
  while (i >= l.size()) l.add("");
5  
  l.set(i, s);
6  
}
7  
8  
static L dataToTable_makeRow(O x, L<S> cols) {
9  
  if (instanceOf(x, "DynamicObject"))
10  
    x = get_raw(x, "fieldValues");
11  
12  
  if (x instanceof Map) {
13  
    Map m = cast x;
14  
    new L row;
15  
    for (O _field : keysWithoutHidden(m)) {
16  
      S field = cast _field;
17  
      O value = m.get(field);
18  
      int col = cols.indexOf(field);
19  
      if (col < 0) {
20  
        cols.add(field);
21  
        col = cols.size()-1;
22  
      }
23  
      dataToTable_dynSet(row, col, dataToTable_wrapValue(value));
24  
    }
25  
    ret row;
26  
  }
27  
  
28  
  // XXX new
29  
  if (x cast L)
30  
    ret allToString(x);
31  
    
32  
  ret litlist(structureOrText(x));
33  
}
34  
35  
static O dataToTable_wrapValue(O o) {
36  
  if (o instanceof BufferedImage) ret o;
37  
  if (o cast MakesBufferedImage) ret o.getBufferedImage();
38  
  ifclass RGBImage
39  
    if (o instanceof RGBImage) ret o; // huh?
40  
  endif
41  
  if (o instanceof Bool) ret o;
42  
  ret dataToTable_useStruct! ? structureOrTextForUser(o) : strOrNull(o);
43  
}

Author comment

Began life as a copy of #1001613

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1001984
Snippet name: dataToTable_makeRow
Eternal ID of this version: #1001984/9
Text MD5: 4c87fa222d8ed79780df7c658fed8db3
Transpilation MD5: d588f69bfb6862cf30f4841d54062034
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-12 04:27:39
Source code size: 1135 bytes / 43 lines
Pitched / IR pitched: No / No
Views / Downloads: 797 / 1437
Version history: 8 change(s)
Referenced in: [show references]