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)

static class Pair<A, B> implements Comparable<Pair<A, B>> {
  A a;
  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   

Travelled to 17 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, imzmzdywqqli, irmadwmeruwu, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, ppjhyzlbdabe, sawdedvomwva, tslmcundralx, tvejysmllsmz, wtqryiryparv

No comments. add comment

Snippet ID: #1004219
Snippet name: Pair - value pair; sorted by a, then b
Eternal ID of this version: #1004219/6
Text MD5: b651e6ec58dc47e49f2ca43949cc11a8
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-23 16:43:46
Source code size: 603 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 380 / 5945
Version history: 5 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1004219 & http://1004219.tinybrain.de