-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
137 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
library/src/main/java/tr/com/erenkaynar/library/earthquake/Constants.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 32 additions & 3 deletions
35
library/src/main/java/tr/com/erenkaynar/library/earthquake/enums/Source.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,36 @@ | ||
package tr.com.erenkaynar.library.earthquake.enums; | ||
|
||
public enum Source { | ||
KANDILLI, | ||
AFAD, | ||
USGS | ||
KANDILLI( | ||
"Kandilli Rasathanesi ve Deprem Araştırma Enstitüsü", | ||
"http://www.koeri.boun.edu.tr/scripts/sondepremler.asp" | ||
), | ||
AFAD( | ||
"Afet ve Acil Durum Yönetimi Başkanlığı", | ||
"https://deprem.afad.gov.tr/last-earthquakes.html" | ||
), | ||
USGS( | ||
"ABD Jeoloji Araştırmaları Kurumu (United States Geological Survey)", | ||
"https://earthquake.usgs.gov/fdsnws/event/1/query?format=text&minlongitude=25&maxlongitude=46&minlatitude=35&maxlatitude=43&limit=100" | ||
), | ||
EMSC( | ||
"Avrupa-Akdeniz Sismoloji Merkezi (European-Mediterranean Seismological Centre)", | ||
"https://www.seismicportal.eu/fdsnws/event/1/query?contributor=EMSC&limit=100&minlat=35&maxlat=43&minlon=25&maxlon=46&format=text&mindepth=0&minmag=0" | ||
); | ||
|
||
private final String name; | ||
private final String url; | ||
|
||
Source(String name, String url) { | ||
this.name = name; | ||
this.url = url; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 52 additions & 2 deletions
54
...ary/src/main/java/tr/com/erenkaynar/library/earthquake/sources/EarthquakeAPICallable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,62 @@ | ||
package tr.com.erenkaynar.library.earthquake.sources; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStreamReader; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
|
||
import tr.com.erenkaynar.library.earthquake.enums.Source; | ||
import tr.com.erenkaynar.library.earthquake.models.Earthquake; | ||
import tr.com.erenkaynar.library.earthquake.sources.parsers.AfadParser; | ||
import tr.com.erenkaynar.library.earthquake.sources.parsers.KandilliParser; | ||
import tr.com.erenkaynar.library.earthquake.sources.parsers.Parser; | ||
import tr.com.erenkaynar.library.earthquake.sources.parsers.TextParser; | ||
import tr.com.erenkaynar.library.earthquake.utils.Callable; | ||
|
||
public abstract class EarthquakeAPICallable extends Callable<ArrayList<Earthquake>> { | ||
public class EarthquakeAPICallable extends Callable<ArrayList<Earthquake>> { | ||
|
||
public abstract URL getUrl() throws Exception; | ||
private Source source; | ||
private Parser parser; | ||
|
||
public EarthquakeAPICallable(Source source) { | ||
this.source = source; | ||
} | ||
|
||
@Override | ||
protected ArrayList<Earthquake> call() throws Exception { | ||
URLConnection connection = new URL(source.getUrl()).openConnection(); | ||
|
||
final Charset charset; | ||
char a = '\n'; | ||
switch (source) { | ||
case KANDILLI: | ||
charset = Charset.forName("windows-1254"); | ||
parser = new KandilliParser(); | ||
break; | ||
case USGS: | ||
case EMSC: | ||
charset = Charset.defaultCharset(); | ||
parser = new TextParser(); | ||
break; | ||
case AFAD: | ||
charset = StandardCharsets.UTF_8; | ||
parser = new AfadParser(); | ||
a = ' '; | ||
break; | ||
default: | ||
return null; | ||
} | ||
|
||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), charset)); | ||
String line; | ||
StringBuilder data = new StringBuilder(); | ||
while ((line = reader.readLine()) != null) | ||
data.append(line).append(a); | ||
reader.close(); | ||
|
||
return parser.parse(data.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
library/src/main/java/tr/com/erenkaynar/library/earthquake/sources/parsers/Parser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package tr.com.erenkaynar.library.earthquake.sources.parsers; | ||
|
||
import java.util.ArrayList; | ||
|
||
import tr.com.erenkaynar.library.earthquake.models.Earthquake; | ||
|
||
public abstract class Parser { | ||
|
||
public abstract ArrayList<Earthquake> parse(String data); | ||
} |
Oops, something went wrong.