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

30
LINES

< > BotCompany Repo | #1030858 // OneMap - exactly one-element map, immutable

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

Libraryless. Click here for Pure Java version (3226L/18K).

1  
sclass OneMap<A, B> extends CompactAbstractMap<A, B> {
2  
  A key;
3  
  B value;
4  
  
5  
  *() {}
6  
  *(A *key, B *value) {}
7  
  *(Map<A, B> map) {
8  
    Iterator<Map.Entry<A, B>> it = map.entrySet().iterator();
9  
    Map.Entry<A, B> e = it.next();
10  
    key = e.getKey();
11  
    value = e.getValue();
12  
    assertFalse(it.hasNext());
13  
  }
14  
  
15  
  public int size() { ret 1; }
16  
  public Set<Map.Entry<A, B>> entrySet() {
17  
    ret litset(simpleMapEntry(key, value));
18  
  }
19  
  
20  
  public bool containsKey(O o) {
21  
    ret isKey(o);
22  
  }
23  
  
24  
  bool isKey(O o) { ret eq(o, key); }
25  
  
26  
  @Override
27  
  public B get(O o) {
28  
    ret isKey(o) ?  value : null;
29  
  }
30  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030858
Snippet name: OneMap - exactly one-element map, immutable
Eternal ID of this version: #1030858/7
Text MD5: 896657788fe68cc806df55fff3d51eb2
Transpilation MD5: 945556a737c936e7735b2439c4af14b8
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-04-25 23:01:54
Source code size: 642 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 132 / 329
Version history: 6 change(s)
Referenced in: [show references]