// no null keys or null values sclass BijectiveMap<A, B> { new Map<A, B> forward; new Map<B, A> backward; void put(A a, B b) { assertNotNull(a); assertNotNull(b); A oldKey = backward.get(b); if (eq(oldKey, a)) ret; // nothing to do if (oldKey != null) forward.remove(oldKey); // remove old mapping // add/overwrite new mapping forward.put(a, b); backward.put(b, a); } void remove(A a) { B b = forward.get(a); if (b == null) ret; // nothing to do forward.remove(a); backward.remove(b); } B get(A a) { ret forward.get(a); } A inverseGet(B b) { ret backward.get(b); } Set<A> keySet() { ret immutableSet(forward.keySet()); } Set<B> valueSet() { ret immutableSet(backward.keySet()); } int size() { ret forward.size(); } Map<A, B> forwardMap() { ret immutableMap(forward); } Map<B, A> backwardMap() { ret immutableMap(backward); } }
Began life as a copy of #1035059
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035371 |
Snippet name: | BijectiveMap - duplicate before implementing Map interface |
Eternal ID of this version: | #1035371/1 |
Text MD5: | fd50962b6163b3229d5f91fa4ad39bbd |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-05-03 12:36:40 |
Source code size: | 1000 bytes / 43 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 94 / 108 |
Referenced in: | [show references] |