Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : update tesh
[simgrid.git] / examples / java / kademlia / Contact.java
1 /* Copyright (c) 2012. 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 /**
10  * Contains the information about a foreign node according to
11  * a node we are trying to find.
12  */
13 public class Contact implements Comparable<Object> {
14         private int id;
15         private int distance;
16         
17         public Contact(int id, int distance) {
18                 this.id = id;
19                 this.distance = distance;
20         }
21
22         public int getId() {
23                 return id;
24         }
25
26         public int getDistance() {
27                 return distance;
28         }
29         
30         public boolean equals(Object x) {
31                 return x.equals(id) ;
32         }
33
34         public int compareTo(Object o) {
35                 Contact c = (Contact)o;
36                 if (distance < c.distance) {
37                         return -1;
38                 }
39                 else if (distance == c.distance) {
40                         return 0;
41                 }
42                 else {
43                         return 1;
44                 }
45         }
46
47         @Override
48         public String toString() {
49                 return "Contact [id=" + id + ", distance=" + distance + "]";
50         }
51         
52 }