Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

24
LINES

< > BotCompany Repo | #1001899 - asSet - makes a guess whether to use TreeSet or HashSet. also drops null elements

JavaX fragment (include)

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;
}

download  show line numbers  debug dex   

Travelled to 14 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, sawdedvomwva, tslmcundralx, tvejysmllsmz, wtqryiryparv

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/5
Text MD5: 08d80b3743055bb18f5beba62f505f58
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-13 17:16:33
Source code size: 442 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 475 / 2535
Version history: 4 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1001899 & http://1001899.tinybrain.de