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 (7871L/44K).

1  
static class Pair<A, B> implements Comparable<Pair<A, B>> {
2  
  settable A a;
3  
  settable B b;
4  
5  
  *() {}
6  
  *(A *a, B *b) {}
7  
  
8  
  public int hashCode() {
9  
    ret hashCodeFor(a) + 2*hashCodeFor(b);
10  
  }
11  
  
12  
  public bool equals(O o) {
13  
    if (o == this) true;
14  
    if (!(o instanceof Pair)) false;
15  
    Pair t = (Pair) o;
16  
    ret eq(a, t.a) && eq(b, t.b);
17  
  }
18  
  
19  
  toString {
20  
    ret "<" + a + ", " + b + ">";
21  
  }
22  
  
23  
  public int compareTo(Pair<A, B> p) {
24  
    if (p == null) ret 1;
25  
    int i = ((Comparable<A>) a).compareTo(p.a);
26  
    if (i != 0) ret i;
27  
    ret ((Comparable<B>) b).compareTo(p.b);
28  
  }
29  
}

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/7
Text MD5: e0901badc04b6e915be310816bcac15f
Transpilation MD5: 180b183114f12a482123ddef45167682
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-04-13 12:19:36
Source code size: 621 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 670 / 6906
Version history: 6 change(s)
Referenced in: [show references]