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

28
LINES

< > BotCompany Repo | #1001974 - smartSet

JavaX fragment (include)

static void smartSet(Field f, O o, O value) throws Exception {
  try {
    f.set(o, value);
  } catch (Exception e) {
    Class type = f.getType();
    
    // take care of common case (long to int)
    if (type == int.class && value instanceof Long)
      value = ((Long) value).intValue();
    
    if (type == LinkedHashMap.class && value instanceof Map)
      ret with f.set(o, asLinkedHashMap((Map) value));
    
    ifclass Concept
      try {
        if (f.getType() == Concept.Ref.class) {
          f.set(o, ((Concept) o).new Ref((Concept) value));
          ret;
        }
        if (o instanceof Concept.Ref) {
          f.set(o, ((Concept.Ref) o).get());
          ret;
        }
      } catch {}
    endif
    throw e;
  }
}

download  show line numbers  debug dex   

Travelled to 14 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, ofpaelxlmzfo, onxytkatvevr, sawdedvomwva, tslmcundralx, tvejysmllsmz, wtqryiryparv

No comments. add comment

Snippet ID: #1001974
Snippet name: smartSet
Eternal ID of this version: #1001974/11
Text MD5: 6dba38071eaee8f4f7abc4fefbe68458
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-27 12:18:39
Source code size: 765 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 407 / 5196
Version history: 10 change(s)
Referenced in: [show references]