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

static <A> Comparator<L<A>> listComparator() {
  ret (a, b) -> {
    int l1 = l(a), l2 = l(b);
    for (int i = 0; ; i++) {
      if (i >= l1) ret i >= l2 ? 0 : -1;
      if (i >= l2) ret 1;
      int c = cmp(a.get(i), b.get(i));
      if (c != 0) ret c;
    }
  };
}

static <A> Comparator<L<A>> listComparator(Comparator<A> comparator) {
  if (comparator == null) ret listComparator();
  
  ret (a, b) -> {
    int l1 = l(a), l2 = l(b);
    for (int i = 0; ; i++) {
      if (i >= l1) ret i >= l2 ? 0 : -1;
      if (i >= l2) ret 1;
      int c = comparator.compare(a.get(i), b.get(i));
      if (c != 0) ret c;
    }
  };
}

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