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

23
LINES

< > BotCompany Repo | #1002310 - subList function - safer version of List.subList

JavaX fragment (include)

1  
static <A> L<A> subList(L<A> l, int startIndex) {
2  
  ret subList(l, startIndex, l(l));
3  
}
4  
5  
static <A> L<A> subList(int startIndex, int endIndex, L<A> l) {
6  
  ret subList(l, startIndex, endIndex);
7  
}
8  
9  
static <A> L<A> subList(L<A> l, int startIndex, int endIndex) {
10  
  if (l == null) null;
11  
  int n = l(l);
12  
  startIndex = Math.max(0, startIndex);
13  
  endIndex = Math.min(n, endIndex);
14  
  if (startIndex >= endIndex) ret ll();
15  
  if (startIndex == 0 && endIndex == n) ret l;
16  
  ret l.subList(startIndex, endIndex);
17  
}
18  
19  
ifclass IntRange
20  
static <A> L<A> subList(L<A> l, IntRange r) {
21  
  ret subList(l, r.start, r.end);
22  
}
23  
endif

Author comment

Began life as a copy of #1001911

download  show line numbers  debug dex   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, podlckwnjdmb, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, xrpafgyirdlv

No comments. add comment

Snippet ID: #1002310
Snippet name: subList function - safer version of List.subList
Eternal ID of this version: #1002310/6
Text MD5: 088f2703d64d4e7ed818ce8bd736cc17
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-25 21:35:10
Source code size: 630 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 521 / 3677
Version history: 5 change(s)
Referenced in: [show references]

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