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)

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

static <A> L<A> subList(int startIndex, int endIndex, L<A> l) {
  ret subList(l, startIndex, endIndex);
}

static <A> L<A> subList(L<A> l, int startIndex, int endIndex) {
  if (l == null) null;
  int n = l(l);
  startIndex = Math.max(0, startIndex);
  endIndex = Math.min(n, endIndex);
  if (startIndex >= endIndex) ret ll();
  if (startIndex == 0 && endIndex == n) ret l;
  ret l.subList(startIndex, endIndex);
}

ifclass IntRange
static <A> L<A> subList(L<A> l, IntRange r) {
  ret subList(l, r.start, r.end);
}
endif

Author comment

Began life as a copy of #1001911

download  show line numbers  debug dex   

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

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