Libraryless. Click here for Pure Java version (3226L/18K).
sclass OneMap<A, B> extends CompactAbstractMap<A, B> { A key; B value; *() {} *(A *key, B *value) {} *(Map<A, B> map) { Iterator<Map.Entry<A, B>> it = map.entrySet().iterator(); Map.Entry<A, B> e = it.next(); key = e.getKey(); value = e.getValue(); assertFalse(it.hasNext()); } public int size() { ret 1; } public Set<Map.Entry<A, B>> entrySet() { ret litset(simpleMapEntry(key, value)); } public bool containsKey(O o) { ret isKey(o); } bool isKey(O o) { ret eq(o, key); } @Override public B get(O o) { ret isKey(o) ? value : null; } }
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: | 179 / 404 |
Version history: | 6 change(s) |
Referenced in: | #1031042 - MinimalMap - map consisting just of an unordered object array [O(n) access/put/remove] #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674) |