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

10
LINES

< > BotCompany Repo | #1019369 // zeroAllFieldsOfTypeExcept - set all fields with a value of a certain type to null

JavaX fragment (include)

static void zeroAllFieldsOfTypeExcept(O o, Class type, S... exceptions) {
  zeroAllFieldsOfTypeExcept(o, type, asSet(exceptions));
}

static void zeroAllFieldsOfTypeExcept(O o, Class type, Collection<S> exceptions) {
  Set<S> set = asSet(exceptions);
  for (S field : allFields(o))
    if (!set.contains(field) && instanceOf(getOpt(o, field), type))
      set(o, field, null);
}

Author comment

Began life as a copy of #1016358

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1019369
Snippet name: zeroAllFieldsOfTypeExcept - set all fields with a value of a certain type to null
Eternal ID of this version: #1019369/2
Text MD5: 1b5581db64cf2da6ec17c1ccebd1240b
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-11-04 19:13:34
Source code size: 387 bytes / 10 lines
Pitched / IR pitched: No / No
Views / Downloads: 241 / 278
Version history: 1 change(s)
Referenced in: [show references]