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

21
LINES

< > BotCompany Repo | #1017030 // firstInstanceOf - get first instance of a class from a collection

JavaX fragment (include)

static <A> A firstInstanceOf(Iterable i, Class<A> c) {
  if (i == null) null;
  c = primitiveToBoxedTypeOpt(c);
  for (O o : i)
    if (isInstance(c, o))
      ret (A) o;
  null;
}

static <A> A firstInstanceOf(Class<A> c, Iterable i) {
  ret firstInstanceOf(i, c);
}

static <A> A firstInstanceOf(O[] a, Class<A> c) {
  if (a == null) null;
  c = primitiveToBoxedTypeOpt(c);
  for (O o : a)
    if (isInstance(c, o))
      ret (A) o;
  null;
}

Author comment

Began life as a copy of #1004443

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1017030
Snippet name: firstInstanceOf - get first instance of a class from a collection
Eternal ID of this version: #1017030/3
Text MD5: 18c029cc63928c47b7b280e89852245d
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-11-30 22:58:17
Source code size: 464 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 409 / 453
Version history: 2 change(s)
Referenced in: [show references]