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();
}
endifdownload 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: | 1840 / 4037 |
| Version history: | 5 change(s) |
| Referenced in: | [show references] |