diff --git a/pom.xml b/pom.xml index af3bd65..02c01a5 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 be.jaud OebbApi - 0.1 + 0.5 jar ÖBB delay check and output for Info Orbs diff --git a/src/main/java/be/jaud/OebbCheck.java b/src/main/java/be/jaud/OebbCheck.java index 4ff7850..bb6e982 100644 --- a/src/main/java/be/jaud/OebbCheck.java +++ b/src/main/java/be/jaud/OebbCheck.java @@ -67,6 +67,11 @@ public class OebbCheck { private static JSONArray getData(String Station, String Time, String maxjourneys) throws IOException, URISyntaxException { URL url = new URI("https://fahrplan.oebb.at/bin/stboard.exe/dn?L=vs_scotty.vs_liveticker&evaId=" + Station + "&boardType=dep&time="+ Time +"&productsFilter=1011110111011&additionalTime=0&maxJourneys=" + maxjourneys + "&outputMode=tickerDataOnly&start=yes&selectDate=today").toURL(); + JSONObject jo = getJsonObject(url); + return jo.getJSONArray("journey"); + } + + private static JSONObject getJsonObject(URL url) throws IOException { HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); BufferedReader in = new BufferedReader( @@ -78,7 +83,6 @@ public class OebbCheck { } in.close(); String sub = content.substring(14); - JSONObject jo = new JSONObject(sub); - return jo.getJSONArray("journey"); + return new JSONObject(sub); } } diff --git a/src/main/java/be/jaud/ResilientExecutor.java b/src/main/java/be/jaud/ResilientExecutor.java index e874f35..42e1418 100644 --- a/src/main/java/be/jaud/ResilientExecutor.java +++ b/src/main/java/be/jaud/ResilientExecutor.java @@ -29,23 +29,17 @@ public class ResilientExecutor extends ScheduledThreadPoolExecutor { return new LogOnExceptionRunnable(command); } - private static class LogOnExceptionRunnable implements Runnable { - private final Runnable theRunnable; - - public LogOnExceptionRunnable(Runnable theRunnable) { - super(); - this.theRunnable = theRunnable; - } + private record LogOnExceptionRunnable(Runnable theRunnable) implements Runnable { @Override - public void run() { - try { - theRunnable.run(); - } catch (Exception e) { - LOG.error("error in executing: {} It will no longer be run!", this.theRunnable, e); - System.exit(1); + public void run() { + try { + theRunnable.run(); + } catch (Exception e) { + LOG.error("error in executing: {} It will no longer be run!", this.theRunnable, e); + System.exit(1); + } } } - } } \ No newline at end of file diff --git a/src/main/java/be/jaud/Settings.java b/src/main/java/be/jaud/Settings.java index 8ec4069..caeaf92 100644 --- a/src/main/java/be/jaud/Settings.java +++ b/src/main/java/be/jaud/Settings.java @@ -2,14 +2,11 @@ package be.jaud; import java.io.File; import java.nio.file.Paths; -import java.util.Iterator; import java.util.List; -import java.util.Map.Entry; import com.typesafe.config.Config; import com.typesafe.config.ConfigException; import com.typesafe.config.ConfigFactory; -import com.typesafe.config.ConfigValue; public class Settings { private static Settings instance = null; @@ -30,25 +27,19 @@ public class Settings { } } - public Iterator> getall(){ - return config.entrySet().iterator(); - } + //public Iterator> getall(){ return config.entrySet().iterator(); } public String getString(String key){ return config.getString(key); } - public Boolean getBoolean(String key){ - return config.getBoolean(key); - } + //public Boolean getBoolean(String key){ return config.getBoolean(key); } public int getInt(String key){ return config.getInt(key); } - public List getStringList(String key){ - return config.getStringList(key); - } + //public List getStringList(String key){ return config.getStringList(key); } public List getIntList(String key){ return config.getIntList(key); } }