Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'coverity_scan' of github.com:mquinson/simgrid
[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   public boolean equals(Object x) {
27     return x.equals(id) ;
28   }
29
30   public int compareTo(Object o) {
31     Contact c = (Contact)o;
32     if (distance < c.distance) {
33       return -1;
34     }
35     else if (distance == c.distance) {
36       return 0;
37     }
38     else {
39       return 1;
40     }
41   }
42
43   @Override
44   public String toString() {
45     return "Contact [id=" + id + ", distance=" + distance + "]";
46   }
47
48 }