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

17
LINES

< > BotCompany Repo | #1002178 // copyFields - now uses setOpt

JavaX fragment (include)

static <A> A copyFields(O x, A y, S... fields) {
  if (empty(fields)) { // assume we should copy all fields
    Map<S, O> map = objectToMap(x);
    for (S field : map.keySet())
      setOpt(y, field, map.get(field));
  } else 
    for (S field : fields) {
      O o = getOpt(x, field);
      if (o != null)
        setOpt(y, field, o);
    }
  ret y;
}

static <A> A copyFields(O x, A y, Collection<S> fields) {
  ret copyFields(x, y, asStringArray(fields));
}

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: #1002178
Snippet name: copyFields - now uses setOpt
Eternal ID of this version: #1002178/3
Text MD5: 23380a7f211e585c1880c4122c3c343e
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-17 17:14:43
Source code size: 476 bytes / 17 lines
Pitched / IR pitched: No / No
Views / Downloads: 757 / 1031
Version history: 2 change(s)
Referenced in: [show references]