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

28
LINES

< > BotCompany Repo | #1006559 // convertToField - convert arbitrary value to fit a field

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

Transpiled version (9520L) is out of date.

static O convertToField(O o, Class c, S field) {
  Field f = setOpt_findField(c, field);
  if (f == null) ret o;
  Class t = f.getType();
  if (t == Long.class || t == long.class)
    ret toLong(o);
  else if (t == Int.class || t == int.class)
    ret toInt(o);
  else if (t == Float.class || t == float.class)
    ret toFloat(o);
  else if (t == Double.class || t == double.class)
    ret toDouble(o);
  else if (t == S.class)
    ret o cast S ? o : str(o);
  else if (t == File.class) {
    if (o cast S) ret new File(o).getAbsoluteFile();
  } else if (t == Pt.class) {
    if (o cast S) ret parsePt(o);
  } else if (t == Rect) {
    if (o cast S) ret parseRect(o);
  }
  
  ifclass GlobalID
    else if (t == GlobalID.class && o instanceof S)
      ret GlobalID((S) o);
  endif
  ret o;
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1006559
Snippet name: convertToField - convert arbitrary value to fit a field
Eternal ID of this version: #1006559/8
Text MD5: 6e44f7d63b647d6affb0ae4d237b9d9c
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-09-14 20:32:16
Source code size: 818 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 627 / 713
Version history: 7 change(s)
Referenced in: [show references]