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

23
LINES

< > BotCompany Repo | #1031513 // generalizedCIComparator (allows non-strings which are compared normally and put in after all the strings)

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

Libraryless. Click here for Pure Java version (111L/1K).

scope generalizedCIComparator

// non-strings must be Comparable to each other
// probably this is not that useful after all

static simplyCached #C generalizedCIComparator() {
  ret new C;
}

final sclass #C implements Comparator<O> {
  public int compare(O o1, O o2) {
    if (o1 cast S)
      if (o2 cast S)
        ret betterCIComparator().compare(o1, o2);
      else
        ret -1;
    else
      if (o2 instanceof S)
        ret 1;
    else
      ret cmp(o1, o2);
  }
}

Author comment

Began life as a copy of #1014136

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1031513
Snippet name: generalizedCIComparator (allows non-strings which are compared normally and put in after all the strings)
Eternal ID of this version: #1031513/3
Text MD5: 142b58aec63cbf7fd7d7b1ad6a461a7c
Transpilation MD5: 2e58ae4d12d02662ec9306bdce2b0133
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-17 06:38:26
Source code size: 498 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 167 / 252
Version history: 2 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)