-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathHotel.java
63 lines (53 loc) · 1.58 KB
/
Hotel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import com.google.gson.annotations.SerializedName;
/*
* Entity class to represent City
* with natural ordering of rating when compared
*/
public class Hotel implements Comparable<Hotel> {
// inner class for rating
class UserRating implements Comparable<UserRating>{
@SerializedName("average_rating")
double averageRating;
int votes;
public UserRating(double averageRating, int votes){
this.averageRating = averageRating;
this.votes = votes;
}
@Override
public int compareTo(UserRating other){
if(this.averageRating == other.averageRating){
return Integer.compare(this.votes, other.votes);
}
return Double.compare(this.averageRating, other.averageRating);
}
@Override
public String toString() {
return "{averageRating:" + this.averageRating + ",votes:" + votes + "}";
}
}
String id;
String city;
String name;
@SerializedName("estimated_cost")
double estimatedCost;
@SerializedName("user_rating")
UserRating userRating;
public Hotel(String id, String name, String city, UserRating rating) {
this.id = id;
this.name = name;
this.city = city;
this.userRating = rating;
}
@Override
public int compareTo(Hotel other){
if(this.estimatedCost == other.estimatedCost){
return this.userRating.compareTo(userRating);
}
return Double.compare(this.estimatedCost, other.estimatedCost);
}
@Override
public String toString() {
return "\nHotel id:" + id + ",name:" + name + ",city:"+ city + ",estimatedCost:" + estimatedCost
+ ",userRating:" + userRating;
}
}