Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0f95358ec146072a1ddd1f55d42c07da24d1273a
[simgrid.git] / examples / java / kademlia / Contact.java
1 /* Copyright (c) 2012-2014, 2016. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 package kademlia;
8
9 public class Contact implements Comparable<Object> {
10   private int id;
11   private int distance;
12
13   public Contact(int id, int distance) {
14     this.id = id;
15     this.distance = distance;
16   }
17
18   public int getId() {
19     return id;
20   }
21
22   public int getDistance() {
23     return distance;
24   }
25
26   @Override
27   public boolean equals(Object x) {
28     return x.equals(id) ;
29   }
30
31   @Override
32   public int compareTo(Object o) {
33     Contact c = (Contact)o;
34     if (distance < c.distance) {
35       return -1;
36     }
37     else if (distance == c.distance) {
38       return 0;
39     }
40     else {
41       return 1;
42     }
43   }
44
45   @Override
46   public String toString() {
47     return "Contact [id=" + id + ", distance=" + distance + "]";
48   }
49
50 }