Libraryless. Click here for Pure Java version (3004L/17K).
// allows null keys but not null values static <A, B> B getOrCreate(Map<A, B> map, A key, Class<? extends B> c) ctex { B b = map.get(key); if (b == null) map.put(key, b = c.newInstance()); ret b; } // f : func -> B static <A, B> B getOrCreate(Map<A, B> map, A key, O f) ctex { B b = map.get(key); if (b == null) map.put(key, b = (B) callF(f)); ret b; } static <A, B> B getOrCreate(IF0<B> f, Map<A, B> map, A key) { ret getOrCreate(map, key, f); } static <A, B> B getOrCreate(Map<A, B> map, A key, IF0<B> f) { B b = map.get(key); if (b == null) map.put(key, b = f!); ret b; } static <A, B> B nuLike getOrCreate(Class<? extends B> c, Map<A, B> map, A key) { ret getOrCreate(map, key, c); }
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment