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).

1  
static <A> int indexOf(L<A> l, A a, int startIndex) {
2  
  if (l == null) ret -1;
3  
  int n = l(l);
4  
  for (int i = startIndex; i < n; i++)
5  
    if (eq(l.get(i), a))
6  
      ret i;
7  
  ret -1;
8  
}
9  
10  
static <A> int indexOf(L<A> l, int startIndex, A a) {
11  
  ret indexOf(l, a, startIndex);
12  
}
13  
14  
static <A> int indexOf(L<A> l, A a) {
15  
  if (l == null) ret -1;
16  
  ret l.indexOf(a);
17  
}
18  
19  
static int indexOf(S a, S b) {
20  
  ret a == null || b == null ? -1 : a.indexOf(b);
21  
}
22  
23  
static int indexOf(S a, S b, int i) {
24  
  ret a == null || b == null ? -1 : a.indexOf(b, i);
25  
}
26  
27  
static int indexOf(S a, char b) {
28  
  ret a == null ? -1 : a.indexOf(b);
29  
}
30  
31  
static int indexOf(S a, int i, char b) {
32  
  ret indexOf(a, b, i);
33  
}
34  
35  
static int indexOf(S a, char b, int i) {
36  
  ret a == null ? -1 : a.indexOf(b, i);
37  
}
38  
39  
static int indexOf(S a, int i, S b) {
40  
  ret a == null || b == null ? -1 : a.indexOf(b, i);
41  
}
42  
43  
static <A> int indexOf(A[] x, A a) {
44  
  int n = l(x);
45  
  for (int i = 0; i < n; i++)
46  
    if (eq(x[i], a))
47  
      ret i;
48  
  ret -1;
49  
}
50  
51  
static <A> int indexOf(Iterable<A> l, A a) {
52  
  if (l == null) ret -1;
53  
  int i = 0;
54  
  for (A x : l) {
55  
    if (eq(x, a))
56  
      ret i;
57  
    i++;
58  
  }
59  
  ret -1;
60  
}

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: 814 / 3335
Version history: 7 change(s)
Referenced in: [show references]