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

8
LINES

< > BotCompany Repo | #1027844 // nestedMapRemove - remove entry from map in map; remove inner map if empty

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

Libraryless. Click here for Pure Java version (2477L/16K).

1  
static <A, B, C> C nestedMapRemove(Map<A, Map<B, C>> map, A a, B b) {
2  
  if (map == null) null;
3  
  Map<B, C> map2 = map.get(a);
4  
  if (map2 == null) null;
5  
  C oldValue = map2.remove(b);
6  
  if (empty(map2)) map.remove(a);
7  
  ret oldValue;
8  
}

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: #1027844
Snippet name: nestedMapRemove - remove entry from map in map; remove inner map if empty
Eternal ID of this version: #1027844/1
Text MD5: f3b7ae624ea83bd6921f2a81bd2ffbdd
Transpilation MD5: 2e0163fe5c85eadfc6535c6fa39f2618
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-04-15 02:14:11
Source code size: 241 bytes / 8 lines
Pitched / IR pitched: No / No
Views / Downloads: 208 / 313
Referenced in: [show references]