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

60
LINES

< > BotCompany Repo | #1001878 // indexOf - fills various gaps in java.util.List API

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4561L/25K).

static <A> int indexOf(L<A> l, A a, int startIndex) {
  if (l == null) ret -1;
  int n = l(l);
  for (int i = startIndex; i < n; i++)
    if (eq(l.get(i), a))
      ret i;
  ret -1;
}

static <A> int indexOf(L<A> l, int startIndex, A a) {
  ret indexOf(l, a, startIndex);
}

static <A> int indexOf(L<A> l, A a) {
  if (l == null) ret -1;
  ret l.indexOf(a);
}

static int indexOf(S a, S b) {
  ret a == null || b == null ? -1 : a.indexOf(b);
}

static int indexOf(S a, S b, int i) {
  ret a == null || b == null ? -1 : a.indexOf(b, i);
}

static int indexOf(S a, char b) {
  ret a == null ? -1 : a.indexOf(b);
}

static int indexOf(S a, int i, char b) {
  ret indexOf(a, b, i);
}

static int indexOf(S a, char b, int i) {
  ret a == null ? -1 : a.indexOf(b, i);
}

static int indexOf(S a, int i, S b) {
  ret a == null || b == null ? -1 : a.indexOf(b, i);
}

static <A> int indexOf(A[] x, A a) {
  int n = l(x);
  for (int i = 0; i < n; i++)
    if (eq(x[i], a))
      ret i;
  ret -1;
}

static <A> int indexOf(Iterable<A> l, A a) {
  if (l == null) ret -1;
  int i = 0;
  for (A x : l) {
    if (eq(x, a))
      ret i;
    i++;
  }
  ret -1;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 17 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1001878
Snippet name: indexOf - fills various gaps in java.util.List API
Eternal ID of this version: #1001878/8
Text MD5: 7ea67f9a0f80dd798ed27899e3c3b1ca
Transpilation MD5: 169504b046aaa1d8e6e53eff8eb6d4ad
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-21 16:43:10
Source code size: 1206 bytes / 60 lines
Pitched / IR pitched: No / No
Views / Downloads: 949 / 3488
Version history: 7 change(s)
Referenced in: #1002427 - Accellerating 629 (SPIKE)
#1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1008874 - indexOfTrim - find trimmed line
#1023108 - indexOf_between
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)