static Set asSet(O[] array) { new HashSet set; for (O o : array) if (o != null) set.add(o); ret set; } static Set<S> asSet(S[] array) { new TreeSet<S> set; for (S o : array) if (o != null) set.add(o); ret set; } static <A> Set<A> asSet(Iterable<A> l) { if (l instanceof Set) ret (Set) l; new HashSet<A> set; for (A o : unnull(l)) if (o != null) set.add(o); ret set; } ifclass MultiSet // Note: does not clone the set (keeps multiset alive) static <A> Set<A> asSet(MultiSet<A> ms) { ret ms == null ? null : ms.asSet(); } endif
download show line numbers debug dex old transpilations
Travelled to 21 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney, wtqryiryparv, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1001899 |
| Snippet name: | asSet - makes a guess whether to use TreeSet or HashSet. also drops null elements |
| Eternal ID of this version: | #1001899/6 |
| Text MD5: | 44056753af36a97874ab95e7322d2556 |
| Author: | stefan |
| Category: | |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2020-07-06 16:28:40 |
| Source code size: | 610 bytes / 31 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 1625 / 3816 |
| Version history: | 5 change(s) |
| Referenced in: | #1002427 - Accellerating 629 (SPIKE) #1002989 - asTreeSet #1003110 - joinSets - uses similar set to first one passed, or HashSet by default #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1008343 - asLinkedHashSet #1028056 - asOrderedSet #3000382 - Answer for ferdie (>> t = 1, f = 0) |