-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDifferentSorters.java
69 lines (64 loc) · 2.91 KB
/
DifferentSorters.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
64
65
66
67
68
69
import java.util.*;
public class DifferentSorters {
public void sortWithCompareTo() {
EarthQuakeParser parser = new EarthQuakeParser();
String source = "E:/Coursera/earthQuakeDataDec6sample1.atom";
//String source = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.atom";
ArrayList<QuakeEntry> list = parser.read(source);
Collections.sort(list);
for(QuakeEntry qe: list) {
System.out.println(qe);
}
int quakeNumber = 49;
System.out.println("Print quake entry in position " + quakeNumber);
System.out.println(list.get(quakeNumber));
}
public void sortByMagnitude() {
EarthQuakeParser parser = new EarthQuakeParser();
String source = "E:/Coursera/nov20quakedata.atom";
//String source = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.atom";
ArrayList<QuakeEntry> list = parser.read(source);
Collections.sort(list, new MagnitudeComparator());
for(QuakeEntry qe: list) {
System.out.println(qe);
}
}
public void sortByDistance() {
EarthQuakeParser parser = new EarthQuakeParser();
String source = "E:/Coursera/nov20quakedata.atom";
//String source = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.atom";
ArrayList<QuakeEntry> list = parser.read(source);
// Location is Durham, NC
Location where = new Location(35.9886, -78.9072);
Collections.sort(list, new DistanceComparator(where));
for(QuakeEntry qe: list) {
System.out.println(qe);
}
}
public void sortByTitleAndDepth() {
EarthQuakeParser parser = new EarthQuakeParser();
String source = "E:/Coursera/earthQuakeDataDec6sample2.atom";
//String source = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.atom";
ArrayList<QuakeEntry> list = parser.read(source);
Collections.sort(list, new TitleAndDepthComparator());
for(QuakeEntry qe: list) {
System.out.println(qe);
}
int quakeNumber = 499;
System.out.println("Print quake entry in position " + quakeNumber);
System.out.println(list.get(quakeNumber));
}
public void sortByLastWordInTitleThenByMagnitude() {
EarthQuakeParser parser = new EarthQuakeParser();
String source = "E:/Coursera/earthQuakeDataDec6sample1.atom";
//String source = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.atom";
ArrayList<QuakeEntry> list = parser.read(source);
Collections.sort(list, new TitleLastAndMagnitudeComparator());
for(QuakeEntry qe: list) {
System.out.println(qe);
}
int quakeNumber = 49;
System.out.println("Print quake entry in position " + quakeNumber);
System.out.println(list.get(quakeNumber));
}
}