-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEarthQuakeClient.java
131 lines (104 loc) · 4.89 KB
/
EarthQuakeClient.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* Search through a data set containing details about earthquakes around the world
* and filter the data based on desired criteria
* implementing interfaces with method signatures.
*
* @author pabl0cesar
*/
import java.util.*;
public class EarthQuakeClient {
public EarthQuakeClient() {
// TODO Auto-generated constructor stub
}
/**
* This method returns an ArrayList of QuakeEntry’s from quakeData
* that meet the requirements of Filter f’s satisfies method.
*/
public ArrayList<QuakeEntry> filter(ArrayList<QuakeEntry> quakeData, Filter f) {
ArrayList<QuakeEntry> answer = new ArrayList<QuakeEntry>();
for(QuakeEntry qe : quakeData) {
if (f.satisfies(qe)) {
answer.add(qe);
}
}
return answer;
}
public void testMatchAllFilters(){
EarthQuakeParser parser = new EarthQuakeParser();
String source = "data/nov20quakedata.atom";
ArrayList<QuakeEntry> list = parser.read(source);
System.out.println("read data for "+list.size()+" quakes");
MatchAllFilters maf = new MatchAllFilters();
MagnitudeFilter mF = new MagnitudeFilter(1.0,4.0,"Magnitude");
DepthFilter dF = new DepthFilter(-180000.0,-30000.0,"Depth");
PhraseFilter pF = new PhraseFilter("any","o","Phrase");
maf.addFilter(mF);
maf.addFilter(dF);
maf.addFilter(pF);
ArrayList<QuakeEntry> filterList = filter(list, maf);
dumpCSV(filterList);
System.out.println("Found "+filterList.size()+" quakes that matches that criteria.");
}
public void testMatchAllFilters2(){
EarthQuakeParser parser = new EarthQuakeParser();
String source = "data/nov20quakedata.atom";
ArrayList<QuakeEntry> list = parser.read(source);
System.out.println("read data for "+list.size()+" quakes");
MatchAllFilters maf = new MatchAllFilters();
MagnitudeFilter mF = new MagnitudeFilter(0.0,5.0,"Magnitude");
LocationFilter lF = new LocationFilter(new Location(55.7308, 9.1153), 3000000,"Location");
PhraseFilter pF = new PhraseFilter("any","Ca","Phrase");
maf.addFilter(mF);
maf.addFilter(lF);
maf.addFilter(pF);
ArrayList<QuakeEntry> filterList = filter(list, maf);
dumpCSV(filterList);
System.out.println("Found "+filterList.size()+" quakes that matches that criteria.");
System.out.println("Filters used are: "+maf.getName());
}
/**
* This method creates an EarthQuakeParser to read in an earthquake data
* file, creating an ArrayList of QuakeEntrys. It then creates a
* MinMagFilter with a minimum magnitude, and then calls
* the filter method with the MinMagFilter to create an ArrayList
* of QuakeEntry’s having that minimum magnitude or greater.
*/
public void quakesWithFilter() {
EarthQuakeParser parser = new EarthQuakeParser();
//String source = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.atom";
String source = "data/nov20quakedata.atom";
ArrayList<QuakeEntry> list = parser.read(source);
System.out.println("read data for "+list.size()+" quakes");
Filter f = new MagnitudeFilter(3.5,4.5,"Magnitude");
ArrayList<QuakeEntry> magList = filter(list, f);
f = new DepthFilter( -55000.0,-20000.0,"Depth");
ArrayList<QuakeEntry> depthMagList = filter(magList, f);
// Filter f = new LocationFilter(new Location(39.7392, -104.9903),1000000,"Location");
// ArrayList<QuakeEntry> locList = filter(list,f);
// f = new PhraseFilter("end","a","Phrase");
// ArrayList<QuakeEntry> multiList = filter(locList,f);
for (QuakeEntry qe: depthMagList) {
System.out.println(qe);
}
System.out.println("Found "+depthMagList.size()+" quakes that matches that criteria.");
}
public void createCSV() {
EarthQuakeParser parser = new EarthQuakeParser();
//String source = "../data/nov20quakedata.atom";
String source = "data/nov20quakedatasmall.atom";
//String source = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.atom";
ArrayList<QuakeEntry> list = parser.read(source);
dumpCSV(list);
System.out.println("# quakes read: "+list.size());
}
public void dumpCSV(ArrayList<QuakeEntry> list) {
System.out.println("Latitude,Longitude,Magnitude,Info");
for(QuakeEntry qe : list){
System.out.printf("%4.2f,%4.2f,%4.2f,%s\n",
qe.getLocation().getLatitude(),
qe.getLocation().getLongitude(),
qe.getMagnitude(),
qe.getInfo());
}
}
}