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

29
LINES

< > BotCompany Repo | #1004219 // Pair - value pair; sorted by a, then b

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

Libraryless. Click here for Pure Java version (10033L/55K).

sclass Pair<A, B> is Comparable<Pair<A, B>> {
  settable A a;
  settable B b;

  *() {}
  *(A *a, B *b) {}
  
  public int hashCode() {
    ret hashCodeFor(a) + 2*hashCodeFor(b);
  }
  
  public bool equals(O o) {
    if (o == this) true;
    if (!(o instanceof Pair)) false;
    Pair t = (Pair) o;
    ret eq(a, t.a) && eq(b, t.b);
  }
  
  toString {
    ret "<" + a + ", " + b + ">";
  }
  
  public int compareTo(Pair<A, B> p) {
    if (p == null) ret 1;
    int i = ((Comparable<A>) a).compareTo(p.a);
    if (i != 0) ret i;
    ret ((Comparable<B>) b).compareTo(p.b);
  }
}

Author comment

Began life as a copy of #1004216

download  show line numbers  debug dex  old transpilations   

Travelled to 24 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, ekrmjmnbrukm, gwrvuhgaqvyk, imzmzdywqqli, irmadwmeruwu, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, onxytkatvevr, ppjhyzlbdabe, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt, wtqryiryparv, xrpafgyirdlv

No comments. add comment

Snippet ID: #1004219
Snippet name: Pair - value pair; sorted by a, then b
Eternal ID of this version: #1004219/8
Text MD5: a731704eb92cc41b604376001c1a454e
Transpilation MD5: cf56c2ac8aa898d5a5d69740efc41ec8
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-01-22 12:10:13
Source code size: 607 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 812 / 7083
Version history: 7 change(s)
Referenced in: #1012602 - PairIC - case-insensitive string pair - doesn't work - how to make hashCode?
#1016582 - Global Utils (stuff in here gets moved to x30_pkg.x30_util.*)
#1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)
#1036521 - SameTypePair - Pair where both types are identical. Not sure if we should use this. Use pairGet instead