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

14
LINES

< > BotCompany Repo | #1002467 // indexByField - returns HashMap. doesn't store null values

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

Libraryless. Click here for Pure Java version (2136L/14K).

1  
// does not store null values
2  
static Map indexByField(Iterable c, S field) {
3  
  new HashMap map;
4  
  for (O a : c) {
5  
    O val = getOpt(a, field);
6  
    if (val != null)
7  
      map.put(val, a);
8  
  }
9  
  ret map;
10  
}
11  
12  
static Map mapMethodLike indexByField(S field, Iterable c) {
13  
  ret indexByField(c, field);
14  
}

Author comment

Began life as a copy of #1002318

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: #1002467
Snippet name: indexByField - returns HashMap. doesn't store null values
Eternal ID of this version: #1002467/5
Text MD5: 393325eed264686cbe7de118c03c4b58
Transpilation MD5: 8050fdd5300932e630c8ea8ed04b1299
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-02-28 15:12:27
Source code size: 311 bytes / 14 lines
Pitched / IR pitched: No / No
Views / Downloads: 865 / 905
Version history: 4 change(s)
Referenced in: [show references]