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

33
LINES

< > BotCompany Repo | #1026010 // _cSmartSetField - kinda duplicated in convertToField

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

Libraryless. Click here for Pure Java version (13251L/90K).

// returns true if change
// DUPLICATED in convertToField AND DefaultValueConverterForField...
sbool _cSmartSetField(Concept c, S field, O value) ctex {
  Field f = setOpt_findField(c.getClass(), field);
  if (f != null && value != null) {
    Class actualType = f.getType();
    Class type = primitiveToBoxedTypeOpt(actualType);
    
    // int magic
    
    if (type == Int.class && !value instanceof Int) {
      if (!setField_trueIfChanged(f, c, toInt(trimIfString(value)))) false;
      if (!isTransient(f)) c.change();
      true;
    }
    
    // bool magic
    
    if (type == Bool.class && value instanceof S)
      if (actualType == Bool.class && eq(value, ""))
        ret _csetField(c, field, null);
      else
        ret _csetField(c, field, eqicOneOf((S) value, "1", "true", "yes"));

    // GlobalID magic
    
    ifclass GlobalID
    if (type == GlobalID.class && value instanceof S)
      ret _csetField(c, field, GlobalID((S) value));
    endif
  }
  ret _csetField(c, field, value);
}

Author comment

Began life as a copy of #1026007

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1026010
Snippet name: _cSmartSetField - kinda duplicated in convertToField
Eternal ID of this version: #1026010/10
Text MD5: 6b9947932d30cde76b51b3acae81e664
Transpilation MD5: b1e40330b244334f7f76ae24b8aa676e
Author: stefan
Category: javax / concepts
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-09-27 16:40:29
Source code size: 1040 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 229 / 370
Version history: 9 change(s)
Referenced in: [show references]