-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuakeEntry.java
54 lines (42 loc) · 1.13 KB
/
QuakeEntry.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
public class QuakeEntry implements Comparable<QuakeEntry>{
private Location myLocation;
private String title;
private double depth;
private double magnitude;
public QuakeEntry(double lat, double lon, double mag,
String t, double d) {
myLocation = new Location(lat,lon);
magnitude = mag;
title = t;
depth = d;
}
public Location getLocation(){
return myLocation;
}
public double getMagnitude(){
return magnitude;
}
public String getInfo(){
return title;
}
public double getDepth(){
return depth;
}
@Override
public int compareTo(QuakeEntry loc) {
double difflat = myLocation.getLatitude() - loc.myLocation.getLatitude();
if (Math.abs(difflat) < 0.001) {
double diff = myLocation.getLongitude() - loc.myLocation.getLongitude();
if (diff < 0) return -1;
if (diff > 0) return 1;
return 0;
}
if (difflat < 0) return -1;
if (difflat > 0) return 1;
// never reached
return 0;
}
public String toString(){
return String.format("(%3.2f, %3.2f), mag = %3.2f, depth = %3.2f, title = %s", myLocation.getLatitude(),myLocation.getLongitude(),magnitude,depth,title);
}
}