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

25
LINES

< > BotCompany Repo | #1030168 // listComparator

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

Libraryless. Click here for Pure Java version (2556L/16K).

1  
static <A> Comparator<L<A>> listComparator() {
2  
  ret (a, b) -> {
3  
    int l1 = l(a), l2 = l(b);
4  
    for (int i = 0; ; i++) {
5  
      if (i >= l1) ret i >= l2 ? 0 : -1;
6  
      if (i >= l2) ret 1;
7  
      int c = cmp(a.get(i), b.get(i));
8  
      if (c != 0) ret c;
9  
    }
10  
  };
11  
}
12  
13  
static <A> Comparator<L<A>> listComparator(Comparator<A> comparator) {
14  
  if (comparator == null) ret listComparator();
15  
  
16  
  ret (a, b) -> {
17  
    int l1 = l(a), l2 = l(b);
18  
    for (int i = 0; ; i++) {
19  
      if (i >= l1) ret i >= l2 ? 0 : -1;
20  
      if (i >= l2) ret 1;
21  
      int c = comparator.compare(a.get(i), b.get(i));
22  
      if (c != 0) ret c;
23  
    }
24  
  };
25  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030168
Snippet name: listComparator
Eternal ID of this version: #1030168/3
Text MD5: 7d0492c862393773cd3c3adc0fd79d2a
Transpilation MD5: fc205b2924f0e31256b0170e7999c523
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-11-11 23:37:08
Source code size: 650 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 198 / 283
Version history: 2 change(s)
Referenced in: [show references]