diff --git a/GlobalQuakeAPI/src/main/java/gqserver/api/Packet.java b/GlobalQuakeAPI/src/main/java/gqserver/api/Packet.java index eec8a203b..2c6de1af0 100644 --- a/GlobalQuakeAPI/src/main/java/gqserver/api/Packet.java +++ b/GlobalQuakeAPI/src/main/java/gqserver/api/Packet.java @@ -4,6 +4,7 @@ public interface Packet extends Serializable { - default void onServerReceive(ServerClient serverClient) {} + default void onServerReceive(ServerClient serverClient) { + } } diff --git a/GlobalQuakeAPI/src/main/java/gqserver/api/ServerClient.java b/GlobalQuakeAPI/src/main/java/gqserver/api/ServerClient.java index 3ee9777f8..a405ba221 100644 --- a/GlobalQuakeAPI/src/main/java/gqserver/api/ServerClient.java +++ b/GlobalQuakeAPI/src/main/java/gqserver/api/ServerClient.java @@ -62,6 +62,7 @@ public class ServerClient { limitRules.put(ArchivedQuakesRequestPacket.class, 4); limitRules.put(DataRequestPacket.class, 60); } + public ServerClient(Socket socket) throws IOException { this.socket = socket; this.inputStream = new ObjectInputStream(socket.getInputStream()); @@ -130,7 +131,7 @@ public ServerClientConfig getClientConfig() { } public synchronized void queuePacket(Packet packet) { - if(destroyed){ + if (destroyed) { return; } diff --git a/GlobalQuakeAPI/src/main/java/gqserver/api/data/earthquake/ArchivedEventData.java b/GlobalQuakeAPI/src/main/java/gqserver/api/data/earthquake/ArchivedEventData.java index 7b1dcd84a..dccb3cbdd 100644 --- a/GlobalQuakeAPI/src/main/java/gqserver/api/data/earthquake/ArchivedEventData.java +++ b/GlobalQuakeAPI/src/main/java/gqserver/api/data/earthquake/ArchivedEventData.java @@ -2,6 +2,7 @@ import java.io.Serial; import java.io.Serializable; + public record ArchivedEventData(float lat, float lon, float maxRatio, long pWave) implements Serializable { @Serial private static final long serialVersionUID = 0L; diff --git a/GlobalQuakeAPI/src/main/java/gqserver/api/data/earthquake/ArchivedQuakeData.java b/GlobalQuakeAPI/src/main/java/gqserver/api/data/earthquake/ArchivedQuakeData.java index 1bc707b69..529a5a4a8 100644 --- a/GlobalQuakeAPI/src/main/java/gqserver/api/data/earthquake/ArchivedQuakeData.java +++ b/GlobalQuakeAPI/src/main/java/gqserver/api/data/earthquake/ArchivedQuakeData.java @@ -4,7 +4,8 @@ import java.io.Serializable; import java.util.UUID; -public record ArchivedQuakeData(UUID uuid, float lat, float lon, float depth, float magnitude, long origin, byte qualityID, long finalUpdateMillis) implements Serializable { +public record ArchivedQuakeData(UUID uuid, float lat, float lon, float depth, float magnitude, long origin, + byte qualityID, long finalUpdateMillis) implements Serializable { @Serial private static final long serialVersionUID = 0L; } diff --git a/GlobalQuakeAPI/src/main/java/gqserver/api/data/earthquake/HypocenterData.java b/GlobalQuakeAPI/src/main/java/gqserver/api/data/earthquake/HypocenterData.java index 8db1f1356..8352966df 100644 --- a/GlobalQuakeAPI/src/main/java/gqserver/api/data/earthquake/HypocenterData.java +++ b/GlobalQuakeAPI/src/main/java/gqserver/api/data/earthquake/HypocenterData.java @@ -4,7 +4,8 @@ import java.io.Serializable; import java.util.UUID; -public record HypocenterData(UUID uuid, int revisionID, float lat, float lon, float depth, long origin, float magnitude, long lastUpdate, String region) implements Serializable { +public record HypocenterData(UUID uuid, int revisionID, float lat, float lon, float depth, long origin, float magnitude, + long lastUpdate, String region) implements Serializable { @Serial private static final long serialVersionUID = 0L; } diff --git a/GlobalQuakeAPI/src/main/java/gqserver/api/data/earthquake/advanced/HypocenterQualityData.java b/GlobalQuakeAPI/src/main/java/gqserver/api/data/earthquake/advanced/HypocenterQualityData.java index a3999b0bd..7e3f888d2 100644 --- a/GlobalQuakeAPI/src/main/java/gqserver/api/data/earthquake/advanced/HypocenterQualityData.java +++ b/GlobalQuakeAPI/src/main/java/gqserver/api/data/earthquake/advanced/HypocenterQualityData.java @@ -3,7 +3,8 @@ import java.io.Serial; import java.io.Serializable; -public record HypocenterQualityData(float errOrigin, float errDepth, float errNS, float errEW, int stations, float pct) implements Serializable { +public record HypocenterQualityData(float errOrigin, float errDepth, float errNS, float errEW, int stations, + float pct) implements Serializable { @Serial private static final long serialVersionUID = 0L; } diff --git a/GlobalQuakeAPI/src/main/java/gqserver/api/data/earthquake/advanced/LocationConfidenceIntervalData.java b/GlobalQuakeAPI/src/main/java/gqserver/api/data/earthquake/advanced/LocationConfidenceIntervalData.java index e527d3bb4..1adc32bac 100644 --- a/GlobalQuakeAPI/src/main/java/gqserver/api/data/earthquake/advanced/LocationConfidenceIntervalData.java +++ b/GlobalQuakeAPI/src/main/java/gqserver/api/data/earthquake/advanced/LocationConfidenceIntervalData.java @@ -4,7 +4,8 @@ import java.io.Serializable; import java.util.List; -public record LocationConfidenceIntervalData(List polygonConfidenceIntervalDataList) implements Serializable { +public record LocationConfidenceIntervalData( + List polygonConfidenceIntervalDataList) implements Serializable { @Serial private static final long serialVersionUID = 0L; } diff --git a/GlobalQuakeAPI/src/main/java/gqserver/api/data/station/StationInfoData.java b/GlobalQuakeAPI/src/main/java/gqserver/api/data/station/StationInfoData.java index 908cf1fe7..66a34ae8a 100644 --- a/GlobalQuakeAPI/src/main/java/gqserver/api/data/station/StationInfoData.java +++ b/GlobalQuakeAPI/src/main/java/gqserver/api/data/station/StationInfoData.java @@ -5,8 +5,10 @@ import java.io.Serial; import java.io.Serializable; -public record StationInfoData(int index, float lat, float lon, String network, String station, String channel, String location, - long time, float maxIntensity, boolean eventMode, InputType sensorType) implements Serializable { +public record StationInfoData(int index, float lat, float lon, String network, String station, String channel, + String location, + long time, float maxIntensity, boolean eventMode, + InputType sensorType) implements Serializable { @Serial private static final long serialVersionUID = 0L; } diff --git a/GlobalQuakeAPI/src/main/java/gqserver/api/packets/earthquake/ArchivedQuakePacket.java b/GlobalQuakeAPI/src/main/java/gqserver/api/packets/earthquake/ArchivedQuakePacket.java index 589715a0e..289391f60 100644 --- a/GlobalQuakeAPI/src/main/java/gqserver/api/packets/earthquake/ArchivedQuakePacket.java +++ b/GlobalQuakeAPI/src/main/java/gqserver/api/packets/earthquake/ArchivedQuakePacket.java @@ -7,7 +7,8 @@ import java.io.Serial; import java.util.List; -public record ArchivedQuakePacket(ArchivedQuakeData archivedQuakeData, List archivedEventDataList) implements Packet { +public record ArchivedQuakePacket(ArchivedQuakeData archivedQuakeData, + List archivedEventDataList) implements Packet { @Serial private static final long serialVersionUID = 0L; } diff --git a/GlobalQuakeAPI/src/main/java/gqserver/api/packets/earthquake/HypocenterDataPacket.java b/GlobalQuakeAPI/src/main/java/gqserver/api/packets/earthquake/HypocenterDataPacket.java index 5b852f129..bbc48774f 100644 --- a/GlobalQuakeAPI/src/main/java/gqserver/api/packets/earthquake/HypocenterDataPacket.java +++ b/GlobalQuakeAPI/src/main/java/gqserver/api/packets/earthquake/HypocenterDataPacket.java @@ -7,7 +7,8 @@ import java.io.Serial; -public record HypocenterDataPacket(HypocenterData data, AdvancedHypocenterData advancedHypocenterData, ClusterData clusterData) implements Packet { +public record HypocenterDataPacket(HypocenterData data, AdvancedHypocenterData advancedHypocenterData, + ClusterData clusterData) implements Packet { @Serial private static final long serialVersionUID = 0L; } diff --git a/GlobalQuakeAPI/src/main/java/gqserver/api/packets/station/StationsIntensityPacket.java b/GlobalQuakeAPI/src/main/java/gqserver/api/packets/station/StationsIntensityPacket.java index ba7eac53b..85ce24359 100644 --- a/GlobalQuakeAPI/src/main/java/gqserver/api/packets/station/StationsIntensityPacket.java +++ b/GlobalQuakeAPI/src/main/java/gqserver/api/packets/station/StationsIntensityPacket.java @@ -7,7 +7,8 @@ import java.util.List; import java.util.UUID; -public record StationsIntensityPacket(UUID stationsIndexing, long time, List intensities) implements Packet { +public record StationsIntensityPacket(UUID stationsIndexing, long time, + List intensities) implements Packet { @Serial private static final long serialVersionUID = 0L; } diff --git a/GlobalQuakeClient/src/main/java/globalquake/alert/AlertManager.java b/GlobalQuakeClient/src/main/java/globalquake/alert/AlertManager.java index 311874bbc..1e5a09b8e 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/alert/AlertManager.java +++ b/GlobalQuakeClient/src/main/java/globalquake/alert/AlertManager.java @@ -21,7 +21,7 @@ public class AlertManager { public AlertManager() { this.warnings = new HashMap<>(); - GlobalQuake.instance.getEventHandler().registerEventListener(new GlobalQuakeEventListener(){ + GlobalQuake.instance.getEventHandler().registerEventListener(new GlobalQuakeEventListener() { @Override public void onQuakeCreate(QuakeCreateEvent event) { tick(); @@ -48,7 +48,7 @@ public synchronized void tick() { Warning warning = kv.getValue(); long age = GlobalQuake.instance.currentTimeMillis() - warning.createdAt; - if(age > 1000 * 60 * STORE_TIME_MINUTES){ + if (age > 1000 * 60 * STORE_TIME_MINUTES) { iterator.remove(); continue; } @@ -61,13 +61,13 @@ public synchronized void tick() { } private void conditionsSatisfied(Warnable warnable, Warning warning) { - if(GlobalQuakeLocal.instance != null){ + if (GlobalQuakeLocal.instance != null) { GlobalQuakeLocal.instance.getLocalEventHandler().fireEvent(new AlertIssuedEvent(warnable, warning)); } } private boolean meetsConditions(Warnable warnable) { - if(warnable instanceof Earthquake){ + if (warnable instanceof Earthquake) { return meetsConditions((Earthquake) warnable, true); } diff --git a/GlobalQuakeClient/src/main/java/globalquake/client/ClientSocket.java b/GlobalQuakeClient/src/main/java/globalquake/client/ClientSocket.java index 5c22746f1..0b8895bcc 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/client/ClientSocket.java +++ b/GlobalQuakeClient/src/main/java/globalquake/client/ClientSocket.java @@ -68,24 +68,24 @@ public void connect(String ip, int port) throws IOException, ClassNotFoundExcept sendPacket(new StationsRequestPacket()); GlobalQuakeClient.instance.getLocalEventHandler().fireEvent(new SocketReconnectEvent()); status = ClientSocketStatus.CONNECTED; - } catch(ConnectException | SocketTimeoutException ce){ + } catch (ConnectException | SocketTimeoutException ce) { Logger.trace(ce); status = ClientSocketStatus.DISCONNECTED; throw ce; - } catch(Exception e) { + } catch (Exception e) { status = ClientSocketStatus.DISCONNECTED; Logger.error(e); throw e; } } - public void runReconnectService(){ + public void runReconnectService() { reconnectService = Executors.newSingleThreadScheduledExecutor(); reconnectService.scheduleAtFixedRate(this::checkReconnect, 0, 10, TimeUnit.SECONDS); } - public void destroy(){ - if(reconnectService == null){ + public void destroy() { + if (reconnectService == null) { return; } @@ -93,7 +93,7 @@ public void destroy(){ } private void checkReconnect() { - if(!socket.isConnected() || socket.isClosed()){ + if (!socket.isConnected() || socket.isClosed()) { try { connect(ip, port); } catch (Exception e) { @@ -105,7 +105,7 @@ private void checkReconnect() { private void sendQuakeRequest() { try { sendPacket(new EarthquakesRequestPacket()); - } catch(SocketTimeoutException | SocketException e){ + } catch (SocketTimeoutException | SocketException e) { Logger.trace(e); onClose(); } catch (IOException e) { @@ -117,7 +117,7 @@ private void sendQuakeRequest() { private void sendHeartbeat() { try { sendPacket(new HeartbeatPacket()); - } catch(SocketTimeoutException | SocketException e){ + } catch (SocketTimeoutException | SocketException e) { Logger.trace(e); onClose(); } catch (IOException e) { @@ -128,10 +128,10 @@ private void sendHeartbeat() { private void onClose() { status = ClientSocketStatus.DISCONNECTED; - if(socket != null){ + if (socket != null) { try { socket.close(); - } catch(SocketTimeoutException | SocketException e){ + } catch (SocketTimeoutException | SocketException e) { Logger.trace(e); onClose(); } catch (IOException e) { @@ -145,7 +145,7 @@ private void onClose() { GlobalQuake.instance.stopService(quakeCheckService); } - public boolean isConnected(){ + public boolean isConnected() { return socket.isConnected() && !socket.isClosed(); } @@ -156,9 +156,9 @@ private void runReader() { Logger.trace("Received packet: %s".formatted(packet.toString())); ((GlobalQuakeClient) GlobalQuakeClient.instance).processPacket(this, packet); } - } catch(SocketTimeoutException | SocketException se){ + } catch (SocketTimeoutException | SocketException se) { Logger.trace(se); - }catch (Exception e){ + } catch (Exception e) { Logger.error(e); } finally { onClose(); @@ -166,7 +166,7 @@ private void runReader() { } public synchronized void sendPacket(Packet packet) throws IOException { - if(outputStream == null){ + if (outputStream == null) { return; } @@ -178,8 +178,8 @@ public synchronized void sendPacket(Packet packet) throws IOException { private void handshake() throws IOException, ClassNotFoundException { sendPacket(new HandshakePacket(GQApi.COMPATIBILITY_VERSION, new ServerClientConfig(true, true))); Packet packet = (Packet) inputStream.readObject(); - if(!(packet instanceof HandshakeSuccessfulPacket)) { - if(packet instanceof TerminationPacket terminationPacket){ + if (!(packet instanceof HandshakeSuccessfulPacket)) { + if (packet instanceof TerminationPacket terminationPacket) { throw new RuntimeApplicationException(terminationPacket.cause()); } else { throw new RuntimeApplicationException("Unknown"); diff --git a/GlobalQuakeClient/src/main/java/globalquake/client/ClusterAnalysisClient.java b/GlobalQuakeClient/src/main/java/globalquake/client/ClusterAnalysisClient.java index d7fa47838..646562f59 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/client/ClusterAnalysisClient.java +++ b/GlobalQuakeClient/src/main/java/globalquake/client/ClusterAnalysisClient.java @@ -31,8 +31,8 @@ public ClusterAnalysisClient() { private void checkClusters() { List toRemove = new ArrayList<>(); - for(Cluster cluster : clusters){ - if(GlobalQuake.instance.currentTimeMillis() - cluster.getLastUpdate() > 30 * 60 * 1000){ + for (Cluster cluster : clusters) { + if (GlobalQuake.instance.currentTimeMillis() - cluster.getLastUpdate() > 30 * 60 * 1000) { toRemove.add(cluster); } } @@ -46,14 +46,14 @@ public List getClusters() { } public void processPacket(ClientSocket ignoredSocket, Packet packet) { - if(packet instanceof ClusterPacket clusterPacket){ + if (packet instanceof ClusterPacket clusterPacket) { getCluster(clusterPacket.clusterData()); } } public Cluster getCluster(ClusterData clusterData) { Cluster existing = findCluster(clusterData.uuid()); - if(existing != null) { + if (existing != null) { existing.updateLevel(clusterData.level()); existing.updateRoot(clusterData.rootLat(), clusterData.rootLon()); } else { diff --git a/GlobalQuakeClient/src/main/java/globalquake/client/EarthquakeAnalysisClient.java b/GlobalQuakeClient/src/main/java/globalquake/client/EarthquakeAnalysisClient.java index 431a095a6..47fc014b4 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/client/EarthquakeAnalysisClient.java +++ b/GlobalQuakeClient/src/main/java/globalquake/client/EarthquakeAnalysisClient.java @@ -34,7 +34,7 @@ public class EarthquakeAnalysisClient extends EarthquakeAnalysis { private final Map clientEarthquakeMap; private final ScheduledExecutorService checkService; - public EarthquakeAnalysisClient(){ + public EarthquakeAnalysisClient() { clientEarthquakeMap = new ConcurrentHashMap<>(); checkService = Executors.newSingleThreadScheduledExecutor(); @@ -54,17 +54,17 @@ private void removeOld() { getEarthquakes().removeAll(toRemove); clientEarthquakeMap.entrySet().removeIf(kv -> shouldRemove(kv.getValue(), -30)); - } catch(Exception e) { + } catch (Exception e) { Logger.error(e); } } public void processPacket(ClientSocket socket, Packet packet) throws IOException { - if(packet instanceof HypocenterDataPacket hypocenterData) { + if (packet instanceof HypocenterDataPacket hypocenterData) { processQuakeDataPacket(hypocenterData); - } else if(packet instanceof EarthquakeCheckPacket checkPacket) { + } else if (packet instanceof EarthquakeCheckPacket checkPacket) { processQuakeCheckPacket(socket, checkPacket); - } else if(packet instanceof ArchivedQuakePacket archivedQuakePacket) { + } else if (packet instanceof ArchivedQuakePacket archivedQuakePacket) { processQuakeArchivePacket(archivedQuakePacket); } } @@ -75,20 +75,20 @@ private void processQuakeArchivePacket(ArchivedQuakePacket archivedQuakePacket) if (existingQuake != null) { clientEarthquakeMap.remove(uuid); getEarthquakes().remove(existingQuake); - ((EarthquakeArchiveClient)GlobalQuakeClient.instance.getArchive()).archiveQuake(archivedQuakePacket, existingQuake); + ((EarthquakeArchiveClient) GlobalQuakeClient.instance.getArchive()).archiveQuake(archivedQuakePacket, existingQuake); } } private void processQuakeCheckPacket(ClientSocket socket, EarthquakeCheckPacket checkPacket) throws IOException { UUID uuid = checkPacket.info().uuid(); Earthquake existingQuake = clientEarthquakeMap.get(uuid); - if(checkPacket.info().revisionID() == EarthquakeInfo.REMOVED){ + if (checkPacket.info().revisionID() == EarthquakeInfo.REMOVED) { clientEarthquakeMap.remove(uuid); - if(existingQuake != null) { + if (existingQuake != null) { getEarthquakes().remove(existingQuake); GlobalQuake.instance.getEventHandler().fireEvent(new QuakeRemoveEvent(existingQuake)); } - }else if(existingQuake == null || existingQuake.getRevisionID() < checkPacket.info().revisionID()){ + } else if (existingQuake == null || existingQuake.getRevisionID() < checkPacket.info().revisionID()) { socket.sendPacket(new EarthquakeRequestPacket(uuid)); } } @@ -101,16 +101,16 @@ private void processQuakeDataPacket(HypocenterDataPacket hypocenterDataPacket) { Earthquake newQuake = createEarthquake(data, hypocenterDataPacket.advancedHypocenterData(), hypocenterDataPacket.clusterData()); // ignore quake data that are too old - if(shouldRemove(newQuake, 30)) { + if (shouldRemove(newQuake, 30)) { return; } - if(existingQuake == null) { + if (existingQuake == null) { clientEarthquakeMap.put(uuid, newQuake); getEarthquakes().add(newQuake); newQuake.getCluster().revisionID = data.revisionID(); GlobalQuake.instance.getEventHandler().fireEvent(new QuakeCreateEvent(newQuake)); - } else if(existingQuake.getRevisionID() < data.revisionID()) { + } else if (existingQuake.getRevisionID() < data.revisionID()) { existingQuake.update(newQuake); newQuake.getCluster().revisionID = data.revisionID(); GlobalQuake.instance.getEventHandler().fireEvent(new QuakeUpdateEvent(existingQuake, null)); @@ -119,21 +119,21 @@ private void processQuakeDataPacket(HypocenterDataPacket hypocenterDataPacket) { private Earthquake createEarthquake(HypocenterData hypocenterData, AdvancedHypocenterData advancedHypocenterData, ClusterData clusterData) { DepthConfidenceInterval depthConfidenceInterval = advancedHypocenterData == null ? null : createDepthConfidenceInterval(advancedHypocenterData.depthIntervalData()); - var polygonConfidenceIntervals =advancedHypocenterData == null ? null : createPolygonConfidenceIntervals(advancedHypocenterData.locationConfidenceIntervalData()); + var polygonConfidenceIntervals = advancedHypocenterData == null ? null : createPolygonConfidenceIntervals(advancedHypocenterData.locationConfidenceIntervalData()); Hypocenter hypocenter = new Hypocenter(hypocenterData.lat(), hypocenterData.lon(), hypocenterData.depth(), hypocenterData.origin(), - 0,0, depthConfidenceInterval, + 0, 0, depthConfidenceInterval, polygonConfidenceIntervals); hypocenter.magnitude = hypocenterData.magnitude(); - Cluster cluster = ((ClusterAnalysisClient)GlobalQuakeClient.instance.getClusterAnalysis()).getCluster(clusterData); + Cluster cluster = ((ClusterAnalysisClient) GlobalQuakeClient.instance.getClusterAnalysis()).getCluster(clusterData); - if(advancedHypocenterData != null){ + if (advancedHypocenterData != null) { hypocenter.quality = createQuality(advancedHypocenterData.qualityData()); StationCountData stationCountData = advancedHypocenterData.stationCountData(); - if(stationCountData != null) { + if (stationCountData != null) { hypocenter.totalEvents = stationCountData.total(); hypocenter.reducedEvents = stationCountData.reduced(); hypocenter.usedEvents = stationCountData.used(); @@ -142,8 +142,8 @@ private Earthquake createEarthquake(HypocenterData hypocenterData, AdvancedHypoc hypocenter.mags = new ArrayList<>(); - for(Float mag : advancedHypocenterData.magsData()){ - hypocenter.mags.add(new MagnitudeReading(mag, 0,55555, InputType.VELOCITY)); + for (Float mag : advancedHypocenterData.magsData()) { + hypocenter.mags.add(new MagnitudeReading(mag, 0, 55555, InputType.VELOCITY)); } } @@ -158,7 +158,7 @@ private Earthquake createEarthquake(HypocenterData hypocenterData, AdvancedHypoc private List createPolygonConfidenceIntervals(LocationConfidenceIntervalData locationConfidenceIntervalData) { List result = new ArrayList<>(); - for(var interval : locationConfidenceIntervalData.polygonConfidenceIntervalDataList()){ + for (var interval : locationConfidenceIntervalData.polygonConfidenceIntervalDataList()) { result.add(new PolygonConfidenceInterval(interval.n(), interval.offset(), interval.lengths().stream().map(Float::doubleValue).collect(Collectors.toList()), 0, 0)); } diff --git a/GlobalQuakeClient/src/main/java/globalquake/client/EarthquakeArchiveClient.java b/GlobalQuakeClient/src/main/java/globalquake/client/EarthquakeArchiveClient.java index 1bcee1e63..c274fb06e 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/client/EarthquakeArchiveClient.java +++ b/GlobalQuakeClient/src/main/java/globalquake/client/EarthquakeArchiveClient.java @@ -12,14 +12,14 @@ public class EarthquakeArchiveClient extends EarthquakeArchive { public void processPacket(ClientSocket ignoredSocket, Packet packet) { - if(packet instanceof ArchivedQuakePacket quakePacket) { - if(getArchivedQuakeByUUID(quakePacket.archivedQuakeData().uuid()) == null) { + if (packet instanceof ArchivedQuakePacket quakePacket) { + if (getArchivedQuakeByUUID(quakePacket.archivedQuakeData().uuid()) == null) { archiveQuake(quakePacket, null); } } } - public void archiveQuake(ArchivedQuakePacket quakePacket, Earthquake earthquake){ + public void archiveQuake(ArchivedQuakePacket quakePacket, Earthquake earthquake) { archiveQuake(createArchivedQuake(quakePacket), earthquake); } diff --git a/GlobalQuakeClient/src/main/java/globalquake/client/GlobalQuakeClient.java b/GlobalQuakeClient/src/main/java/globalquake/client/GlobalQuakeClient.java index 5ca59b5fd..b0ba029e3 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/client/GlobalQuakeClient.java +++ b/GlobalQuakeClient/src/main/java/globalquake/client/GlobalQuakeClient.java @@ -32,11 +32,11 @@ public GlobalQuakeClient(ClientSocket clientSocket) { super.seedlinkNetworksReader = new SeedlinkNetworksReaderClient(); this.clientSocket = clientSocket; - getLocalEventHandler().registerEventListener(new GlobalQuakeLocalEventListener(){ + getLocalEventHandler().registerEventListener(new GlobalQuakeLocalEventListener() { @Override public void onStationMonitorOpened(StationMonitorOpenEvent event) { try { - if(openedStationMonitors.stream().noneMatch(stationMonitor -> stationMonitor.getStation().getIdentifier().equals(event.station().getIdentifier()))) { + if (openedStationMonitors.stream().noneMatch(stationMonitor -> stationMonitor.getStation().getIdentifier().equals(event.station().getIdentifier()))) { clientSocket.sendPacket(new DataRequestPacket(event.station().getIdentifier(), false)); } @@ -50,7 +50,7 @@ public void onStationMonitorOpened(StationMonitorOpenEvent event) { public void onStationMonitorClosed(StationMonitorCloseEvent event) { try { openedStationMonitors.remove(event.monitor()); - if(openedStationMonitors.stream().noneMatch(stationMonitor -> stationMonitor.getStation().getIdentifier().equals(event.station().getIdentifier()))) { + if (openedStationMonitors.stream().noneMatch(stationMonitor -> stationMonitor.getStation().getIdentifier().equals(event.station().getIdentifier()))) { event.station().getAnalysis().fullReset(); clientSocket.sendPacket(new DataRequestPacket(event.station().getIdentifier(), true)); } @@ -62,7 +62,7 @@ public void onStationMonitorClosed(StationMonitorCloseEvent event) { @Override public void onSocketReconnect(SocketReconnectEvent socketReconnectEvent) { try { - for(StationMonitor monitor : new HashSet(openedStationMonitors)){ + for (StationMonitor monitor : new HashSet(openedStationMonitors)) { clientSocket.sendPacket(new DataRequestPacket(monitor.getStation().getIdentifier(), false)); } } catch (IOException e) { @@ -78,10 +78,10 @@ public void onStationCreate(StationCreateEvent stationCreateEvent) { } public void processPacket(ClientSocket socket, Packet packet) throws IOException { - ((EarthquakeAnalysisClient)getEarthquakeAnalysis()).processPacket(socket, packet); - ((EarthquakeArchiveClient)getArchive()).processPacket(socket, packet); - ((GlobalStationManagerClient)getStationManager()).processPacket(socket, packet); - ((ClusterAnalysisClient)getClusterAnalysis()).processPacket(socket, packet); + ((EarthquakeAnalysisClient) getEarthquakeAnalysis()).processPacket(socket, packet); + ((EarthquakeArchiveClient) getArchive()).processPacket(socket, packet); + ((GlobalStationManagerClient) getStationManager()).processPacket(socket, packet); + ((ClusterAnalysisClient) getClusterAnalysis()).processPacket(socket, packet); } @Override @@ -91,7 +91,7 @@ public GlobalQuakeLocal createFrame() { globalQuakeFrame.setVisible(true); Main.getErrorHandler().setParent(globalQuakeFrame); - }catch (Exception e){ + } catch (Exception e) { Logger.error(e); System.exit(0); } diff --git a/GlobalQuakeClient/src/main/java/globalquake/client/GlobalQuakeLocal.java b/GlobalQuakeClient/src/main/java/globalquake/client/GlobalQuakeLocal.java index e821b38cb..dc1953428 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/client/GlobalQuakeLocal.java +++ b/GlobalQuakeClient/src/main/java/globalquake/client/GlobalQuakeLocal.java @@ -80,7 +80,7 @@ public void windowClosing(WindowEvent e) { getArchive().saveArchive(); } }); - }catch (Exception e){ + } catch (Exception e) { Logger.error(e); System.exit(0); } diff --git a/GlobalQuakeClient/src/main/java/globalquake/client/GlobalStationManagerClient.java b/GlobalQuakeClient/src/main/java/globalquake/client/GlobalStationManagerClient.java index b1439ca6a..1c6877a6e 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/client/GlobalStationManagerClient.java +++ b/GlobalQuakeClient/src/main/java/globalquake/client/GlobalStationManagerClient.java @@ -26,7 +26,7 @@ public class GlobalStationManagerClient extends GlobalStationManager { private final Map stationsIdMap = new ConcurrentHashMap<>(); - public GlobalStationManagerClient(){ + public GlobalStationManagerClient() { stations = new CopyOnWriteArrayList<>(); } @@ -36,18 +36,18 @@ public void initStations(StationDatabaseManager databaseManager) { } public void processPacket(ClientSocket socket, Packet packet) { - if(packet instanceof StationsInfoPacket stationsInfoPacket){ + if (packet instanceof StationsInfoPacket stationsInfoPacket) { processStationsInfoPacket(socket, stationsInfoPacket); } else if (packet instanceof StationsIntensityPacket stationsIntensityPacket) { processStationsIntensityPacket(socket, stationsIntensityPacket); - } else if (packet instanceof DataRecordPacket dataRecordPacket){ + } else if (packet instanceof DataRecordPacket dataRecordPacket) { processDataRecordPacket(dataRecordPacket); } } private void processDataRecordPacket(DataRecordPacket dataRecordPacket) { ClientStation station = stationsIdMap.get(dataRecordPacket.stationIndex()); - if(station == null){ + if (station == null) { Logger.warn("Received data record but for unkown station!"); return; } @@ -62,24 +62,24 @@ private void processDataRecordPacket(DataRecordPacket dataRecordPacket) { } private void processStationsIntensityPacket(ClientSocket socket, StationsIntensityPacket stationsIntensityPacket) { - if(getIndexing() == null ||!getIndexing().equals(stationsIntensityPacket.stationsIndexing())){ + if (getIndexing() == null || !getIndexing().equals(stationsIntensityPacket.stationsIndexing())) { resetIndexing(socket, stationsIntensityPacket.stationsIndexing()); } - for(StationIntensityData stationIntensityData : stationsIntensityPacket.intensities()){ + for (StationIntensityData stationIntensityData : stationsIntensityPacket.intensities()) { ClientStation clientStation = stationsIdMap.get(stationIntensityData.index()); - if(clientStation != null){ + if (clientStation != null) { clientStation.setIntensity(stationIntensityData.maxIntensity(), stationsIntensityPacket.time(), stationIntensityData.eventMode()); } } } private void processStationsInfoPacket(ClientSocket socket, StationsInfoPacket stationsInfoPacket) { - if(getIndexing() == null || !getIndexing().equals(stationsInfoPacket.stationsIndexing())){ + if (getIndexing() == null || !getIndexing().equals(stationsInfoPacket.stationsIndexing())) { resetIndexing(socket, stationsInfoPacket.stationsIndexing()); } List list = new ArrayList<>(); - for(StationInfoData infoData : stationsInfoPacket.stationInfoDataList()) { - if(!stationsIdMap.containsKey(infoData.index())) { + for (StationInfoData infoData : stationsInfoPacket.stationInfoDataList()) { + if (!stationsIdMap.containsKey(infoData.index())) { ClientStation station; list.add(station = new ClientStation( infoData.network(), @@ -100,7 +100,7 @@ private void processStationsInfoPacket(ClientSocket socket, StationsInfoPacket s } private void resetIndexing(ClientSocket socket, UUID uuid) { - if(super.indexing != null) { + if (super.indexing != null) { Logger.info("Station indexing has changed, probably because the server has been restarted"); try { socket.sendPacket(new StationsRequestPacket()); diff --git a/GlobalQuakeClient/src/main/java/globalquake/events/GlobalQuakeLocalEventHandler.java b/GlobalQuakeClient/src/main/java/globalquake/events/GlobalQuakeLocalEventHandler.java index 501ab9951..76a20033d 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/events/GlobalQuakeLocalEventHandler.java +++ b/GlobalQuakeClient/src/main/java/globalquake/events/GlobalQuakeLocalEventHandler.java @@ -21,20 +21,20 @@ public GlobalQuakeLocalEventHandler runHandler() { return this; } - public void stopHandler(){ + public void stopHandler() { GlobalQuake.instance.stopService(executor); } - public void registerEventListener(GlobalQuakeLocalEventListener eventListener){ + public void registerEventListener(GlobalQuakeLocalEventListener eventListener) { eventListeners.add(eventListener); } @SuppressWarnings("unused") - public boolean removeEventListener(GlobalQuakeLocalEventListener eventListener){ + public boolean removeEventListener(GlobalQuakeLocalEventListener eventListener) { return eventListeners.remove(eventListener); } - public void fireEvent(GlobalQuakeLocalEvent event){ + public void fireEvent(GlobalQuakeLocalEvent event) { executor.submit(() -> { Logger.tag("Event").trace("GQLocal event fired: %s".formatted(event.toString())); for (GlobalQuakeLocalEventListener eventListener : eventListeners) { diff --git a/GlobalQuakeClient/src/main/java/globalquake/events/GlobalQuakeLocalEventListener.java b/GlobalQuakeClient/src/main/java/globalquake/events/GlobalQuakeLocalEventListener.java index 38a982c09..3e3c7f22a 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/events/GlobalQuakeLocalEventListener.java +++ b/GlobalQuakeClient/src/main/java/globalquake/events/GlobalQuakeLocalEventListener.java @@ -4,17 +4,24 @@ public class GlobalQuakeLocalEventListener { - public void onWarningIssued(AlertIssuedEvent event) {} + public void onWarningIssued(AlertIssuedEvent event) { + } - public void onShakemapCreated(ShakeMapsUpdatedEvent ignoredEvent) {} + public void onShakemapCreated(ShakeMapsUpdatedEvent ignoredEvent) { + } - public void onCinemaModeTargetSwitch(CinemaEvent event) {} + public void onCinemaModeTargetSwitch(CinemaEvent event) { + } - public void onStationMonitorOpened(StationMonitorOpenEvent stationMonitorOpenEvent) {} + public void onStationMonitorOpened(StationMonitorOpenEvent stationMonitorOpenEvent) { + } - public void onStationMonitorClosed(StationMonitorCloseEvent stationMonitorCloseEvent) {} + public void onStationMonitorClosed(StationMonitorCloseEvent stationMonitorCloseEvent) { + } - public void onSocketReconnect(SocketReconnectEvent ignoredSocketReconnectEvent) {} + public void onSocketReconnect(SocketReconnectEvent ignoredSocketReconnectEvent) { + } - public void onStationCreate(StationCreateEvent stationCreateEvent) {} + public void onStationCreate(StationCreateEvent stationCreateEvent) { + } } diff --git a/GlobalQuakeClient/src/main/java/globalquake/events/specific/StationMonitorOpenEvent.java b/GlobalQuakeClient/src/main/java/globalquake/events/specific/StationMonitorOpenEvent.java index b9bad73ce..eee970a3e 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/events/specific/StationMonitorOpenEvent.java +++ b/GlobalQuakeClient/src/main/java/globalquake/events/specific/StationMonitorOpenEvent.java @@ -3,7 +3,8 @@ import globalquake.core.station.GlobalStation; import globalquake.events.GlobalQuakeLocalEventListener; -public record StationMonitorOpenEvent(globalquake.ui.StationMonitor stationMonitor, GlobalStation station) implements GlobalQuakeLocalEvent { +public record StationMonitorOpenEvent(globalquake.ui.StationMonitor stationMonitor, + GlobalStation station) implements GlobalQuakeLocalEvent { @Override public void run(GlobalQuakeLocalEventListener eventListener) { diff --git a/GlobalQuakeClient/src/main/java/globalquake/intensity/IntensityHex.java b/GlobalQuakeClient/src/main/java/globalquake/intensity/IntensityHex.java index 322d57355..9f7200f0e 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/intensity/IntensityHex.java +++ b/GlobalQuakeClient/src/main/java/globalquake/intensity/IntensityHex.java @@ -4,7 +4,7 @@ import java.util.Objects; -public record IntensityHex(long id, double pga, Point2D center) implements Comparable{ +public record IntensityHex(long id, double pga, Point2D center) implements Comparable { @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/GlobalQuakeClient/src/main/java/globalquake/intensity/ShakeMap.java b/GlobalQuakeClient/src/main/java/globalquake/intensity/ShakeMap.java index 4b850d7bf..edc4615e2 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/intensity/ShakeMap.java +++ b/GlobalQuakeClient/src/main/java/globalquake/intensity/ShakeMap.java @@ -21,7 +21,7 @@ public class ShakeMap { private final int res; private double maxPGA; - public static void init() throws IOException{ + public static void init() throws IOException { h3 = H3Core.newInstance(); } @@ -36,7 +36,7 @@ private void generate(Hypocenter hypocenter, int res) { IntensityScale intensityScale = IntensityScales.getIntensityScale(); double pga = GeoUtils.pgaFunction(hypocenter.magnitude, hypocenter.depth, hypocenter.depth); Level level = intensityScale.getLevel(pga); - if(level == null){ + if (level == null) { return; } @@ -56,7 +56,7 @@ private Set bfs(IntensityHex intensityHex, Hypocenter hypocenter, Queue pq = new PriorityQueue<>(); pq.add(intensityHex); - while(!pq.isEmpty()) { + while (!pq.isEmpty()) { IntensityHex current = pq.remove(); result.add(current); diff --git a/GlobalQuakeClient/src/main/java/globalquake/main/Main.java b/GlobalQuakeClient/src/main/java/globalquake/main/Main.java index 1bf05d9dd..7a68f9627 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/main/Main.java +++ b/GlobalQuakeClient/src/main/java/globalquake/main/Main.java @@ -87,7 +87,7 @@ private static void initMainDirectory() { } public static ApplicationErrorHandler getErrorHandler() { - if(errorHandler == null) { + if (errorHandler == null) { errorHandler = new ApplicationErrorHandler(null, false); } return errorHandler; diff --git a/GlobalQuakeClient/src/main/java/globalquake/playground/DecimalInputDialog.java b/GlobalQuakeClient/src/main/java/globalquake/playground/DecimalInputDialog.java index 420803456..fe7d52816 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/playground/DecimalInputDialog.java +++ b/GlobalQuakeClient/src/main/java/globalquake/playground/DecimalInputDialog.java @@ -13,7 +13,7 @@ public class DecimalInputDialog extends JDialog { public DecimalInputDialog(JFrame parent, String title, java.util.List decimalInputs, Runnable action) { super(parent, title, true); - this. decimalInputs = decimalInputs; + this.decimalInputs = decimalInputs; sliders = new JSlider[decimalInputs.size()]; @@ -26,7 +26,7 @@ public DecimalInputDialog(JFrame parent, String title, java.util.List earthquakeDistancesMap = new ConcurrentHashMap<>(); - static{ - for(int i = 0; i < STEPS; i++){ + static { + for (int i = 0; i < STEPS; i++) { double freq = MIN_FREQ * Math.pow(2, i); FREQS[i] = freq; BACKGROUND_NOISES[i] = backgroundNoise(freq); @@ -66,6 +66,7 @@ public Distances(Earthquake earthquake, AbstractStation station) { private static double backgroundNoise(double freq) { return (freq * 120000.0) / (160 * (freq - 0.15) * (freq - 0.15) + 1); } + private static final Random r = new Random(); public StationWaveformGenerator(AbstractStation station, int seed) { @@ -73,10 +74,10 @@ public StationWaveformGenerator(AbstractStation station, int seed) { sensMul = Math.pow(100, r.nextGaussian() * 0.12 + 0.5) / 10.0; // todo setting maybe for the 0.12 bias = (long) Math.abs(r.nextGaussian() * TIME_BIAS); delay = (long) Math.abs(r.nextGaussian() * DELAY_BIAS); - for(int i = 0; i < STEPS; i++){ + for (int i = 0; i < STEPS; i++) { double freq = FREQS[i]; noises[i] = new Perlin(); - noises[i].setSeed(seed + i*23); + noises[i].setSeed(seed + i * 23); noises[i].setOctaveCount(1); noises[i].setFrequency(freq); } @@ -88,8 +89,8 @@ public long getDelay() { public int getValue(long time) { double sum = 0.0; - for(int i = 0; i < STEPS; i++) { - sum += noises[i].getValue(time / 1000.0,0,0) * getPower(i, time); + for (int i = 0; i < STEPS; i++) { + sum += noises[i].getValue(time / 1000.0, 0, 0) * getPower(i, time); } return (int) sum; } @@ -98,20 +99,20 @@ private double getPower(int i, long time) { double freq = FREQS[i]; double result = BACKGROUND_NOISES[i]; - for(Earthquake earthquake : ((GlobalQuakePlayground) GlobalQuake.instance).getPlaygroundEarthquakes()){ + for (Earthquake earthquake : ((GlobalQuakePlayground) GlobalQuake.instance).getPlaygroundEarthquakes()) { result += getPowerFromQuake(earthquake, freq, time - bias, i); } return result; } - public void second(){ + public void second() { earthquakeDistancesMap.entrySet().removeIf(kv -> EarthquakeAnalysis.shouldRemove(kv.getKey(), 0)); } private double getPowerFromQuake(Earthquake earthquake, double freq, long time, int i) { Distances distances = earthquakeDistancesMap.get(earthquake); - if(distances == null){ + if (distances == null) { earthquakeDistancesMap.put(earthquake, distances = new Distances(earthquake, station)); } @@ -127,13 +128,13 @@ private double getPowerFromQuake(Earthquake earthquake, double freq, long time, double m = earthquake.getMag() + gcd / 30.0; double m2 = (m * m); - if(_secondsP < 0 && distances.pTravel >= 0){ - double decay = (m2) / (_secondsP * _secondsP+ m2); + if (_secondsP < 0 && distances.pTravel >= 0) { + double decay = (m2) / (_secondsP * _secondsP + m2); double increase = Math.min(1.0, (-_secondsP) / earthquake.getMag()); result += 2E3 * decay * increase; } - if(_secondsS < 0 && distances.sTravel >= 0){ + if (_secondsS < 0 && distances.sTravel >= 0) { double decay = (m2) / (_secondsS * _secondsS + m2); double increase = Math.min(1.0, (-_secondsS) / earthquake.getMag()); result += 2E3 * decay * increase * psRatio(gcd); diff --git a/GlobalQuakeClient/src/main/java/globalquake/playground/WaveformGenerator.java b/GlobalQuakeClient/src/main/java/globalquake/playground/WaveformGenerator.java index c43ff4ead..2dc1f5958 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/playground/WaveformGenerator.java +++ b/GlobalQuakeClient/src/main/java/globalquake/playground/WaveformGenerator.java @@ -18,22 +18,22 @@ public WaveformGenerator(GlobalQuakePlayground globalQuakePlayground) { private void updateWaveforms() { try { globalQuakePlayground.getStationManager().getStations().parallelStream().forEach(WaveformGenerator::generateWaveform); - }catch(Exception e){ + } catch (Exception e) { Logger.error(e); } - } + } private static void generateWaveform(AbstractStation station) { PlaygroundStation playgroundStation = (PlaygroundStation) station; long lastLog = playgroundStation.lastSampleTime; long now = GlobalQuake.instance.currentTimeMillis() - playgroundStation.getDelay(); - if(lastLog < 0){ + if (lastLog < 0) { lastLog = now - 2 * 60 * 1000; } - while(lastLog < now) { + while (lastLog < now) { station.getAnalysis().nextSample( playgroundStation.getNoise(lastLog), lastLog, diff --git a/GlobalQuakeClient/src/main/java/globalquake/sounds/SoundsInfo.java b/GlobalQuakeClient/src/main/java/globalquake/sounds/SoundsInfo.java index ea80fdb1e..f0bf7ca99 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/sounds/SoundsInfo.java +++ b/GlobalQuakeClient/src/main/java/globalquake/sounds/SoundsInfo.java @@ -2,13 +2,13 @@ public class SoundsInfo { - public int maxLevel = -1; - public double maxPGA; - public double maxPGAHome; - public boolean warningPlayed; - public int lastCountdown = 999; - public boolean meets; - - public final long createdAt = System.currentTimeMillis(); + public int maxLevel = -1; + public double maxPGA; + public double maxPGAHome; + public boolean warningPlayed; + public int lastCountdown = 999; + public boolean meets; + + public final long createdAt = System.currentTimeMillis(); } diff --git a/GlobalQuakeClient/src/main/java/globalquake/sounds/SoundsService.java b/GlobalQuakeClient/src/main/java/globalquake/sounds/SoundsService.java index 4d261f07f..5f5e83779 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/sounds/SoundsService.java +++ b/GlobalQuakeClient/src/main/java/globalquake/sounds/SoundsService.java @@ -24,14 +24,14 @@ public class SoundsService { private final Map clusterSoundsInfo = new HashMap<>(); private final ScheduledExecutorService soundCheckService; - public SoundsService(){ + public SoundsService() { soundCheckService = Executors.newSingleThreadScheduledExecutor(); soundCheckService.scheduleAtFixedRate(this::checkSounds, 0, 200, TimeUnit.MILLISECONDS); - GlobalQuake.instance.getEventHandler().registerEventListener(new GlobalQuakeEventListener(){ + GlobalQuake.instance.getEventHandler().registerEventListener(new GlobalQuakeEventListener() { @Override public void onQuakeCreate(QuakeCreateEvent event) { - if(SoundsService.this.canPing(event.earthquake())) { + if (SoundsService.this.canPing(event.earthquake())) { Sounds.playSound(Sounds.found); event.earthquake().foundPlayed = true; } @@ -39,8 +39,8 @@ public void onQuakeCreate(QuakeCreateEvent event) { @Override public void onQuakeUpdate(QuakeUpdateEvent event) { - if(SoundsService.this.canPing(event.earthquake())) { - if(!event.earthquake().foundPlayed){ + if (SoundsService.this.canPing(event.earthquake())) { + if (!event.earthquake().foundPlayed) { Sounds.playSound(Sounds.found); event.earthquake().foundPlayed = true; } else { @@ -54,7 +54,7 @@ public void onQuakeUpdate(QuakeUpdateEvent event) { private void checkSounds() { try { - if(GlobalQuake.instance.getClusterAnalysis() == null ||GlobalQuake.instance.getEarthquakeAnalysis() == null){ + if (GlobalQuake.instance.getClusterAnalysis() == null || GlobalQuake.instance.getEarthquakeAnalysis() == null) { return; } @@ -67,7 +67,7 @@ private void checkSounds() { } clusterSoundsInfo.entrySet().removeIf(kv -> System.currentTimeMillis() - kv.getValue().createdAt > 1000 * 60 * 100); - }catch(Exception e){ + } catch (Exception e) { Logger.error(e); } } @@ -75,13 +75,13 @@ private void checkSounds() { public void determineSounds(Cluster cluster) { SoundsInfo info = clusterSoundsInfo.get(cluster); - if(info == null){ + if (info == null) { clusterSoundsInfo.put(cluster, info = new SoundsInfo()); } int level = cluster.getLevel(); if (level > info.maxLevel && (canPing(cluster) || canPing(cluster.getEarthquake()))) { - if(info.maxLevel < 0){ + if (info.maxLevel < 0) { Sounds.playSound(Sounds.level_0); } if (level >= 1 && info.maxLevel < 1) { @@ -154,7 +154,7 @@ public void determineSounds(Cluster cluster) { private boolean canPing(Earthquake earthquake) { - if(earthquake == null || !Settings.enableEarthquakeSounds){ + if (earthquake == null || !Settings.enableEarthquakeSounds) { return false; } @@ -163,14 +163,14 @@ private boolean canPing(Earthquake earthquake) { } private boolean canPing(Cluster cluster) { - if(cluster == null || !Settings.alertPossibleShaking){ + if (cluster == null || !Settings.alertPossibleShaking) { return false; } double distGCD = GeoUtils.greatCircleDistance(cluster.getRootLat(), cluster.getRootLon(), Settings.homeLat, Settings.homeLon); return !(distGCD > Settings.alertPossibleShakingDistance); } - public void destroy(){ + public void destroy() { GlobalQuake.instance.stopService(soundCheckService); } diff --git a/GlobalQuakeClient/src/main/java/globalquake/ui/StationMonitor.java b/GlobalQuakeClient/src/main/java/globalquake/ui/StationMonitor.java index 59027d28e..b85f6560b 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/ui/StationMonitor.java +++ b/GlobalQuakeClient/src/main/java/globalquake/ui/StationMonitor.java @@ -14,93 +14,93 @@ public class StationMonitor extends GQFrame { - private final StationMonitorPanel stationMonitorPanel; - private AbstractStation station; - - public StationMonitor(Component parent, AbstractStation station, int refreshTime) { - this.station = station; - - if(GlobalQuakeLocal.instance != null && station instanceof GlobalStation globalStation){ - GlobalQuakeLocal.instance.getLocalEventHandler().fireEvent(new StationMonitorOpenEvent(StationMonitor.this, globalStation)); - } - - setLayout(new BorderLayout()); - - add(createControlPanel(), BorderLayout.NORTH); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - stationMonitorPanel = new StationMonitorPanel(station); - add(stationMonitorPanel, BorderLayout.CENTER); - - pack(); - - setLocationRelativeTo(parent); - setResizable(true); - setTitle("Station Monitor - " + station.getNetworkCode() + " " + station.getStationCode() + " " - + station.getChannelName() + " " + station.getLocationCode()); - - Timer timer = new Timer(); - timer.scheduleAtFixedRate(new TimerTask() { - public void run() { - stationMonitorPanel.updateImage(); - stationMonitorPanel.repaint(); - } - }, 0, refreshTime); - - addWindowListener(new WindowAdapter() { - - @Override - public void windowClosed(WindowEvent e) { - timer.cancel(); - if(GlobalQuakeLocal.instance != null && station instanceof GlobalStation globalStation){ - GlobalQuakeLocal.instance.getLocalEventHandler().fireEvent(new StationMonitorCloseEvent(StationMonitor.this, globalStation)); - } - } - }); - - addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - System.err.println("K"); - if(e.getKeyCode() == KeyEvent.VK_ESCAPE){ - System.err.println("ESC"); - dispose(); - } - } - }); - - stationMonitorPanel.addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - stationMonitorPanel.updateImage(); - stationMonitorPanel.repaint(); - } - }); - - setVisible(true); - } - - private Component createControlPanel() { - JPanel panel = new JPanel(); - - JCheckBox chkBoxDisable = new JCheckBox("Disable event picking", station.disabled); - chkBoxDisable.addActionListener(new AbstractAction() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - station.disabled = chkBoxDisable.isSelected(); - } - }); - - panel.add(chkBoxDisable); - - return panel; - } - - public AbstractStation getStation() { - return station; - } - - public void swapStation(GlobalStation station) { - this.station = station; - stationMonitorPanel.setStation(station); - } + private final StationMonitorPanel stationMonitorPanel; + private AbstractStation station; + + public StationMonitor(Component parent, AbstractStation station, int refreshTime) { + this.station = station; + + if (GlobalQuakeLocal.instance != null && station instanceof GlobalStation globalStation) { + GlobalQuakeLocal.instance.getLocalEventHandler().fireEvent(new StationMonitorOpenEvent(StationMonitor.this, globalStation)); + } + + setLayout(new BorderLayout()); + + add(createControlPanel(), BorderLayout.NORTH); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + stationMonitorPanel = new StationMonitorPanel(station); + add(stationMonitorPanel, BorderLayout.CENTER); + + pack(); + + setLocationRelativeTo(parent); + setResizable(true); + setTitle("Station Monitor - " + station.getNetworkCode() + " " + station.getStationCode() + " " + + station.getChannelName() + " " + station.getLocationCode()); + + Timer timer = new Timer(); + timer.scheduleAtFixedRate(new TimerTask() { + public void run() { + stationMonitorPanel.updateImage(); + stationMonitorPanel.repaint(); + } + }, 0, refreshTime); + + addWindowListener(new WindowAdapter() { + + @Override + public void windowClosed(WindowEvent e) { + timer.cancel(); + if (GlobalQuakeLocal.instance != null && station instanceof GlobalStation globalStation) { + GlobalQuakeLocal.instance.getLocalEventHandler().fireEvent(new StationMonitorCloseEvent(StationMonitor.this, globalStation)); + } + } + }); + + addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + System.err.println("K"); + if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { + System.err.println("ESC"); + dispose(); + } + } + }); + + stationMonitorPanel.addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + stationMonitorPanel.updateImage(); + stationMonitorPanel.repaint(); + } + }); + + setVisible(true); + } + + private Component createControlPanel() { + JPanel panel = new JPanel(); + + JCheckBox chkBoxDisable = new JCheckBox("Disable event picking", station.disabled); + chkBoxDisable.addActionListener(new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + station.disabled = chkBoxDisable.isSelected(); + } + }); + + panel.add(chkBoxDisable); + + return panel; + } + + public AbstractStation getStation() { + return station; + } + + public void swapStation(GlobalStation station) { + this.station = station; + stationMonitorPanel.setStation(station); + } } diff --git a/GlobalQuakeClient/src/main/java/globalquake/ui/StationMonitorPanel.java b/GlobalQuakeClient/src/main/java/globalquake/ui/StationMonitorPanel.java index e2cd11ad7..a0cc4f1b3 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/ui/StationMonitorPanel.java +++ b/GlobalQuakeClient/src/main/java/globalquake/ui/StationMonitorPanel.java @@ -20,256 +20,256 @@ public class StationMonitorPanel extends JPanel { - private static final double HEIGHT_1 = 0.33; - - private static final double HEIGHT_2 = 0.66; - private BufferedImage image; - private AbstractStation station; - - public StationMonitorPanel(AbstractStation station) { - this.station = station; - setLayout(null); - setPreferredSize(new Dimension(600, 500)); - setSize(getPreferredSize()); - updateImage(); - } - - private static final Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, - new float[] { 3 }, 0); - - public void updateImage() { - int w = getWidth(); - int h = getHeight(); - BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR); - Graphics2D g = img.createGraphics(); - g.setColor(Color.white); - g.fillRect(0, 0, w, h); - - g.setColor(Color.black); - g.setFont(new Font("Calibri", Font.BOLD, 14)); - g.drawString("Raw Data", 4, 14); - g.drawString("Band Pass %sHz - %sHz".formatted(BetterAnalysis.minFreqDefault, BetterAnalysis.maxFreqDefault), 4, (int) (h * HEIGHT_1 + 14)); - g.drawString("Averages Ratio", 4, (int) (h * HEIGHT_2 + 14)); - - long upperMinute = (long) (Math.ceil(getTime()/ (1000 * 60.0) + 1) * (1000L * 60L)); - for (int deltaSec = 0; deltaSec <= 60 * Settings.logsStoreTimeMinutes + 80; deltaSec += 10) { - long time = upperMinute - deltaSec * 1000L; - boolean fullMinute = time % 60000 == 0; - double x = getX(time); - g.setColor(!fullMinute ? Color.lightGray : Color.gray); - g.setStroke(!fullMinute ? dashed : new BasicStroke(2f)); - g.draw(new Line2D.Double(x, 0, x, getHeight())); - } - - java.util.List logs = getLogs(); - - if (logs.size() > 1) { - double maxValue = -Double.MAX_VALUE; - double minValue = Double.MAX_VALUE; - double maxFilteredValue = -Double.MAX_VALUE; - double minFilteredValue = Double.MAX_VALUE; - double maxRatio = 0; - for (Log l : logs) { - int v = l.rawValue(); - if (v > maxValue) { - maxValue = v; - } - if (v < minValue) { - minValue = v; - } - - double fv = l.filteredV(); - if (fv > maxFilteredValue) { - maxFilteredValue = fv; - } - if (fv < minFilteredValue) { - minFilteredValue = fv; - } - - double ratio = l.ratio(); - double medRatio = l.mediumRatio(); - double specRatio = l.specialRatio(); - if (ratio > maxRatio) { - maxRatio = ratio; - } - if (medRatio > maxRatio) { - maxRatio = medRatio; - } - if (specRatio > maxRatio) { - maxRatio = specRatio; - } - } - - maxValue += 10.0; - minValue -= 10.0; - - double fix1 = (maxValue - minValue) * 0.25 * 0.5; - maxValue += fix1; - minValue -= fix1; - - double fix2 = (maxFilteredValue - minFilteredValue) * 0.25 * 0.5; - maxFilteredValue += fix2; - minFilteredValue -= fix2; - - - for (int i = 0; i < logs.size() - 1; i++) { - Log a = logs.get(i); - Log b = logs.get(i + 1); - - boolean gap = (a.time() - b.time()) > (1000.0 / station.getAnalysis().getSampleRate()) * 2; - if (gap) { - continue; - } - - double x1 = getX(a.time()); - double x2 = getX(b.time()); - - double y1 = 0 + (getHeight() * HEIGHT_1) * (maxValue - a.rawValue()) / (maxValue - minValue); - double y2 = 0 + (getHeight() * HEIGHT_1) * (maxValue - b.rawValue()) / (maxValue - minValue); - - double y3 = getHeight() * HEIGHT_1 + (getHeight() * HEIGHT_1) * (maxFilteredValue - a.filteredV()) - / (maxFilteredValue - minFilteredValue); - double y4 = getHeight() * HEIGHT_1 + (getHeight() * HEIGHT_1) * (maxFilteredValue - b.filteredV()) - / (maxFilteredValue - minFilteredValue); - - double y11 = getHeight() * HEIGHT_2 + (getHeight() * (1 - HEIGHT_2)) * (maxRatio - a.ratio()) / (maxRatio); - double y12 = getHeight() * HEIGHT_2 + (getHeight() * (1 - HEIGHT_2)) * (maxRatio - b.ratio()) / (maxRatio); - - double y13 = getHeight() * HEIGHT_2 + (getHeight() * (1 - HEIGHT_2)) * (maxRatio - a.mediumRatio()) / (maxRatio); - double y14 = getHeight() * HEIGHT_2 + (getHeight() * (1 - HEIGHT_2)) * (maxRatio - b.mediumRatio()) / (maxRatio); - - double y13c = getHeight() * HEIGHT_2 + (getHeight() * (1 - HEIGHT_2)) * (maxRatio - a.specialRatio()) / (maxRatio); - double y14c = getHeight() * HEIGHT_2 + (getHeight() * (1 - HEIGHT_2)) * (maxRatio - b.specialRatio()) / (maxRatio); - - double yA = getHeight() * HEIGHT_2 + (getHeight() * (1 - HEIGHT_2)) * (maxRatio - 1.0) / (maxRatio); - - g.setColor(Color.blue); - g.setStroke(new BasicStroke(1f)); - g.draw(new Line2D.Double(x1, y1, x2, y2)); - - g.setColor(Color.orange); - g.setStroke(new BasicStroke(1f)); - g.draw(new Line2D.Double(x1, y3, x2, y4)); - - g.setColor(Color.blue); - g.setStroke(new BasicStroke(2f)); - g.draw(new Line2D.Double(x1, y13, x2, y14)); - - g.setColor(Color.red); - g.setStroke(new BasicStroke(2f)); - g.draw(new Line2D.Double(x1, y13c, x2, y14c)); - - g.setColor(Color.black); - g.setStroke(new BasicStroke(1f)); - g.draw(new Line2D.Double(x1, y11, x2, y12)); - - g.setColor(Color.red); - g.setStroke(new BasicStroke(1f)); - g.draw(new Line2D.Double(x1, yA, x2, yA)); - - for (double d : Event.RECALCULATE_P_WAVE_THRESHOLDS) { - double _y = getHeight() * HEIGHT_2 + (getHeight() * (1 - HEIGHT_2)) * (maxRatio - d) / (maxRatio); - if (_y > getHeight() * HEIGHT_2) { - g.setColor(Color.magenta); - g.setStroke(new BasicStroke(1f)); - g.draw(new Line2D.Double(x1, _y, x2, _y)); - } - } - - } - } - - for (Event e : station.getAnalysis().getDetectedEvents()) { - if(!e.isValid()){ - continue; - } - double x = getX(e.getpWave()); - g.setColor(e.isSWave() ? Color.red : Color.blue); - g.setStroke(new BasicStroke(2f)); - g.draw(new Line2D.Double(x, 0, x, getHeight())); - } - - if(GlobalQuake.instance != null) { - for (Earthquake earthquake : GlobalQuake.instance.getEarthquakeAnalysis().getEarthquakes()) { - double distGC = GeoUtils.greatCircleDistance(station.getLatitude(), station.getLongitude(), earthquake.getLat(), earthquake.getLon()); - // todo handle no arrival, but anyway this entire thing will get reworked. - long arrivalP = (long) (earthquake.getOrigin() + 1000 * (TauPTravelTimeCalculator.getPWaveTravelTime(earthquake.getDepth(), - TauPTravelTimeCalculator.toAngle(distGC)) + EarthquakeAnalysis.getElevationCorrection(station.getAlt()))); - - long arrivalS = (long) (earthquake.getOrigin() + 1000 * (TauPTravelTimeCalculator.getSWaveTravelTime(earthquake.getDepth(), - TauPTravelTimeCalculator.toAngle(distGC)) + EarthquakeAnalysis.getElevationCorrection(station.getAlt()))); - - double xP = getX(arrivalP); - double xS = getX(arrivalS); - - g.setColor(Color.magenta); - g.setStroke(dashed); - g.draw(new Line2D.Double(xP, 0, xP, getHeight())); - g.draw(new Line2D.Double(xS, 0, xS, getHeight())); - - double x1 = getX((long) (arrivalP - Settings.pWaveInaccuracyThreshold)); - double x2 = getX((long) (arrivalP + Settings.pWaveInaccuracyThreshold)); - double x3 = getX((long) (arrivalS - Settings.pWaveInaccuracyThreshold)); - double x4 = getX((long) (arrivalS + Settings.pWaveInaccuracyThreshold)); - - g.setColor(new Color(0, 0, 255, 80)); - g.fill(new Rectangle2D.Double(x1, 0, x2 - x1, h)); - - g.setColor(new Color(255, 0, 0, 80)); - g.fill(new Rectangle2D.Double(x3, 0, x4 - x3, h)); - } - } - - g.setColor(Color.black); - g.setStroke(new BasicStroke(2f)); - g.draw(new Rectangle2D.Double(0, 0, w - 1, h - 1)); - g.draw(new Rectangle2D.Double(0, 0, w - 1, (h - 1) * HEIGHT_1)); - g.draw(new Rectangle2D.Double(0, h * HEIGHT_1, w - 1, (h - 1) * HEIGHT_1)); - g.draw(new Rectangle2D.Double(0, h * HEIGHT_2, w - 1, (h - 1) * (1 - HEIGHT_2))); - - g.dispose(); - - this.image = img; - } - - private java.util.List getLogs() { - java.util.List logs = new ArrayList<>(); - - WaveformBuffer waveformBuffer = station.getAnalysis().getWaveformBuffer(); - - if(waveformBuffer != null) { - try{ - waveformBuffer.getReadLock().lock(); - if (!station.getAnalysis().getWaveformBuffer().isEmpty()) { - int index = station.getAnalysis().getWaveformBuffer().getOldestDataSlot(); - while (index != station.getAnalysis().getWaveformBuffer().getNewestDataSlot()) { - logs.add(station.getAnalysis().getWaveformBuffer().toLog(index)); - index = (index + 1) % station.getAnalysis().getWaveformBuffer().getSize(); - } - } - } finally { - waveformBuffer.getReadLock().unlock(); - } - } - return logs; - } - - private long getTime() { - return GlobalQuake.instance != null ? GlobalQuake.instance.currentTimeMillis() : System.currentTimeMillis(); - } - - private double getX(long time) { - return getWidth() * (1 - (getTime() - time) / (Settings.logsStoreTimeMinutes * 60 * 1000.0)); - } - - @Override - public void paint(Graphics gr) { - super.paint(gr); - Graphics2D g = (Graphics2D) gr; - g.drawImage(image, 0, 0, null); - } - - public void setStation(AbstractStation station) { - this.station = station; - } + private static final double HEIGHT_1 = 0.33; + + private static final double HEIGHT_2 = 0.66; + private BufferedImage image; + private AbstractStation station; + + public StationMonitorPanel(AbstractStation station) { + this.station = station; + setLayout(null); + setPreferredSize(new Dimension(600, 500)); + setSize(getPreferredSize()); + updateImage(); + } + + private static final Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, + new float[]{3}, 0); + + public void updateImage() { + int w = getWidth(); + int h = getHeight(); + BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR); + Graphics2D g = img.createGraphics(); + g.setColor(Color.white); + g.fillRect(0, 0, w, h); + + g.setColor(Color.black); + g.setFont(new Font("Calibri", Font.BOLD, 14)); + g.drawString("Raw Data", 4, 14); + g.drawString("Band Pass %sHz - %sHz".formatted(BetterAnalysis.minFreqDefault, BetterAnalysis.maxFreqDefault), 4, (int) (h * HEIGHT_1 + 14)); + g.drawString("Averages Ratio", 4, (int) (h * HEIGHT_2 + 14)); + + long upperMinute = (long) (Math.ceil(getTime() / (1000 * 60.0) + 1) * (1000L * 60L)); + for (int deltaSec = 0; deltaSec <= 60 * Settings.logsStoreTimeMinutes + 80; deltaSec += 10) { + long time = upperMinute - deltaSec * 1000L; + boolean fullMinute = time % 60000 == 0; + double x = getX(time); + g.setColor(!fullMinute ? Color.lightGray : Color.gray); + g.setStroke(!fullMinute ? dashed : new BasicStroke(2f)); + g.draw(new Line2D.Double(x, 0, x, getHeight())); + } + + java.util.List logs = getLogs(); + + if (logs.size() > 1) { + double maxValue = -Double.MAX_VALUE; + double minValue = Double.MAX_VALUE; + double maxFilteredValue = -Double.MAX_VALUE; + double minFilteredValue = Double.MAX_VALUE; + double maxRatio = 0; + for (Log l : logs) { + int v = l.rawValue(); + if (v > maxValue) { + maxValue = v; + } + if (v < minValue) { + minValue = v; + } + + double fv = l.filteredV(); + if (fv > maxFilteredValue) { + maxFilteredValue = fv; + } + if (fv < minFilteredValue) { + minFilteredValue = fv; + } + + double ratio = l.ratio(); + double medRatio = l.mediumRatio(); + double specRatio = l.specialRatio(); + if (ratio > maxRatio) { + maxRatio = ratio; + } + if (medRatio > maxRatio) { + maxRatio = medRatio; + } + if (specRatio > maxRatio) { + maxRatio = specRatio; + } + } + + maxValue += 10.0; + minValue -= 10.0; + + double fix1 = (maxValue - minValue) * 0.25 * 0.5; + maxValue += fix1; + minValue -= fix1; + + double fix2 = (maxFilteredValue - minFilteredValue) * 0.25 * 0.5; + maxFilteredValue += fix2; + minFilteredValue -= fix2; + + + for (int i = 0; i < logs.size() - 1; i++) { + Log a = logs.get(i); + Log b = logs.get(i + 1); + + boolean gap = (a.time() - b.time()) > (1000.0 / station.getAnalysis().getSampleRate()) * 2; + if (gap) { + continue; + } + + double x1 = getX(a.time()); + double x2 = getX(b.time()); + + double y1 = 0 + (getHeight() * HEIGHT_1) * (maxValue - a.rawValue()) / (maxValue - minValue); + double y2 = 0 + (getHeight() * HEIGHT_1) * (maxValue - b.rawValue()) / (maxValue - minValue); + + double y3 = getHeight() * HEIGHT_1 + (getHeight() * HEIGHT_1) * (maxFilteredValue - a.filteredV()) + / (maxFilteredValue - minFilteredValue); + double y4 = getHeight() * HEIGHT_1 + (getHeight() * HEIGHT_1) * (maxFilteredValue - b.filteredV()) + / (maxFilteredValue - minFilteredValue); + + double y11 = getHeight() * HEIGHT_2 + (getHeight() * (1 - HEIGHT_2)) * (maxRatio - a.ratio()) / (maxRatio); + double y12 = getHeight() * HEIGHT_2 + (getHeight() * (1 - HEIGHT_2)) * (maxRatio - b.ratio()) / (maxRatio); + + double y13 = getHeight() * HEIGHT_2 + (getHeight() * (1 - HEIGHT_2)) * (maxRatio - a.mediumRatio()) / (maxRatio); + double y14 = getHeight() * HEIGHT_2 + (getHeight() * (1 - HEIGHT_2)) * (maxRatio - b.mediumRatio()) / (maxRatio); + + double y13c = getHeight() * HEIGHT_2 + (getHeight() * (1 - HEIGHT_2)) * (maxRatio - a.specialRatio()) / (maxRatio); + double y14c = getHeight() * HEIGHT_2 + (getHeight() * (1 - HEIGHT_2)) * (maxRatio - b.specialRatio()) / (maxRatio); + + double yA = getHeight() * HEIGHT_2 + (getHeight() * (1 - HEIGHT_2)) * (maxRatio - 1.0) / (maxRatio); + + g.setColor(Color.blue); + g.setStroke(new BasicStroke(1f)); + g.draw(new Line2D.Double(x1, y1, x2, y2)); + + g.setColor(Color.orange); + g.setStroke(new BasicStroke(1f)); + g.draw(new Line2D.Double(x1, y3, x2, y4)); + + g.setColor(Color.blue); + g.setStroke(new BasicStroke(2f)); + g.draw(new Line2D.Double(x1, y13, x2, y14)); + + g.setColor(Color.red); + g.setStroke(new BasicStroke(2f)); + g.draw(new Line2D.Double(x1, y13c, x2, y14c)); + + g.setColor(Color.black); + g.setStroke(new BasicStroke(1f)); + g.draw(new Line2D.Double(x1, y11, x2, y12)); + + g.setColor(Color.red); + g.setStroke(new BasicStroke(1f)); + g.draw(new Line2D.Double(x1, yA, x2, yA)); + + for (double d : Event.RECALCULATE_P_WAVE_THRESHOLDS) { + double _y = getHeight() * HEIGHT_2 + (getHeight() * (1 - HEIGHT_2)) * (maxRatio - d) / (maxRatio); + if (_y > getHeight() * HEIGHT_2) { + g.setColor(Color.magenta); + g.setStroke(new BasicStroke(1f)); + g.draw(new Line2D.Double(x1, _y, x2, _y)); + } + } + + } + } + + for (Event e : station.getAnalysis().getDetectedEvents()) { + if (!e.isValid()) { + continue; + } + double x = getX(e.getpWave()); + g.setColor(e.isSWave() ? Color.red : Color.blue); + g.setStroke(new BasicStroke(2f)); + g.draw(new Line2D.Double(x, 0, x, getHeight())); + } + + if (GlobalQuake.instance != null) { + for (Earthquake earthquake : GlobalQuake.instance.getEarthquakeAnalysis().getEarthquakes()) { + double distGC = GeoUtils.greatCircleDistance(station.getLatitude(), station.getLongitude(), earthquake.getLat(), earthquake.getLon()); + // todo handle no arrival, but anyway this entire thing will get reworked. + long arrivalP = (long) (earthquake.getOrigin() + 1000 * (TauPTravelTimeCalculator.getPWaveTravelTime(earthquake.getDepth(), + TauPTravelTimeCalculator.toAngle(distGC)) + EarthquakeAnalysis.getElevationCorrection(station.getAlt()))); + + long arrivalS = (long) (earthquake.getOrigin() + 1000 * (TauPTravelTimeCalculator.getSWaveTravelTime(earthquake.getDepth(), + TauPTravelTimeCalculator.toAngle(distGC)) + EarthquakeAnalysis.getElevationCorrection(station.getAlt()))); + + double xP = getX(arrivalP); + double xS = getX(arrivalS); + + g.setColor(Color.magenta); + g.setStroke(dashed); + g.draw(new Line2D.Double(xP, 0, xP, getHeight())); + g.draw(new Line2D.Double(xS, 0, xS, getHeight())); + + double x1 = getX((long) (arrivalP - Settings.pWaveInaccuracyThreshold)); + double x2 = getX((long) (arrivalP + Settings.pWaveInaccuracyThreshold)); + double x3 = getX((long) (arrivalS - Settings.pWaveInaccuracyThreshold)); + double x4 = getX((long) (arrivalS + Settings.pWaveInaccuracyThreshold)); + + g.setColor(new Color(0, 0, 255, 80)); + g.fill(new Rectangle2D.Double(x1, 0, x2 - x1, h)); + + g.setColor(new Color(255, 0, 0, 80)); + g.fill(new Rectangle2D.Double(x3, 0, x4 - x3, h)); + } + } + + g.setColor(Color.black); + g.setStroke(new BasicStroke(2f)); + g.draw(new Rectangle2D.Double(0, 0, w - 1, h - 1)); + g.draw(new Rectangle2D.Double(0, 0, w - 1, (h - 1) * HEIGHT_1)); + g.draw(new Rectangle2D.Double(0, h * HEIGHT_1, w - 1, (h - 1) * HEIGHT_1)); + g.draw(new Rectangle2D.Double(0, h * HEIGHT_2, w - 1, (h - 1) * (1 - HEIGHT_2))); + + g.dispose(); + + this.image = img; + } + + private java.util.List getLogs() { + java.util.List logs = new ArrayList<>(); + + WaveformBuffer waveformBuffer = station.getAnalysis().getWaveformBuffer(); + + if (waveformBuffer != null) { + try { + waveformBuffer.getReadLock().lock(); + if (!station.getAnalysis().getWaveformBuffer().isEmpty()) { + int index = station.getAnalysis().getWaveformBuffer().getOldestDataSlot(); + while (index != station.getAnalysis().getWaveformBuffer().getNewestDataSlot()) { + logs.add(station.getAnalysis().getWaveformBuffer().toLog(index)); + index = (index + 1) % station.getAnalysis().getWaveformBuffer().getSize(); + } + } + } finally { + waveformBuffer.getReadLock().unlock(); + } + } + return logs; + } + + private long getTime() { + return GlobalQuake.instance != null ? GlobalQuake.instance.currentTimeMillis() : System.currentTimeMillis(); + } + + private double getX(long time) { + return getWidth() * (1 - (getTime() - time) / (Settings.logsStoreTimeMinutes * 60 * 1000.0)); + } + + @Override + public void paint(Graphics gr) { + super.paint(gr); + Graphics2D g = (Graphics2D) gr; + g.drawImage(image, 0, 0, null); + } + + public void setStation(AbstractStation station) { + this.station = station; + } } diff --git a/GlobalQuakeClient/src/main/java/globalquake/ui/archived/ArchivedQuakeAnimation.java b/GlobalQuakeClient/src/main/java/globalquake/ui/archived/ArchivedQuakeAnimation.java index e59e4cf99..d08045c94 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/ui/archived/ArchivedQuakeAnimation.java +++ b/GlobalQuakeClient/src/main/java/globalquake/ui/archived/ArchivedQuakeAnimation.java @@ -56,16 +56,16 @@ public void windowClosed(WindowEvent e) { addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { - if(e.getKeyCode() == KeyEvent.VK_RIGHT){ + if (e.getKeyCode() == KeyEvent.VK_RIGHT) { animationStart -= 5000; } - if(e.getKeyCode() == KeyEvent.VK_LEFT){ + if (e.getKeyCode() == KeyEvent.VK_LEFT) { animationStart += 5000; } - if(e.getKeyCode() == KeyEvent.VK_DOWN){ + if (e.getKeyCode() == KeyEvent.VK_DOWN) { animationStart = System.currentTimeMillis() + 5000; } - if(e.getKeyCode() == KeyEvent.VK_ESCAPE){ + if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { dispose(); } } diff --git a/GlobalQuakeClient/src/main/java/globalquake/ui/archived/ArchivedQuakePanel.java b/GlobalQuakeClient/src/main/java/globalquake/ui/archived/ArchivedQuakePanel.java index a25c512e6..75e2e58ae 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/ui/archived/ArchivedQuakePanel.java +++ b/GlobalQuakeClient/src/main/java/globalquake/ui/archived/ArchivedQuakePanel.java @@ -29,14 +29,14 @@ public ArchivedQuakePanel(ArchivedQuakeAnimation animation, ArchivedQuake quake) this.animation = animation; this.quake = quake; - setPreferredSize(new Dimension(600,480)); + setPreferredSize(new Dimension(600, 480)); setCinemaMode(true); getRenderer().addFeature(new FeatureGlobalStation(createFakeStations())); getRenderer().addFeature(new FeatureEarthquake(createFakeQuake(quake))); } - static class AnimatedStation extends AbstractStation{ + static class AnimatedStation extends AbstractStation { private final ArchivedQuakeAnimation animation; private final ArchivedEvent event; @@ -97,7 +97,7 @@ public long getOrigin() { private List createFakeStations() { List result = new ArrayList<>(); - for(ArchivedEvent event : quake.getArchivedEvents()){ + for (ArchivedEvent event : quake.getArchivedEvents()) { result.add(new AnimatedStation(animation, event)); } @@ -105,7 +105,7 @@ private List createFakeStations() { } private List createFakeQuake(ArchivedQuake quake) { - Earthquake fake = new AnimatedEarthquake(animation,quake.getLat(),quake.getLon(),quake.getDepth()); + Earthquake fake = new AnimatedEarthquake(animation, quake.getLat(), quake.getLon(), quake.getDepth()); fake.getHypocenter().magnitude = quake.getMag(); return List.of(fake); } @@ -115,16 +115,16 @@ private List createFakeQuake(ArchivedQuake quake) { public void paint(Graphics gr) { super.paint(gr); - Graphics2D g =(Graphics2D) gr; + Graphics2D g = (Graphics2D) gr; g.setColor(Color.white); g.setFont(new Font("Calibri", Font.BOLD, 14)); int y = 0; - g.drawString("M%.1f %s".formatted(quake.getMag(), quake.getRegion()), 5, y+=15); - g.drawString("%s".formatted(Settings.formatDateTime(Instant.ofEpochMilli(quake.getOrigin()))), 5, y+=15); - g.drawString("%.4f %.4f".formatted(quake.getLat(), quake.getLon()), 5, y+=15); - g.drawString("Depth: %s".formatted(Settings.getSelectedDistanceUnit().format(quake.getDepth(), 1)), 5, y+=15); - g.drawString("%d Stations".formatted(quake.getAssignedStations()), 5, y+=15); + g.drawString("M%.1f %s".formatted(quake.getMag(), quake.getRegion()), 5, y += 15); + g.drawString("%s".formatted(Settings.formatDateTime(Instant.ofEpochMilli(quake.getOrigin()))), 5, y += 15); + g.drawString("%.4f %.4f".formatted(quake.getLat(), quake.getLon()), 5, y += 15); + g.drawString("Depth: %s".formatted(Settings.getSelectedDistanceUnit().format(quake.getDepth(), 1)), 5, y += 15); + g.drawString("%d Stations".formatted(quake.getAssignedStations()), 5, y += 15); g.setFont(new Font("Calibri", Font.BOLD, 18)); g.setColor(Color.orange); diff --git a/GlobalQuakeClient/src/main/java/globalquake/ui/archived/ArchivedQuakeUI.java b/GlobalQuakeClient/src/main/java/globalquake/ui/archived/ArchivedQuakeUI.java index 876a250d7..4f49fcaa6 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/ui/archived/ArchivedQuakeUI.java +++ b/GlobalQuakeClient/src/main/java/globalquake/ui/archived/ArchivedQuakeUI.java @@ -26,7 +26,7 @@ public ArchivedQuakeUI(Frame parent, ArchivedQuake quake) { // Create a panel to hold the labels JPanel panel = new JPanel(); - panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); + panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.add(latLabel); panel.add(lonLabel); @@ -49,19 +49,19 @@ public void actionPerformed(ActionEvent actionEvent) { getContentPane().add(panel, BorderLayout.CENTER); JPanel panel2 = new JPanel(); - panel2.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); + panel2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); panel2.add(animButton); getContentPane().add(panel2, BorderLayout.SOUTH); - for(Component component: panel.getComponents()){ + for (Component component : panel.getComponents()) { component.setFont(new Font("Calibri", Font.PLAIN, 18)); } addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { - if(e.getKeyCode() == KeyEvent.VK_ESCAPE){ + if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { dispose(); } } diff --git a/GlobalQuakeClient/src/main/java/globalquake/ui/client/MainFrame.java b/GlobalQuakeClient/src/main/java/globalquake/ui/client/MainFrame.java index b0f8c03e6..c02016495 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/ui/client/MainFrame.java +++ b/GlobalQuakeClient/src/main/java/globalquake/ui/client/MainFrame.java @@ -199,10 +199,10 @@ private static void finishInit() { if (Settings.recalibrateOnLaunch) { EarthquakeAnalysisTraining.calibrateResolution(MainFrame::updateProgressBar, null, true); - if(GQHypocs.isCudaLoaded()){ + if (GQHypocs.isCudaLoaded()) { EarthquakeAnalysisTraining.calibrateResolution(MainFrame::updateProgressBar, null, false); } - } else if (GQHypocs.isCudaLoaded()) { + } else if (GQHypocs.isCudaLoaded()) { GQHypocs.calculateStationLimit(); } diff --git a/GlobalQuakeClient/src/main/java/globalquake/ui/client/ServerSelectionFrame.java b/GlobalQuakeClient/src/main/java/globalquake/ui/client/ServerSelectionFrame.java index f7092d865..48142d24b 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/ui/client/ServerSelectionFrame.java +++ b/GlobalQuakeClient/src/main/java/globalquake/ui/client/ServerSelectionFrame.java @@ -35,7 +35,7 @@ public ServerSelectionFrame() { client = new ClientSocket(); setTitle(Main.fullName); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setPreferredSize(new Dimension(400,160)); + setPreferredSize(new Dimension(400, 160)); add(createServerSelectionPanel()); @@ -50,7 +50,7 @@ private JPanel createServerSelectionPanel() { JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); - var grid= new GridLayout(2,1); + var grid = new GridLayout(2, 1); grid.setVgap(5); JPanel addressPanel = new JPanel(grid); addressPanel.setBorder(BorderFactory.createTitledBorder("Server address")); @@ -58,25 +58,25 @@ private JPanel createServerSelectionPanel() { JPanel ipPanel = new JPanel(); ipPanel.setLayout(new BoxLayout(ipPanel, BoxLayout.X_AXIS)); ipPanel.add(new JLabel("IP Address: ")); - ipPanel.add(addressField = new JTextField(Settings.lastServerIP,20)); + ipPanel.add(addressField = new JTextField(Settings.lastServerIP, 20)); addressPanel.add(ipPanel); JPanel portPanel = new JPanel(); portPanel.setLayout(new BoxLayout(portPanel, BoxLayout.X_AXIS)); portPanel.add(new JLabel("Port: ")); - portPanel.add(portField = new JTextField(String.valueOf(Settings.lastServerPORT),20)); + portPanel.add(portField = new JTextField(String.valueOf(Settings.lastServerPORT), 20)); addressPanel.add(portPanel); panel.add(addressPanel); - var gridl2 = new GridLayout(1,2); + var gridl2 = new GridLayout(1, 2); gridl2.setVgap(5); gridl2.setHgap(5); JPanel buttonsPanel = new JPanel(gridl2); - buttonsPanel.setBorder(new EmptyBorder(5,5,5,5)); + buttonsPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); connectButton = new JButton("Connect"); ActionListener connectEvent = actionEvent1 -> connect(); @@ -154,12 +154,12 @@ public void windowClosed(WindowEvent e) { }); } - public static void main(String[] args) throws Exception{ + public static void main(String[] args) throws Exception { init(); new ServerSelectionFrame(); } - private static void init() throws Exception{ + private static void init() throws Exception { Regions.init(); Scale.load(); ShakeMap.init(); diff --git a/GlobalQuakeClient/src/main/java/globalquake/ui/database/DatabaseMonitorFrame.java b/GlobalQuakeClient/src/main/java/globalquake/ui/database/DatabaseMonitorFrame.java index 8c944816e..42688a41f 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/ui/database/DatabaseMonitorFrame.java +++ b/GlobalQuakeClient/src/main/java/globalquake/ui/database/DatabaseMonitorFrame.java @@ -97,7 +97,7 @@ private void updateFrame() { private Component createTabbedPane() { JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.addTab("Seedlink Networks", new SeedlinkServersPanel( - this, manager,restoreDatabaseAction, getBtnSelectStations(), getBtnLaunch())); + this, manager, restoreDatabaseAction, getBtnSelectStations(), getBtnLaunch())); tabbedPane.addTab("Station Sources", new StationSourcesPanel( this, manager, restoreDatabaseAction, getBtnSelectStations(), getBtnLaunch())); return tabbedPane; @@ -151,14 +151,14 @@ public void actionPerformed(ActionEvent actionEvent) { bottomPanel.add(new StationCountPanel(manager, new GridLayout(2, 2))); - mainProgressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, 100); + mainProgressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, 100); mainProgressBar.setValue(0); mainProgressBar.setStringPainted(true); mainProgressBar.setString("Init..."); buttonsOutsidePanel.add(buttonsPanel); buttonsOutsidePanel.add(mainProgressBar); - + bottomPanel.add(buttonsOutsidePanel); return bottomPanel; } @@ -172,7 +172,7 @@ public void initDone() { } public JButton getBtnSelectStations() { - return btnSelectStations; + return btnSelectStations; } public JButton getBtnLaunch() { diff --git a/GlobalQuakeClient/src/main/java/globalquake/ui/debug/FeatureDebugStation.java b/GlobalQuakeClient/src/main/java/globalquake/ui/debug/FeatureDebugStation.java index 43c82993d..ab7f27e58 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/ui/debug/FeatureDebugStation.java +++ b/GlobalQuakeClient/src/main/java/globalquake/ui/debug/FeatureDebugStation.java @@ -16,7 +16,7 @@ public class FeatureDebugStation extends RenderFeature { private final MonitorableCopyOnWriteArrayList list; - public FeatureDebugStation(MonitorableCopyOnWriteArrayList list){ + public FeatureDebugStation(MonitorableCopyOnWriteArrayList list) { super(1); this.list = list; } @@ -28,8 +28,8 @@ public Collection getElements() { @Override public void createPolygon(GlobeRenderer renderer, RenderEntity entity, RenderProperties renderProperties) { - RenderElement element=entity.getRenderElement(0); - if(element.getPolygon() == null){ + RenderElement element = entity.getRenderElement(0); + if (element.getPolygon() == null) { element.setPolygon(new Polygon3D()); } @@ -46,20 +46,20 @@ public boolean needsCreatePolygon(RenderEntity entity, boolean pro @Override public void project(GlobeRenderer renderer, RenderEntity entity, RenderProperties renderProperties) { - RenderElement element=entity.getRenderElement(0); + RenderElement element = entity.getRenderElement(0); element.getShape().reset(); - element.shouldDraw = renderer.project3D(element.getShape(), element.getPolygon(), true, renderProperties); + element.shouldDraw = renderer.project3D(element.getShape(), element.getPolygon(), true, renderProperties); } @Override public void render(GlobeRenderer renderer, Graphics2D graphics, RenderEntity entity, RenderProperties renderProperties) { - RenderElement element=entity.getRenderElement(0); - if(!element.shouldDraw){ + RenderElement element = entity.getRenderElement(0); + if (!element.shouldDraw) { return; } graphics.setColor(Color.BLUE); graphics.fill(element.getShape()); - if(renderer.isMouseNearby(entity.getOriginal().coords(), 10.0, true, renderProperties) && renderProperties.scroll < 1){ + if (renderer.isMouseNearby(entity.getOriginal().coords(), 10.0, true, renderProperties) && renderProperties.scroll < 1) { graphics.setColor(Color.yellow); graphics.draw(element.getShape()); } @@ -68,6 +68,6 @@ public void render(GlobeRenderer renderer, Graphics2D graphics, RenderEntity entity) { - return ((RenderEntity)entity).getOriginal().coords(); + return ((RenderEntity) entity).getOriginal().coords(); } } diff --git a/GlobalQuakeClient/src/main/java/globalquake/ui/debug/GlobePanelDebug.java b/GlobalQuakeClient/src/main/java/globalquake/ui/debug/GlobePanelDebug.java index 6b14a85de..016d135f3 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/ui/debug/GlobePanelDebug.java +++ b/GlobalQuakeClient/src/main/java/globalquake/ui/debug/GlobePanelDebug.java @@ -30,177 +30,177 @@ public class GlobePanelDebug extends GQFrame { - private final GlobePanel panel; - private final JPanel list; - private final JPanel mainPanel; - private List archivedQuakes; - protected boolean hideList; - private boolean _containsListToggle; - private boolean _containsSettings; - - public GlobePanelDebug() { - createArchived(); - - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setPreferredSize(new Dimension(800, 600)); - - panel = new GlobePanel(50,17) { - - @Override - public void paint(Graphics gr) { - super.paint(gr); - Graphics2D g = (Graphics2D) gr; - - g.setColor(_containsListToggle ? Color.gray : Color.lightGray); - g.fillRect(getWidth() - 20, 0, 20, 30); - g.setColor(Color.black); - g.drawRect(getWidth() - 20, 0, 20, 30); - g.setFont(new Font("Calibri", Font.BOLD, 16)); - g.setColor(Color.black); - g.drawString(hideList ? "<" : ">", getWidth() - 16, 20); - - g.setColor(_containsSettings ? Color.gray : Color.lightGray); - g.fillRect(getWidth() - 20, getHeight() - 30, 20, 30); - g.setColor(Color.black); - g.drawRect(getWidth() - 20, getHeight() - 30, 20, 30); - g.setFont(new Font("Calibri", Font.BOLD, 16)); - g.setColor(Color.black); - g.drawString("S", getWidth() - 15, getHeight() - 8); - - String region = Regions.getRegion(getRenderer().getRenderProperties().centerLat, getRenderer().getRenderProperties().centerLon); - g.setColor(Color.white); - g.drawString(region, getWidth() / 2 - g.getFontMetrics().stringWidth(region), getHeight() - 16); - - double x = getWidth() / 2.0; - double y = getHeight() / 2.0; - double r = 10.0; - g.draw(new Ellipse2D.Double(x - r/2, y - r/2, r, r)); - } - }; - - addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - if(e.getKeyCode() == KeyEvent.VK_SPACE){ - panel.smoothTransition(0,0,0.5); - } - if(e.getKeyCode() == KeyEvent.VK_C){ - panel.setCinemaMode(!panel.isCinemaMode()); - } - } - }); - - MonitorableCopyOnWriteArrayList debugStations = new MonitorableCopyOnWriteArrayList<>(); - - double centerLat = 50; - double centerLon = 17; - - double maxDist = 10000; - int total = 400; - - - double phi = 1.61803398875; - double c = maxDist / Math.sqrt(total); - - for(int n = 0; n < total; n++){ - double ang = 360.0 / (phi * phi) * n; - double radius = Math.sqrt(n) * c; - double[] latlon = GeoUtils.moveOnGlobe(centerLat, centerLon, radius, ang); - debugStations.add(new DebugStation(new Point2D(latlon[0], latlon[1]))); - } - - System.out.println(debugStations.size()); - panel.getRenderer().addFeature(new FeatureDebugStation(debugStations)); - panel.getRenderer().addFeature(new FeatureCities()); - - panel.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - int x = e.getX(); - int y = e.getY(); - if (x >= panel.getWidth() - 20 && x <= panel.getWidth() && y >= 0 && y <= 30) { - toggleList(); - } - } - - @Override - public void mouseExited(MouseEvent e) { - _containsListToggle = false; - _containsSettings = false; - } - }); - panel.addMouseMotionListener(new MouseAdapter() { - - @Override - public void mouseMoved(MouseEvent e) { - int x = e.getX(); - int y = e.getY(); - _containsListToggle = x >= panel.getWidth() - 20 && x <= panel.getWidth() && y >= 0 && y <= 30; - _containsSettings = x >= panel.getWidth() - 20 && x <= panel.getWidth() && y >= panel.getHeight() - 30 && y <= panel.getHeight(); - } - - }); - - list = new EarthquakeListPanel(this, archivedQuakes); - panel.setPreferredSize(new Dimension(600, 600)); - list.setPreferredSize(new Dimension(300, 600)); - - mainPanel = new JPanel(); - mainPanel.setLayout(new BorderLayout()); - mainPanel.setPreferredSize(new Dimension(800, 600)); - mainPanel.add(panel, BorderLayout.CENTER); - mainPanel.add(list, BorderLayout.EAST); - - setContentPane(mainPanel); - - pack(); - setLocationRelativeTo(null); - setResizable(true); - setTitle("Globe Panel"); - - Timer timer = new Timer(); - timer.scheduleAtFixedRate(new TimerTask() { - public void run() { - mainPanel.repaint(); - } - }, 0, 1000 / 40); - } - - private void createArchived() { - archivedQuakes = new ArrayList<>(); - Random r = new Random(); - Settings.oldEventsTimeFilterEnabled = false; - Settings.oldEventsMagnitudeFilterEnabled = false; - for(double mag = 0.5; mag <= 11; mag += 0.2) { - archivedQuakes.add(new ArchivedQuake(null, 0, 0, 0, mag, r.nextLong() % System.currentTimeMillis(), QualityClass.S, System.currentTimeMillis()+100)); //100ms added to make finalUpdateMillis > origin - } - //archivedQuakes.sort(Comparator.comparing(ArchivedQuake::getOrigin)); - } - - protected void toggleList() { - hideList = !hideList; - if (hideList) { - panel.setSize(new Dimension(mainPanel.getWidth(), mainPanel.getHeight())); - list.setPreferredSize(new Dimension(0, (int) list.getPreferredSize().getHeight())); - } else { - panel.setSize(new Dimension(mainPanel.getWidth() - 300, mainPanel.getHeight())); - list.setPreferredSize(new Dimension(300, (int) list.getPreferredSize().getHeight())); - } - _containsListToggle = false; - _containsSettings = false; - revalidate(); - } - - public static void main(String[] args) { - try { - TauPTravelTimeCalculator.init(); - Regions.init(); - Scale.load(); - Sounds.load(); - GlobalQuake.prepare(Main.MAIN_FOLDER, null); - } catch (Exception e) { - return; - } - EventQueue.invokeLater(() -> new GlobePanelDebug().setVisible(true)); - } + private final GlobePanel panel; + private final JPanel list; + private final JPanel mainPanel; + private List archivedQuakes; + protected boolean hideList; + private boolean _containsListToggle; + private boolean _containsSettings; + + public GlobePanelDebug() { + createArchived(); + + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setPreferredSize(new Dimension(800, 600)); + + panel = new GlobePanel(50, 17) { + + @Override + public void paint(Graphics gr) { + super.paint(gr); + Graphics2D g = (Graphics2D) gr; + + g.setColor(_containsListToggle ? Color.gray : Color.lightGray); + g.fillRect(getWidth() - 20, 0, 20, 30); + g.setColor(Color.black); + g.drawRect(getWidth() - 20, 0, 20, 30); + g.setFont(new Font("Calibri", Font.BOLD, 16)); + g.setColor(Color.black); + g.drawString(hideList ? "<" : ">", getWidth() - 16, 20); + + g.setColor(_containsSettings ? Color.gray : Color.lightGray); + g.fillRect(getWidth() - 20, getHeight() - 30, 20, 30); + g.setColor(Color.black); + g.drawRect(getWidth() - 20, getHeight() - 30, 20, 30); + g.setFont(new Font("Calibri", Font.BOLD, 16)); + g.setColor(Color.black); + g.drawString("S", getWidth() - 15, getHeight() - 8); + + String region = Regions.getRegion(getRenderer().getRenderProperties().centerLat, getRenderer().getRenderProperties().centerLon); + g.setColor(Color.white); + g.drawString(region, getWidth() / 2 - g.getFontMetrics().stringWidth(region), getHeight() - 16); + + double x = getWidth() / 2.0; + double y = getHeight() / 2.0; + double r = 10.0; + g.draw(new Ellipse2D.Double(x - r / 2, y - r / 2, r, r)); + } + }; + + addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_SPACE) { + panel.smoothTransition(0, 0, 0.5); + } + if (e.getKeyCode() == KeyEvent.VK_C) { + panel.setCinemaMode(!panel.isCinemaMode()); + } + } + }); + + MonitorableCopyOnWriteArrayList debugStations = new MonitorableCopyOnWriteArrayList<>(); + + double centerLat = 50; + double centerLon = 17; + + double maxDist = 10000; + int total = 400; + + + double phi = 1.61803398875; + double c = maxDist / Math.sqrt(total); + + for (int n = 0; n < total; n++) { + double ang = 360.0 / (phi * phi) * n; + double radius = Math.sqrt(n) * c; + double[] latlon = GeoUtils.moveOnGlobe(centerLat, centerLon, radius, ang); + debugStations.add(new DebugStation(new Point2D(latlon[0], latlon[1]))); + } + + System.out.println(debugStations.size()); + panel.getRenderer().addFeature(new FeatureDebugStation(debugStations)); + panel.getRenderer().addFeature(new FeatureCities()); + + panel.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + int x = e.getX(); + int y = e.getY(); + if (x >= panel.getWidth() - 20 && x <= panel.getWidth() && y >= 0 && y <= 30) { + toggleList(); + } + } + + @Override + public void mouseExited(MouseEvent e) { + _containsListToggle = false; + _containsSettings = false; + } + }); + panel.addMouseMotionListener(new MouseAdapter() { + + @Override + public void mouseMoved(MouseEvent e) { + int x = e.getX(); + int y = e.getY(); + _containsListToggle = x >= panel.getWidth() - 20 && x <= panel.getWidth() && y >= 0 && y <= 30; + _containsSettings = x >= panel.getWidth() - 20 && x <= panel.getWidth() && y >= panel.getHeight() - 30 && y <= panel.getHeight(); + } + + }); + + list = new EarthquakeListPanel(this, archivedQuakes); + panel.setPreferredSize(new Dimension(600, 600)); + list.setPreferredSize(new Dimension(300, 600)); + + mainPanel = new JPanel(); + mainPanel.setLayout(new BorderLayout()); + mainPanel.setPreferredSize(new Dimension(800, 600)); + mainPanel.add(panel, BorderLayout.CENTER); + mainPanel.add(list, BorderLayout.EAST); + + setContentPane(mainPanel); + + pack(); + setLocationRelativeTo(null); + setResizable(true); + setTitle("Globe Panel"); + + Timer timer = new Timer(); + timer.scheduleAtFixedRate(new TimerTask() { + public void run() { + mainPanel.repaint(); + } + }, 0, 1000 / 40); + } + + private void createArchived() { + archivedQuakes = new ArrayList<>(); + Random r = new Random(); + Settings.oldEventsTimeFilterEnabled = false; + Settings.oldEventsMagnitudeFilterEnabled = false; + for (double mag = 0.5; mag <= 11; mag += 0.2) { + archivedQuakes.add(new ArchivedQuake(null, 0, 0, 0, mag, r.nextLong() % System.currentTimeMillis(), QualityClass.S, System.currentTimeMillis() + 100)); //100ms added to make finalUpdateMillis > origin + } + //archivedQuakes.sort(Comparator.comparing(ArchivedQuake::getOrigin)); + } + + protected void toggleList() { + hideList = !hideList; + if (hideList) { + panel.setSize(new Dimension(mainPanel.getWidth(), mainPanel.getHeight())); + list.setPreferredSize(new Dimension(0, (int) list.getPreferredSize().getHeight())); + } else { + panel.setSize(new Dimension(mainPanel.getWidth() - 300, mainPanel.getHeight())); + list.setPreferredSize(new Dimension(300, (int) list.getPreferredSize().getHeight())); + } + _containsListToggle = false; + _containsSettings = false; + revalidate(); + } + + public static void main(String[] args) { + try { + TauPTravelTimeCalculator.init(); + Regions.init(); + Scale.load(); + Sounds.load(); + GlobalQuake.prepare(Main.MAIN_FOLDER, null); + } catch (Exception e) { + return; + } + EventQueue.invokeLater(() -> new GlobePanelDebug().setVisible(true)); + } } diff --git a/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/CinemaHandler.java b/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/CinemaHandler.java index 64b585bc5..c1a1bdbaa 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/CinemaHandler.java +++ b/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/CinemaHandler.java @@ -62,11 +62,11 @@ public void run() { cinemaTargetService.schedule(task, 0, TimeUnit.SECONDS); - GlobalQuake.instance.getEventHandler().registerEventListener(new GlobalQuakeEventListener(){ + GlobalQuake.instance.getEventHandler().registerEventListener(new GlobalQuakeEventListener() { @Override public void onQuakeCreate(QuakeCreateEvent event) { CinemaTarget target = createTarget(event.earthquake()); - if(lastTarget == null || target.priority() > lastTarget.priority()){ + if (lastTarget == null || target.priority() > lastTarget.priority()) { selectTarget(target, true); } } @@ -74,7 +74,7 @@ public void onQuakeCreate(QuakeCreateEvent event) { @Override public void onClusterCreate(ClusterCreateEvent event) { CinemaTarget target = createTarget(event.cluster()); - if(lastTarget == null || target.priority() > lastTarget.priority()){ + if (lastTarget == null || target.priority() > lastTarget.priority()) { selectTarget(target, true); } } @@ -82,8 +82,8 @@ public void onClusterCreate(ClusterCreateEvent event) { @Override public void onQuakeRemove(QuakeRemoveEvent event) { warnings.remove(event.earthquake()); - if(lastTarget != null && lastTarget.original() instanceof Earthquake earthquake){ - if(event.earthquake().getUuid().equals(earthquake.getUuid())){ + if (lastTarget != null && lastTarget.original() instanceof Earthquake earthquake) { + if (event.earthquake().getUuid().equals(earthquake.getUuid())) { lastTarget = null; } } @@ -91,9 +91,9 @@ public void onQuakeRemove(QuakeRemoveEvent event) { @Override public void onQuakeArchive(QuakeArchiveEvent event) { - if(event.earthquake() != null) { + if (event.earthquake() != null) { warnings.remove(event.earthquake()); - if(lastTarget != null && lastTarget.original() instanceof Earthquake earthquake) { + if (lastTarget != null && lastTarget.original() instanceof Earthquake earthquake) { if (event.earthquake().getUuid().equals(earthquake.getUuid())) { lastTarget = null; } @@ -102,7 +102,7 @@ public void onQuakeArchive(QuakeArchiveEvent event) { } }); - GlobalQuakeLocal.instance.getLocalEventHandler().registerEventListener(new GlobalQuakeLocalEventListener(){ + GlobalQuakeLocal.instance.getLocalEventHandler().registerEventListener(new GlobalQuakeLocalEventListener() { @Override public void onWarningIssued(AlertIssuedEvent event) { warnings.putIfAbsent(event.warnable(), event.warning()); @@ -133,7 +133,7 @@ public void onWarningIssued(AlertIssuedEvent event) { }); } - public void stop(){ + public void stop() { GlobalQuake.instance.stopService(cinemaTargetService); } @@ -152,7 +152,7 @@ private synchronized void selectTarget(CinemaTarget target, boolean bypass) { return; } - if(isWarningInProgress() && !isWarned(target.original())){ + if (isWarningInProgress() && !isWarned(target.original())) { return; } @@ -167,8 +167,8 @@ private boolean isWarned(Warnable original) { } private boolean isWarningInProgress() { - for(Warning warning : warnings.values()){ - if(GlobalQuake.instance.currentTimeMillis() - warning.createdAt < WARNING_VALID){ + for (Warning warning : warnings.values()) { + if (GlobalQuake.instance.currentTimeMillis() - warning.createdAt < WARNING_VALID) { return true; } } @@ -215,7 +215,7 @@ private CinemaTarget selectNextTarget() { var cluster = GlobalQuake.instance.getClusterAnalysis().getClusters().stream().findFirst(); if (cluster.isPresent()) { Cluster cluster1 = cluster.get(); - if (! (GlobalQuake.instance.currentTimeMillis()- cluster1.getLastUpdate() > 1000 * 60 || cluster1.getRootLon() < -500 || cluster1.getRootLat() < -500)) { + if (!(GlobalQuake.instance.currentTimeMillis() - cluster1.getLastUpdate() > 1000 * 60 || cluster1.getRootLon() < -500 || cluster1.getRootLat() < -500)) { lastCluster = cluster1; return createTarget(cluster1); } @@ -232,12 +232,12 @@ private CinemaTarget createTarget(Cluster cluster) { private CinemaTarget createTarget(Earthquake earthquake) { double ageMin = (GlobalQuake.instance.currentTimeMillis() - earthquake.getOrigin()) / (1000 * 60.0); double zoom = Math.max(0.1, Math.min(1.6, ageMin / 5.0)) / (Settings.cinemaModeZoomMultiplier / 100.0); - if(ageMin >= 3.0 && (GlobalQuake.instance.currentTimeMillis() % 60000 < 22000)){ + if (ageMin >= 3.0 && (GlobalQuake.instance.currentTimeMillis() % 60000 < 22000)) { zoom = Math.max(0.02, earthquake.getMag() / 50.0); } double priority = 100 + Math.max(0, earthquake.getMag() * 100.0); - if(AlertManager.meetsConditions(earthquake, true)){ + if (AlertManager.meetsConditions(earthquake, true)) { priority += 10000.0; } diff --git a/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/EarthquakeListPanel.java b/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/EarthquakeListPanel.java index c4548201f..4c326d607 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/EarthquakeListPanel.java +++ b/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/EarthquakeListPanel.java @@ -33,8 +33,8 @@ public class EarthquakeListPanel extends JPanel { private final List archivedQuakes; private boolean isMouseInGoUpRect; - private List getFiltered(){ - if(archivedQuakes == null){ + private List getFiltered() { + if (archivedQuakes == null) { return null; } return archivedQuakes.stream().filter(ArchivedQuake::shouldBeDisplayed).collect(Collectors.toList()); @@ -49,7 +49,7 @@ public EarthquakeListPanel(Frame parent, List archivedQuakes) { addMouseWheelListener(e -> { List filtered = getFiltered(); - if(filtered == null){ + if (filtered == null) { return; } boolean down = e.getWheelRotation() < 0; @@ -71,7 +71,7 @@ public void mousePressed(MouseEvent e) { int y = e.getY(); int i = (int) ((y + scroll) / cell_height); List filtered = getFiltered(); - if (filtered == null || i < 0 || i >=filtered.size()) { + if (filtered == null || i < 0 || i >= filtered.size()) { return; } @@ -81,15 +81,15 @@ public void mousePressed(MouseEvent e) { quake.setWrong(!quake.isWrong()); } - if(e.getButton() == MouseEvent.BUTTON1) { - if(isMouseInGoUpRect) { + if (e.getButton() == MouseEvent.BUTTON1) { + if (isMouseInGoUpRect) { scroll = 0; - }else if (quake != null ) { + } else if (quake != null) { new ArchivedQuakeUI(parent, quake).setVisible(true); } } - if(e.getButton() == MouseEvent.BUTTON2 && !isMouseInGoUpRect && quake != null) { + if (e.getButton() == MouseEvent.BUTTON2 && !isMouseInGoUpRect && quake != null) { new ArchivedQuakeAnimation(parent, quake).setVisible(true); } } @@ -113,7 +113,7 @@ public void mouseMoved(MouseEvent e) { public void paint(Graphics gr) { super.paint(gr); - if(getWidth() <= 60){ + if (getWidth() <= 60) { return; } @@ -121,13 +121,13 @@ public void paint(Graphics gr) { Graphics2D g = (Graphics2D) gr; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); int i = 0; - if(getFiltered() != null) { + if (getFiltered() != null) { for (ArchivedQuake quake : getFiltered()) { int y = (int) (i * cell_height - scroll); if (y > getHeight()) { break; } - if(y < -cell_height){ + if (y < -cell_height) { i++; continue; } @@ -153,7 +153,7 @@ public void paint(Graphics gr) { g.setStroke(new BasicStroke(0.5f)); g.draw(rect); - if (!isMouseInGoUpRect && (int)((mouseY + scroll) / cell_height) == i) { + if (!isMouseInGoUpRect && (int) ((mouseY + scroll) / cell_height) == i) { g.setColor(new Color(0, 0, 0, 60)); g.fill(rect); } @@ -214,18 +214,18 @@ public void paint(Graphics gr) { g.setStroke(new BasicStroke(1f)); - if(i == 0){ + if (i == 0) { g.setFont(new Font("Calibri", Font.BOLD, 16)); g.setColor(Color.white); String str = "No earthquakes archived"; g.drawString(str, getWidth() / 2 - g.getFontMetrics().stringWidth(str) / 2, 22); } - if(scroll > 0){ + if (scroll > 0) { g.setColor(Color.gray); g.fill(goUpRectangle); - if(isMouseInGoUpRect){ + if (isMouseInGoUpRect) { g.setStroke(new BasicStroke(2f)); } diff --git a/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/GlobalQuakeFrame.java b/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/GlobalQuakeFrame.java index a9da741c8..848f1b767 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/GlobalQuakeFrame.java +++ b/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/GlobalQuakeFrame.java @@ -16,153 +16,153 @@ public class GlobalQuakeFrame extends GQFrame { - private boolean hideList = false; - private final EarthquakeListPanel list; - protected GlobalQuakePanel panel; - protected JPanel mainPanel; - private boolean _containsListToggle; - - public GlobalQuakeFrame() { - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - panel = new GlobalQuakePanel(this) { - - @Override - public void paint(Graphics gr) { - super.paint(gr); - Graphics2D g = (Graphics2D) gr; - g.setColor(_containsListToggle ? Color.gray : Color.lightGray); - g.fillRect(getWidth() - 20, 0, 20, 30); - g.setColor(Color.black); - g.drawRect(getWidth() - 20, 0, 20, 30); - g.setFont(new Font("Calibri", Font.BOLD, 16)); - g.setColor(Color.black); - g.drawString(hideList ? "<" : ">", getWidth() - 16, 20); - } - }; - panel.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - int x = e.getX(); - int y = e.getY(); - if (x >= panel.getWidth() - 20 && x <= panel.getWidth() && y >= 0 && y <= 30) { - toggleList(); - } - } - - @Override - public void mouseExited(MouseEvent e) { - _containsListToggle = false; - } - }); - panel.addMouseMotionListener(new MouseAdapter() { - - @Override - public void mouseMoved(MouseEvent e) { - int x = e.getX(); - int y = e.getY(); - _containsListToggle = x >= panel.getWidth() - 20 && x <= panel.getWidth() && y >= 0 && y <= 30; - } - }); - - list = new EarthquakeListPanel(this, GlobalQuake.instance.getArchive().getArchivedQuakes()); - panel.setPreferredSize(new Dimension(600, 600)); - list.setPreferredSize(new Dimension(300, 600)); - - mainPanel = new JPanel(); - mainPanel.setLayout(new BorderLayout()); - mainPanel.setPreferredSize(new Dimension(1000, 700)); - mainPanel.add(panel, BorderLayout.CENTER); - mainPanel.add(list, BorderLayout.EAST); - - setContentPane(mainPanel); - - setJMenuBar(createJMenuBar()); - - pack(); - setLocationRelativeTo(null); - setMinimumSize(new Dimension(320, 300)); - setResizable(true); - setTitle(Main.fullName); - - ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); - - // Schedule the task - scheduler.schedule(new Runnable() { - @Override - public void run() { - mainPanel.repaint(); - scheduler.schedule(this, 1000 / Settings.fpsIdle, TimeUnit.MILLISECONDS); - } - }, 1, TimeUnit.SECONDS); - - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - scheduler.shutdown(); - } - - @Override - public void windowClosed(WindowEvent e) { - scheduler.shutdown(); - } - }); - } - - protected JMenuBar createJMenuBar() { - JMenuBar menuBar = new JMenuBar(); - menuBar.setBackground(Color.lightGray); - - JMenu menuOptions = new JMenu("Options"); - - JMenuItem settings = new JMenuItem("Settings"); - settings.addActionListener(new AbstractAction() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - // Check if an instance of SettingsFrame already exists - if (SettingsFrame.getInstance() == null) { - // If not, create a new instance and make it visible - SettingsFrame settingsFrame = new SettingsFrame(GlobalQuakeFrame.this, GlobalQuake.getInstance().limitedSettings()); - settingsFrame.setVisible(true); - // Ensure that the SettingsFrame is always on top - settingsFrame.setAlwaysOnTop(true); - } - } - }); - - menuOptions.add(settings); - - menuBar.add(menuOptions); - - JMenu aboutMenu = new JMenu("Links"); - - aboutMenu.add(new OpenURLAction("https://github.com/xspanger3770/GlobalQuake/", "Open GitHub webpage")); - aboutMenu.add(new OpenURLAction("https://github.com/xspanger3770/GlobalQuake/issues/", "Report issue or request new feature")); - aboutMenu.add(new OpenURLAction("https://github.com/xspanger3770/GlobalQuake/releases/", "Check for latest version")); - aboutMenu.add(new OpenURLAction("https://www.buymeacoffee.com/jakubspangl/", "Donate")); - - menuBar.add(aboutMenu); - - return menuBar; - } - - protected void toggleList() { - hideList = !hideList; - if (hideList) { - panel.setSize(new Dimension(mainPanel.getWidth(), mainPanel.getHeight())); - list.setPreferredSize(new Dimension(0, (int) list.getPreferredSize().getHeight())); - } else { - panel.setSize(new Dimension(mainPanel.getWidth() - 300, mainPanel.getHeight())); - list.setPreferredSize(new Dimension(300, (int) list.getPreferredSize().getHeight())); - } - _containsListToggle = false; - revalidate(); - } - - public GlobalQuakePanel getGQPanel() { - return panel; - } + private boolean hideList = false; + private final EarthquakeListPanel list; + protected GlobalQuakePanel panel; + protected JPanel mainPanel; + private boolean _containsListToggle; + + public GlobalQuakeFrame() { + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + panel = new GlobalQuakePanel(this) { + + @Override + public void paint(Graphics gr) { + super.paint(gr); + Graphics2D g = (Graphics2D) gr; + g.setColor(_containsListToggle ? Color.gray : Color.lightGray); + g.fillRect(getWidth() - 20, 0, 20, 30); + g.setColor(Color.black); + g.drawRect(getWidth() - 20, 0, 20, 30); + g.setFont(new Font("Calibri", Font.BOLD, 16)); + g.setColor(Color.black); + g.drawString(hideList ? "<" : ">", getWidth() - 16, 20); + } + }; + panel.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + int x = e.getX(); + int y = e.getY(); + if (x >= panel.getWidth() - 20 && x <= panel.getWidth() && y >= 0 && y <= 30) { + toggleList(); + } + } + + @Override + public void mouseExited(MouseEvent e) { + _containsListToggle = false; + } + }); + panel.addMouseMotionListener(new MouseAdapter() { + + @Override + public void mouseMoved(MouseEvent e) { + int x = e.getX(); + int y = e.getY(); + _containsListToggle = x >= panel.getWidth() - 20 && x <= panel.getWidth() && y >= 0 && y <= 30; + } + }); + + list = new EarthquakeListPanel(this, GlobalQuake.instance.getArchive().getArchivedQuakes()); + panel.setPreferredSize(new Dimension(600, 600)); + list.setPreferredSize(new Dimension(300, 600)); + + mainPanel = new JPanel(); + mainPanel.setLayout(new BorderLayout()); + mainPanel.setPreferredSize(new Dimension(1000, 700)); + mainPanel.add(panel, BorderLayout.CENTER); + mainPanel.add(list, BorderLayout.EAST); + + setContentPane(mainPanel); + + setJMenuBar(createJMenuBar()); + + pack(); + setLocationRelativeTo(null); + setMinimumSize(new Dimension(320, 300)); + setResizable(true); + setTitle(Main.fullName); + + ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + + // Schedule the task + scheduler.schedule(new Runnable() { + @Override + public void run() { + mainPanel.repaint(); + scheduler.schedule(this, 1000 / Settings.fpsIdle, TimeUnit.MILLISECONDS); + } + }, 1, TimeUnit.SECONDS); + + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + scheduler.shutdown(); + } + + @Override + public void windowClosed(WindowEvent e) { + scheduler.shutdown(); + } + }); + } + + protected JMenuBar createJMenuBar() { + JMenuBar menuBar = new JMenuBar(); + menuBar.setBackground(Color.lightGray); + + JMenu menuOptions = new JMenu("Options"); + + JMenuItem settings = new JMenuItem("Settings"); + settings.addActionListener(new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + // Check if an instance of SettingsFrame already exists + if (SettingsFrame.getInstance() == null) { + // If not, create a new instance and make it visible + SettingsFrame settingsFrame = new SettingsFrame(GlobalQuakeFrame.this, GlobalQuake.getInstance().limitedSettings()); + settingsFrame.setVisible(true); + // Ensure that the SettingsFrame is always on top + settingsFrame.setAlwaysOnTop(true); + } + } + }); + + menuOptions.add(settings); + + menuBar.add(menuOptions); + + JMenu aboutMenu = new JMenu("Links"); + + aboutMenu.add(new OpenURLAction("https://github.com/xspanger3770/GlobalQuake/", "Open GitHub webpage")); + aboutMenu.add(new OpenURLAction("https://github.com/xspanger3770/GlobalQuake/issues/", "Report issue or request new feature")); + aboutMenu.add(new OpenURLAction("https://github.com/xspanger3770/GlobalQuake/releases/", "Check for latest version")); + aboutMenu.add(new OpenURLAction("https://www.buymeacoffee.com/jakubspangl/", "Donate")); + + menuBar.add(aboutMenu); + + return menuBar; + } + + protected void toggleList() { + hideList = !hideList; + if (hideList) { + panel.setSize(new Dimension(mainPanel.getWidth(), mainPanel.getHeight())); + list.setPreferredSize(new Dimension(0, (int) list.getPreferredSize().getHeight())); + } else { + panel.setSize(new Dimension(mainPanel.getWidth() - 300, mainPanel.getHeight())); + list.setPreferredSize(new Dimension(300, (int) list.getPreferredSize().getHeight())); + } + _containsListToggle = false; + revalidate(); + } + + public GlobalQuakePanel getGQPanel() { + return panel; + } public void clear() { - getGQPanel().clear(); - } + getGQPanel().clear(); + } } diff --git a/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/GlobalQuakePanel.java b/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/GlobalQuakePanel.java index 5424f049d..81bb53753 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/GlobalQuakePanel.java +++ b/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/GlobalQuakePanel.java @@ -439,7 +439,7 @@ private void drawTexts(Graphics2D g) { } - if(GlobalQuake.instance.isSimulation()){ + if (GlobalQuake.instance.isSimulation()) { g.setColor(Color.orange); } g.drawString(str, getWidth() - g.getFontMetrics().stringWidth(str) - 6, getHeight() - 9); @@ -638,7 +638,7 @@ private void drawEarthquakesBox(Graphics2D g, int x, int y) { g.setColor(isDark(levelColor) ? Color.white : Color.black); g.drawString(quakeString, x + 3, y + 21); - String sim = GlobalQuake.instance.isSimulation() ? " (Simulated)":""; + String sim = GlobalQuake.instance.isSimulation() ? " (Simulated)" : ""; g.setColor(Color.white); g.setFont(regionFont); @@ -659,7 +659,7 @@ private void drawEarthquakesBox(Graphics2D g, int x, int y) { var obv = quake.getHypocenter().obviousArrivalsInfo; - if(Settings.displayAdditionalQuakeInfo && obv != null && obv.total() >= EarthquakeAnalysis.OBVIOUS_CORRECT_MIN_TOTAL) { + if (Settings.displayAdditionalQuakeInfo && obv != null && obv.total() >= EarthquakeAnalysis.OBVIOUS_CORRECT_MIN_TOTAL) { str = "Obv: %.1f%%".formatted(obv.getPCT() * 100.0); g.drawString(str, x + baseWidth - g.getFontMetrics().stringWidth(str) - 5, y + 104); } diff --git a/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/feature/FeatureArchivedEarthquake.java b/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/feature/FeatureArchivedEarthquake.java index 5023c3189..209351298 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/feature/FeatureArchivedEarthquake.java +++ b/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/feature/FeatureArchivedEarthquake.java @@ -72,10 +72,10 @@ public void project(GlobeRenderer renderer, RenderEntity entity, RenderElement element = entity.getRenderElement(0); boolean displayed = !entity.getOriginal().isWrong() && entity.getOriginal().shouldBeDisplayed(); - if(displayed) { + if (displayed) { element.getShape().reset(); element.shouldDraw = renderer.project3D(element.getShape(), element.getPolygon(), true, renderProperties); - }else { + } else { element.shouldDraw = false; } } @@ -87,7 +87,7 @@ public void render(GlobeRenderer renderer, Graphics2D graphics, RenderEntity 4 ? new Color(200, 0, 0) : new Color(255, 0, 0)) - : ageInHRS < 24 ? new Color(255, 140, 0) : new Color(255,255,0); - } else if(Settings.selectedEventColorIndex == 1){ + : ageInHRS < 24 ? new Color(255, 140, 0) : new Color(255, 255, 0); + } else if (Settings.selectedEventColorIndex == 1) { col = Scale.getColorEasily(Math.max(0.06, 0.9 - quake.getDepth() / 400.0)); - } else{ + } else { col = Scale.getColorEasily(quake.getMag() / 8.0); } diff --git a/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/feature/FeatureCities.java b/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/feature/FeatureCities.java index 6126bbf0c..42a53f604 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/feature/FeatureCities.java +++ b/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/feature/FeatureCities.java @@ -39,7 +39,7 @@ private List load() { double lon = Double.parseDouble(fields[3]); int population = Integer.parseInt(fields[4]); - if(population < MIN_POPULATION){ + if (population < MIN_POPULATION) { continue; } @@ -102,7 +102,7 @@ public void render(GlobeRenderer renderer, Graphics2D graphics, RenderEntity entity, Render RenderElement elementRoot = entity.getRenderElement(0); elementRoot.getShape().reset(); elementRoot.shouldDraw = renderer.project3D(elementRoot.getShape(), elementRoot.getPolygon(), true, renderProperties); - } + } @SuppressWarnings("unchecked") @Override public boolean isEntityVisible(RenderEntity entity) { - Cluster cluster = ((RenderEntity)entity).getOriginal(); + Cluster cluster = ((RenderEntity) entity).getOriginal(); return (!Settings.hideClustersWithQuake && GlobalQuake.instance.currentTimeMillis() - cluster.getLastUpdate() <= FLASH_TIME * 5) || GlobalQuake.instance.currentTimeMillis() - cluster.getLastUpdate() <= FLASH_TIME && cluster.getEarthquake() == null; } @@ -82,17 +82,17 @@ public boolean isEntityVisible(RenderEntity entity) { public void render(GlobeRenderer renderer, Graphics2D graphics, RenderEntity entity, RenderProperties renderProperties) { RenderElement elementRoot = entity.getRenderElement(0); - if(!elementRoot.shouldDraw) { + if (!elementRoot.shouldDraw) { return; } - if((System.currentTimeMillis() / 500) % 2 != 0){ + if ((System.currentTimeMillis() / 500) % 2 != 0) { return; } graphics.setStroke(new BasicStroke(1f)); - if(Settings.antialiasingClusters) { + if (Settings.antialiasingClusters) { graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } @@ -110,7 +110,7 @@ public Point2D getCenterCoords(RenderEntity entity) { return null; } - private static final Color[] colors = {Color.WHITE, new Color(10, 100, 255), new Color(0,255,0), new Color(255,200,0), new Color(200,0,0)}; + private static final Color[] colors = {Color.WHITE, new Color(10, 100, 255), new Color(0, 255, 0), new Color(255, 200, 0), new Color(200, 0, 0)}; private Color getColorLevel(int level) { return level >= 0 && level < colors.length ? colors[level] : Color.GRAY; diff --git a/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/feature/FeatureShakemap.java b/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/feature/FeatureShakemap.java index d013e7640..b9abe4945 100644 --- a/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/feature/FeatureShakemap.java +++ b/GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/feature/FeatureShakemap.java @@ -41,7 +41,7 @@ public FeatureShakemap() { throw new RuntimeException(e); } - GlobalQuakeLocal.instance.getLocalEventHandler().registerEventListener(new GlobalQuakeLocalEventListener(){ + GlobalQuakeLocal.instance.getLocalEventHandler().registerEventListener(new GlobalQuakeLocalEventListener() { @Override public void onShakemapCreated(ShakeMapsUpdatedEvent event) { hexService.submit(() -> updateHexes()); @@ -71,18 +71,18 @@ public boolean needsProject(RenderEntity entity, boolean propertie private void updateHexes() { java.util.Map items = new HashMap<>(); - for(var pair : GlobalQuakeLocal.instance.getShakemapService().getShakeMaps().entrySet().stream() - .sorted(Comparator.comparing(kv -> kv.getValue().getRes())).toList()){ + for (var pair : GlobalQuakeLocal.instance.getShakemapService().getShakeMaps().entrySet().stream() + .sorted(Comparator.comparing(kv -> kv.getValue().getRes())).toList()) { ShakeMap shakeMap = pair.getValue(); - if(shakeMap != null){ + if (shakeMap != null) { shakeMap.getHexList().forEach(intensityHex -> { IntensityHex current = items.get(intensityHex.id()); - if(current == null){ + if (current == null) { current = findParent(items, intensityHex.id()); } - if(current == null){ + if (current == null) { items.put(intensityHex.id(), intensityHex); - } else if(intensityHex.pga() > current.pga()){ + } else if (intensityHex.pga() > current.pga()) { items.put(current.id(), new IntensityHex(current.id(), intensityHex.pga(), current.center())); } }); @@ -95,10 +95,10 @@ private void updateHexes() { private IntensityHex findParent(Map items, long id) { int res = h3.getResolution(id); - while(res >= 1){ + while (res >= 1) { res--; id = h3.cellToParent(id, res); - if(items.containsKey(id)){ + if (items.containsKey(id)) { return items.get(id); } } @@ -113,7 +113,7 @@ public Collection getElements() { @Override public void createPolygon(GlobeRenderer renderer, RenderEntity entity, RenderProperties renderProperties) { RenderElement elementHex = entity.getRenderElement(0); - if(elementHex.getPolygon() == null){ + if (elementHex.getPolygon() == null) { elementHex.setPolygon(new Polygon3D()); } @@ -126,7 +126,7 @@ public void createPolygon(Polygon3D polygon3D, List coords) { coords.add(coords.get(0)); - for(LatLng latLng : coords){ + for (LatLng latLng : coords) { Vector3D vector3D = new Vector3D( GlobeRenderer.getX_3D(latLng.lat, latLng.lng, 0), GlobeRenderer.getY_3D(latLng.lat, latLng.lng, 0), @@ -150,7 +150,7 @@ public void render(GlobeRenderer renderer, Graphics2D graphics, RenderEntity TIME_REF_LIMIT){ + if (deltaT > TIME_REF_LIMIT) { changeReference(); deltaT = (int) (time - timeReference); } @@ -88,13 +88,13 @@ private void log(long time, int rawValue, float filteredV, float ratio, float me } private void changeReference() { - if(isEmpty()) { + if (isEmpty()) { return; } long oldestTime = getTime(getOldestDataSlot()); int index = getOldestDataSlot(); - while(index != getNextSlot()) { + while (index != getNextSlot()) { times[index] = (int) (getTime(index) - oldestTime); index = (index + 1) % size; } @@ -103,7 +103,7 @@ private void changeReference() { } public void log(long time, int rawValue, float filteredV, float shortAverage, float mediumAverage, float longAverage, - float specialAverage, boolean expand){ + float specialAverage, boolean expand) { log(time, rawValue, filteredV, shortAverage / longAverage, mediumAverage / longAverage, specialAverage / longAverage, expand); } @@ -119,24 +119,24 @@ private void _resize(int new_size) { float[][] new_computed = new float[getComputedCount()][new_size]; int i2 = 0; - for(int step = 0; step < Math.min(size, new_size); step++){ + for (int step = 0; step < Math.min(size, new_size); step++) { i2 -= 1; - if(i2 < 0){ + if (i2 < 0) { i2 = new_size - 1; } nextFreeSlot -= 1; - if(nextFreeSlot < 0){ + if (nextFreeSlot < 0) { nextFreeSlot = size - 1; } new_times[i2] = times[nextFreeSlot]; - if(!server){ + if (!server) { new_rawValues[i2] = rawValues[nextFreeSlot]; } - for(int i = 0; i < getComputedCount(); i++) { + for (int i = 0; i < getComputedCount(); i++) { new_computed[i][i2] = computed[i][nextFreeSlot]; } } @@ -170,34 +170,34 @@ public int getOldestDataSlot() { return oldestDataSlot; } - public long getTime(int index){ + public long getTime(int index) { return timeReference + times[index]; } - public int getRaw(int index){ + public int getRaw(int index) { return rawValues[index]; } - public float getComputed(int type, int index){ + public float getComputed(int type, int index) { return computed[type][index]; } - public double getMediumRatio(int index){ + public double getMediumRatio(int index) { return getComputed(MEDIUM_RATIO, index); } - public double getSpecialRatio(int index){ + public double getSpecialRatio(int index) { return getComputed(SPECIAL_RATIO, index); } - public double getRatio(int index){ + public double getRatio(int index) { return getComputed(RATIO, index); } - public Log toLog(int index){ - if(isServer()){ + public Log toLog(int index) { + if (isServer()) { throw new UnsupportedOperationException("toLog() is not supported in server mode!"); } return new Log( @@ -224,23 +224,23 @@ public int getNewestDataSlot() { public WaveformBuffer extract(long start, long end) { int seconds = (int) Math.ceil((end - start) / 1000.0); - if(seconds <= 0){ + if (seconds <= 0) { throw new IllegalArgumentException("Cannot extract empty waveform buffer!"); } // additional space - seconds = (int)(seconds * 1.4); + seconds = (int) (seconds * 1.4); WaveformBuffer result = new WaveformBuffer(sps, seconds, server); - if(isEmpty()){ + if (isEmpty()) { return result; } int closest = getClosestIndex(start); long time = getTime(closest); - while(closest != getNextSlot() && time <= end){ + while (closest != getNextSlot() && time <= end) { result.log( time, isServer() ? 0 : getRaw(closest), @@ -259,21 +259,21 @@ public WaveformBuffer extract(long start, long end) { } public int getClosestIndex(long time) { - if(isEmpty()){ + if (isEmpty()) { throw new IllegalStateException("There is no closest log since the buffer is empty!"); } int low = getOldestDataSlot(); int high = getNewestDataSlot(); - if(low > high){ + if (low > high) { high += size; } - while(high - low > 1){ + while (high - low > 1) { int mid = (low + high) / 2; - if(getTime(mid % size) > time){ + if (getTime(mid % size) > time) { high = mid; - } else{ + } else { low = mid; } } @@ -286,7 +286,7 @@ public boolean isServer() { public void checkSize(int seconds) { int _size = (int) Math.ceil(seconds * sps); - if(_size != size){ + if (_size != size) { _resize(_size); } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/archive/ArchivedEvent.java b/GlobalQuakeCore/src/main/java/globalquake/core/archive/ArchivedEvent.java index 2da879674..73167254f 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/archive/ArchivedEvent.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/archive/ArchivedEvent.java @@ -5,8 +5,8 @@ public record ArchivedEvent(double lat, double lon, double maxRatio, long pWave) implements Serializable { - @Serial - private static final long serialVersionUID = 7013566809976851817L; + @Serial + private static final long serialVersionUID = 7013566809976851817L; } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/archive/ArchivedQuake.java b/GlobalQuakeCore/src/main/java/globalquake/core/archive/ArchivedQuake.java index 1f3a65b84..ac51a522b 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/archive/ArchivedQuake.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/archive/ArchivedQuake.java @@ -310,8 +310,8 @@ public String getFdsnText() { return fdsnText; } - public static void main(String[] args) { - System.err.println(UUID.randomUUID()); - } + public static void main(String[] args) { + System.err.println(UUID.randomUUID()); + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/archive/EarthquakeArchive.java b/GlobalQuakeCore/src/main/java/globalquake/core/archive/EarthquakeArchive.java index 7c71030ab..78273e1e7 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/archive/EarthquakeArchive.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/archive/EarthquakeArchive.java @@ -16,129 +16,129 @@ public class EarthquakeArchive { - public static final File ARCHIVE_FILE = new File(GlobalQuake.mainFolder, "volume/archive.dat"); - public static final File TEMP_ARCHIVE_FILE = new File(GlobalQuake.mainFolder, "volume/temp_archive.dat"); - private final ExecutorService executor; - - private List archivedQuakes = new MonitorableCopyOnWriteArrayList<>(); - - private final Map uuidArchivedQuakeMap = new ConcurrentHashMap<>(); - - public EarthquakeArchive() { - executor = Executors.newSingleThreadExecutor(); - } - - @SuppressWarnings("unchecked") - public EarthquakeArchive loadArchive() { - if (!ARCHIVE_FILE.exists()) { - Logger.info("Created new archive"); - } else { - try { - ObjectInputStream oin = new ObjectInputStream(new FileInputStream(ARCHIVE_FILE)); - archivedQuakes = (MonitorableCopyOnWriteArrayList) oin.readObject(); - oin.close(); - Logger.info("Loaded " + archivedQuakes.size() + " quakes from archive."); - } catch (Exception e) { - Logger.error(e); - } - } - - archivedQuakes.sort(Comparator.comparing(archivedQuake1 -> -archivedQuake1.getOrigin())); - buildUUIDMap(); - - return this; - } - - private void buildUUIDMap() { - for(ArchivedQuake archivedQuake : archivedQuakes){ - uuidArchivedQuakeMap.put(archivedQuake.getUuid(), archivedQuake); - } - } - - public void saveArchive() { - if (archivedQuakes != null) { - try { - ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(TEMP_ARCHIVE_FILE)); - Logger.info("Saving " + archivedQuakes.size() + " quakes to " + ARCHIVE_FILE.getName()); - out.writeObject(archivedQuakes); - out.close(); - boolean res = (!ARCHIVE_FILE.exists() || ARCHIVE_FILE.delete()) && TEMP_ARCHIVE_FILE.renameTo(ARCHIVE_FILE); - if(!res){ - Logger.error("Unable to save archive!"); - } else { - Logger.info("Archive saved"); - } - } catch (Exception e) { - Logger.error(e); - } - } - } - - public List getArchivedQuakes() { - return archivedQuakes; - } - - public void archiveQuakeAndSave(Earthquake earthquake) { - executor.submit(() -> { - try { - archiveQuake(earthquake); - - saveArchive(); - } catch(Exception e){ - Logger.error(e); - } + public static final File ARCHIVE_FILE = new File(GlobalQuake.mainFolder, "volume/archive.dat"); + public static final File TEMP_ARCHIVE_FILE = new File(GlobalQuake.mainFolder, "volume/temp_archive.dat"); + private final ExecutorService executor; + + private List archivedQuakes = new MonitorableCopyOnWriteArrayList<>(); + + private final Map uuidArchivedQuakeMap = new ConcurrentHashMap<>(); + + public EarthquakeArchive() { + executor = Executors.newSingleThreadExecutor(); + } + + @SuppressWarnings("unchecked") + public EarthquakeArchive loadArchive() { + if (!ARCHIVE_FILE.exists()) { + Logger.info("Created new archive"); + } else { + try { + ObjectInputStream oin = new ObjectInputStream(new FileInputStream(ARCHIVE_FILE)); + archivedQuakes = (MonitorableCopyOnWriteArrayList) oin.readObject(); + oin.close(); + Logger.info("Loaded " + archivedQuakes.size() + " quakes from archive."); + } catch (Exception e) { + Logger.error(e); + } + } + + archivedQuakes.sort(Comparator.comparing(archivedQuake1 -> -archivedQuake1.getOrigin())); + buildUUIDMap(); + + return this; + } + + private void buildUUIDMap() { + for (ArchivedQuake archivedQuake : archivedQuakes) { + uuidArchivedQuakeMap.put(archivedQuake.getUuid(), archivedQuake); + } + } + + public void saveArchive() { + if (archivedQuakes != null) { + try { + ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(TEMP_ARCHIVE_FILE)); + Logger.info("Saving " + archivedQuakes.size() + " quakes to " + ARCHIVE_FILE.getName()); + out.writeObject(archivedQuakes); + out.close(); + boolean res = (!ARCHIVE_FILE.exists() || ARCHIVE_FILE.delete()) && TEMP_ARCHIVE_FILE.renameTo(ARCHIVE_FILE); + if (!res) { + Logger.error("Unable to save archive!"); + } else { + Logger.info("Archive saved"); + } + } catch (Exception e) { + Logger.error(e); + } + } + } + + public List getArchivedQuakes() { + return archivedQuakes; + } + + public void archiveQuakeAndSave(Earthquake earthquake) { + executor.submit(() -> { + try { + archiveQuake(earthquake); + + saveArchive(); + } catch (Exception e) { + Logger.error(e); + } }); - } + } - private void reportQuake(Earthquake earthquake, ArchivedQuake archivedQuake) { - executor.submit(() -> { + private void reportQuake(Earthquake earthquake, ArchivedQuake archivedQuake) { + executor.submit(() -> { try { EarthquakeReporter.report(earthquake, archivedQuake); } catch (Exception e) { Logger.error(e); } }); - } - - public void archiveQuake(Earthquake earthquake) { - ArchivedQuake archivedQuake = new ArchivedQuake(earthquake); - archiveQuake(archivedQuake, earthquake); - if (Settings.reportsEnabled) { - reportQuake(earthquake, archivedQuake); - } - } - - protected synchronized void archiveQuake(ArchivedQuake archivedQuake, Earthquake earthquake) { - if(archivedQuakes == null){ - archivedQuakes = new MonitorableCopyOnWriteArrayList<>(); - } - - archivedQuake.updateRegion(); - archivedQuakes.add(0, archivedQuake); - uuidArchivedQuakeMap.put(archivedQuake.getUuid(), archivedQuake); - archivedQuakes.sort(Comparator.comparing(archivedQuake1 -> -archivedQuake1.getOrigin())); - - if(GlobalQuake.instance != null && earthquake != null) { - GlobalQuake.instance.getEventHandler().fireEvent(new QuakeArchiveEvent(earthquake, archivedQuake)); - } - - while(archivedQuakes.size() > Settings.maxArchivedQuakes){ - ArchivedQuake toRemove = archivedQuakes.get(archivedQuakes.size() - 1); - archivedQuakes.remove(toRemove); - uuidArchivedQuakeMap.remove(toRemove.getUuid()); - } - - if(archivedQuakes.size() != uuidArchivedQuakeMap.size()){ - Logger.error("Possible memory leak: %d archived quake, but %d in map".formatted(archivedQuakes.size(), uuidArchivedQuakeMap.size())); - } - } - - public ArchivedQuake getArchivedQuakeByUUID(UUID uuid){ - return uuidArchivedQuakeMap.get(uuid); - } - - public void destroy(){ - GlobalQuake.instance.stopService(executor); - } + } + + public void archiveQuake(Earthquake earthquake) { + ArchivedQuake archivedQuake = new ArchivedQuake(earthquake); + archiveQuake(archivedQuake, earthquake); + if (Settings.reportsEnabled) { + reportQuake(earthquake, archivedQuake); + } + } + + protected synchronized void archiveQuake(ArchivedQuake archivedQuake, Earthquake earthquake) { + if (archivedQuakes == null) { + archivedQuakes = new MonitorableCopyOnWriteArrayList<>(); + } + + archivedQuake.updateRegion(); + archivedQuakes.add(0, archivedQuake); + uuidArchivedQuakeMap.put(archivedQuake.getUuid(), archivedQuake); + archivedQuakes.sort(Comparator.comparing(archivedQuake1 -> -archivedQuake1.getOrigin())); + + if (GlobalQuake.instance != null && earthquake != null) { + GlobalQuake.instance.getEventHandler().fireEvent(new QuakeArchiveEvent(earthquake, archivedQuake)); + } + + while (archivedQuakes.size() > Settings.maxArchivedQuakes) { + ArchivedQuake toRemove = archivedQuakes.get(archivedQuakes.size() - 1); + archivedQuakes.remove(toRemove); + uuidArchivedQuakeMap.remove(toRemove.getUuid()); + } + + if (archivedQuakes.size() != uuidArchivedQuakeMap.size()) { + Logger.error("Possible memory leak: %d archived quake, but %d in map".formatted(archivedQuakes.size(), uuidArchivedQuakeMap.size())); + } + } + + public ArchivedQuake getArchivedQuakeByUUID(UUID uuid) { + return uuidArchivedQuakeMap.get(uuid); + } + + public void destroy() { + GlobalQuake.instance.stopService(executor); + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/database/Channel.java b/GlobalQuakeCore/src/main/java/globalquake/core/database/Channel.java index d8f0d995c..91139e987 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/database/Channel.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/database/Channel.java @@ -113,15 +113,15 @@ public void merge(Channel newChannel) { this.latitude = newChannel.latitude; this.longitude = newChannel.longitude; this.elevation = newChannel.elevation; - if(newChannel.sensitivity2 > 0) { + if (newChannel.sensitivity2 > 0) { double diff = Math.abs(sensitivity2 - newChannel.sensitivity2); - if(diff > 10){ + if (diff > 10) { Logger.trace("Sensitivity changed at station %s from %6.3E to %6.3E!".formatted(code, sensitivity2, newChannel.sensitivity2)); } sensitivity2 = newChannel.sensitivity2; } - if(inputType == InputType.UNKNOWN && newChannel.inputType != InputType.UNKNOWN){ + if (inputType == InputType.UNKNOWN && newChannel.inputType != InputType.UNKNOWN) { inputType = newChannel.inputType; } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/database/CountInputStream.java b/GlobalQuakeCore/src/main/java/globalquake/core/database/CountInputStream.java index e468c7872..b9ab981b7 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/database/CountInputStream.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/database/CountInputStream.java @@ -7,45 +7,45 @@ public class CountInputStream extends FilterInputStream { - private long count = 0L; - private Runnable event; - - public CountInputStream(InputStream in) { - super(in); - } - - public void setEvent(Runnable event) { - this.event = event; - } - - public int read() throws IOException { - final int c = super.read(); - if (c >= 0) { - count++; - event.run(); - } - return c; - } - - public int read(@Nonnull byte[] b, int off, int len) throws IOException { - final int bytesRead = super.read(b, off, len); - if (bytesRead > 0) { - count += bytesRead; - event.run(); - } - return bytesRead; - } - - public int read(@Nonnull byte[] b) throws IOException { - final int bytesRead = super.read(b); - if (bytesRead > 0) { - count += bytesRead; - event.run(); - } - return bytesRead; - } - - public long getCount() { - return count; - } + private long count = 0L; + private Runnable event; + + public CountInputStream(InputStream in) { + super(in); + } + + public void setEvent(Runnable event) { + this.event = event; + } + + public int read() throws IOException { + final int c = super.read(); + if (c >= 0) { + count++; + event.run(); + } + return c; + } + + public int read(@Nonnull byte[] b, int off, int len) throws IOException { + final int bytesRead = super.read(b, off, len); + if (bytesRead > 0) { + count += bytesRead; + event.run(); + } + return bytesRead; + } + + public int read(@Nonnull byte[] b) throws IOException { + final int bytesRead = super.read(b); + if (bytesRead > 0) { + count += bytesRead; + event.run(); + } + return bytesRead; + } + + public long getCount() { + return count; + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/database/FDSNWSDownloader.java b/GlobalQuakeCore/src/main/java/globalquake/core/database/FDSNWSDownloader.java index 8ba581e8c..d2651435a 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/database/FDSNWSDownloader.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/database/FDSNWSDownloader.java @@ -60,15 +60,15 @@ public void checkServerTrusted( } sensitivityCorrections = new ArrayList<>(); - try{ + try { File file = new File(GlobalQuake.mainFolder, "sensitivity_corrections.txt"); - if(!file.exists()) { - if(!file.createNewFile()){ + if (!file.exists()) { + if (!file.createNewFile()) { throw new RuntimeException("Failed to create sensitivity_corrections.txt file!"); } } sensitivityCorrections.addAll(loadSensitivityCorrections(file.getAbsolutePath())); - } catch(Exception e){ + } catch (Exception e) { Logger.error("Unable to load sensitivity corrections", e); } } @@ -99,7 +99,7 @@ public static List loadSensitivityCorrections(String file return corrections; } - public static void main(String[] args) throws Exception{ + public static void main(String[] args) throws Exception { GlobalQuake.prepare(new File("./.GlobalQuakeData/"), null); var a = loadSensitivityCorrections(new File(GlobalQuake.mainFolder, "sensitivity_corrections.txt").getAbsolutePath()); System.err.println(a); @@ -362,8 +362,8 @@ private static void parseChannels( } public static double getSensitivityCorrection(String networkCode, String stationCode) { - for(SensitivityCorrection sensitivityCorrection : sensitivityCorrections){ - if(sensitivityCorrection.match(networkCode, stationCode)){ + for (SensitivityCorrection sensitivityCorrection : sensitivityCorrections) { + if (sensitivityCorrection.match(networkCode, stationCode)) { return sensitivityCorrection.getMultiplier(); } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/database/SeedlinkNetwork.java b/GlobalQuakeCore/src/main/java/globalquake/core/database/SeedlinkNetwork.java index a56b2f343..921dce1c1 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/database/SeedlinkNetwork.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/database/SeedlinkNetwork.java @@ -55,7 +55,7 @@ public String toString() { "port=" + port + ']'; } - public void setStatus(int value, String str){ + public void setStatus(int value, String str) { SwingUtilities.invokeLater(() -> { getStatusBar().setString(str); getStatusBar().setValue(value); @@ -63,7 +63,7 @@ public void setStatus(int value, String str){ } public JProgressBar getStatusBar() { - if(statusBar == null){ + if (statusBar == null) { statusBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, 100); statusBar.setIndeterminate(false); statusBar.setString("Ready"); @@ -86,7 +86,7 @@ public int getConnectedStations() { } public int getTimeout() { - if(timeout < 5){ + if (timeout < 5) { timeout = DEFAULT_TIMEOUT; } return timeout; diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/database/SensitivityCorrection.java b/GlobalQuakeCore/src/main/java/globalquake/core/database/SensitivityCorrection.java index 9a7059adc..5f3b0ca0b 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/database/SensitivityCorrection.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/database/SensitivityCorrection.java @@ -16,7 +16,7 @@ public double getMultiplier() { return multiplier; } - public boolean match(String networkCode, String stationCode){ + public boolean match(String networkCode, String stationCode) { return networkCode.toUpperCase().startsWith(this.networkCode.toUpperCase()) && stationCode.toUpperCase().startsWith(this.stationCode.toUpperCase()); } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/database/Station.java b/GlobalQuakeCore/src/main/java/globalquake/core/database/Station.java index e80323906..ace3dda9b 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/database/Station.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/database/Station.java @@ -96,7 +96,7 @@ public boolean hasAvailableChannel() { public void selectBestChannel() { selectBestAvailableChannel(); - if(selectedChannel != null){ + if (selectedChannel != null) { return; } @@ -109,11 +109,11 @@ public void selectBestAvailableChannel() { selectedChannel = null; } - if(selectedChannel != null){ + if (selectedChannel != null) { return; } - for(Channel channel : getChannels()){ + for (Channel channel : getChannels()) { if (channel.isAvailable() && (selectedChannel == null || channel.getSampleRate() < selectedChannel.getSampleRate())) { selectedChannel = channel; } @@ -121,7 +121,7 @@ public void selectBestAvailableChannel() { } public boolean locationErrorSuspected() { - if(getSelectedChannel() == null){ + if (getSelectedChannel() == null) { return false; } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/database/StationDatabase.java b/GlobalQuakeCore/src/main/java/globalquake/core/database/StationDatabase.java index 602f0ac5d..f624d2f24 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/database/StationDatabase.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/database/StationDatabase.java @@ -49,7 +49,7 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE } private void convert() { - if(version < VERSION){ + if (version < VERSION) { Logger.warn("Database updated!"); networks.clear(); stationSources.forEach(stationSource -> stationSource.setLastUpdate(LocalDateTime.ofInstant(Instant.ofEpochMilli(0), ZoneId.systemDefault()))); @@ -171,9 +171,9 @@ public Lock getDatabaseWriteLock() { return databaseWriteLock; } - public static Channel getChannel(Station station, String channelCode, String locationCode){ - for(Channel channel: station.getChannels()){ - if(channel.getCode().equalsIgnoreCase(channelCode) && channel.getLocationCode().equalsIgnoreCase(locationCode)){ + public static Channel getChannel(Station station, String channelCode, String locationCode) { + for (Channel channel : station.getChannels()) { + if (channel.getCode().equalsIgnoreCase(channelCode) && channel.getLocationCode().equalsIgnoreCase(locationCode)) { return channel; } } @@ -185,8 +185,8 @@ public static Channel getOrCreateChannel(Station station, String channelCode, St double lat, double lon, double alt, double sampleRate, StationSource stationSource, double sensitivity, InputType inputType) { Channel channel = getChannel(station, channelCode, locationCode); - if(channel != null){ - if(channel.getSensitivity() <= 0 && sensitivity > 0){ + if (channel != null) { + if (channel.getSensitivity() <= 0 && sensitivity > 0) { channel.setSensitivity(sensitivity); } return channel; @@ -200,7 +200,7 @@ public static Channel getOrCreateChannel(Station station, String channelCode, St public static Station getStation(List networks, String networkCode, String stationCode) { Network network = getNetwork(networks, networkCode); - if(network == null){ + if (network == null) { return null; } @@ -209,7 +209,7 @@ public static Station getStation(List networks, String networkCode, Str public static Channel getChannel(List networks, String networkCode, String stationCode, String channelName, String locationCode) { Station station = getStation(networks, networkCode, stationCode); - if(station == null){ + if (station == null) { return null; } @@ -217,8 +217,8 @@ public static Channel getChannel(List networks, String networkCode, Str } private static Station findStation(Network network, String stationCode) { - for(Station station: network.getStations()){ - if(station.getStationCode().equalsIgnoreCase(stationCode)){ + for (Station station : network.getStations()) { + if (station.getStationCode().equalsIgnoreCase(stationCode)) { return station; } } @@ -228,11 +228,11 @@ private static Station findStation(Network network, String stationCode) { public static Station getOrCreateStation(Network network, String stationCode, String stationSite, double lat, double lon, double alt) { Station station = findStation(network, stationCode); - if(station != null){ + if (station != null) { return station; } - station = new Station(network, stationCode, stationSite, lat, lon ,alt); + station = new Station(network, stationCode, stationSite, lat, lon, alt); network.getStations().add(station); @@ -241,7 +241,7 @@ public static Station getOrCreateStation(Network network, String stationCode, St public static Station getOrInsertStation(Network network, Station stationNew) { Station station = findStation(network, stationNew.getStationCode()); - if(station != null){ + if (station != null) { return station; } @@ -251,8 +251,8 @@ public static Station getOrInsertStation(Network network, Station stationNew) { } public static Network getNetwork(List networks, String networkCode) { - for(Network network: networks){ - if(network.getNetworkCode().equalsIgnoreCase(networkCode)){ + for (Network network : networks) { + if (network.getNetworkCode().equalsIgnoreCase(networkCode)) { return network; } } @@ -262,7 +262,7 @@ public static Network getNetwork(List networks, String networkCode) { public static Network getOrCreateNetwork(List networks, String networkCode, String networkDescription) { Network resultNetwork = getNetwork(networks, networkCode); - if(resultNetwork != null) { + if (resultNetwork != null) { return resultNetwork; } @@ -274,7 +274,7 @@ public static Network getOrCreateNetwork(List networks, String networkC public static Network getOrInsertNetwork(List networks, Network network) { Network resultNetwork = getNetwork(networks, network.getNetworkCode()); - if(resultNetwork != null) { + if (resultNetwork != null) { return resultNetwork; } @@ -289,7 +289,7 @@ public Channel acceptChannel(Network network, Station station, Channel channel) Network networkFound = getOrInsertNetwork(networks, network); Station stationFound = getOrInsertStation(networkFound, station); Channel channelFound = getChannel(stationFound, channel.getCode(), channel.getLocationCode()); - if(channelFound != null) { + if (channelFound != null) { channelFound.merge(channel); } else { stationFound.getChannels().add(channel); diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/database/StationSource.java b/GlobalQuakeCore/src/main/java/globalquake/core/database/StationSource.java index b74ff3246..b73bd6c46 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/database/StationSource.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/database/StationSource.java @@ -58,7 +58,7 @@ public void setLastUpdate(LocalDateTime lastUpdate) { } public JProgressBar getStatus() { - if(status == null){ + if (status == null) { status = new JProgressBar(JProgressBar.HORIZONTAL, 0, 100); status.setIndeterminate(false); status.setString(isOutdated() ? "Needs Update" : "Ready"); diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/ClusterAnalysis.java b/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/ClusterAnalysis.java index ad1caa812..1f14edbf4 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/ClusterAnalysis.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/ClusterAnalysis.java @@ -66,7 +66,7 @@ public void run() { } private void markSWaves() { - for(Cluster cluster: getClusters()){ + for (Cluster cluster : getClusters()) { markPossibleSWaves(cluster); } } @@ -74,11 +74,12 @@ private void markSWaves() { public void destroy() { } - record EventIntensityInfo(Cluster cluster, AbstractStation station, double expectedIntensity){} + record EventIntensityInfo(Cluster cluster, AbstractStation station, double expectedIntensity) { + } private void stealEvents() { java.util.Map map = new HashMap<>(); - for(Cluster cluster : clusters) { + for (Cluster cluster : clusters) { if (cluster.getEarthquake() == null) { continue; } @@ -90,7 +91,7 @@ private void stealEvents() { double expectedIntensity = IntensityTable.getIntensity(cluster.getEarthquake().getMag(), GeoUtils.gcdToGeo(distGC)); EventIntensityInfo eventIntensityInfo = new EventIntensityInfo(cluster, station, expectedIntensity); EventIntensityInfo old = map.putIfAbsent(event, eventIntensityInfo); - if(old != null && eventIntensityInfo.expectedIntensity > old.expectedIntensity){ + if (old != null && eventIntensityInfo.expectedIntensity > old.expectedIntensity) { map.put(event, eventIntensityInfo); } } @@ -99,13 +100,13 @@ private void stealEvents() { } // reassign - for(var entry : map.entrySet()){ + for (var entry : map.entrySet()) { Event event = entry.getKey(); AbstractStation station = entry.getValue().station(); Cluster cluster = entry.getValue().cluster(); - if(!cluster.getAssignedEvents().containsKey(station)){ - if(event.assignedCluster != null){ + if (!cluster.getAssignedEvents().containsKey(station)) { + if (event.assignedCluster != null) { event.assignedCluster.getAssignedEvents().remove(station); } @@ -116,8 +117,8 @@ private void stealEvents() { } private void clearSWaves() { - for(Cluster cluster : clusters) { - if(cluster.getEarthquake() == null){ + for (Cluster cluster : clusters) { + if (cluster.getEarthquake() == null) { continue; } @@ -136,7 +137,7 @@ private void markPossibleSWaves(Cluster cluster) { for (AbstractStation station : stations) { for (Event event : station.getAnalysis().getDetectedEvents()) { if (event.isValid() && !event.isSWave() && (couldBeSArrival(event, cluster.getEarthquake()) - && !couldBeArrival(event,cluster.getEarthquake(), true, false, true))) { + && !couldBeArrival(event, cluster.getEarthquake(), true, false, true))) { event.setAsSWave(true); } } @@ -188,11 +189,11 @@ private void merge(Earthquake earthquake, List toMerge) { } private boolean canMerge(Earthquake earthquake, Cluster cluster) { - if(cluster.getEarthquake() != null && cluster.getPreviousHypocenter() != null){ + if (cluster.getEarthquake() != null && cluster.getPreviousHypocenter() != null) { int thatCorrect = cluster.getPreviousHypocenter().correctEvents; double dist = GeoUtils.greatCircleDistance(earthquake.getLat(), earthquake.getLon(), cluster.getEarthquake().getLat(), cluster.getEarthquake().getLon()); double maxDist = 6000 / (1 + thatCorrect * 0.2); - if(dist > maxDist){ + if (dist > maxDist) { return false; } } @@ -237,7 +238,7 @@ private void assignEventsToExistingEarthquakeClusters() { } @SuppressWarnings("RedundantIfStatement") - private boolean couldBeSArrival(Event event, Earthquake earthquake){ + private boolean couldBeSArrival(Event event, Earthquake earthquake) { if (!event.isValid() || earthquake == null) { return false; } @@ -274,7 +275,7 @@ public static boolean couldBeArrival(PickedEvent pickedEvent, PreliminaryHypocen return false; } - if(considerIntensity){ + if (considerIntensity) { throw new IllegalArgumentException("Preliminary Hypocenter doesn't have magnitude and cannot be assessed using intensity."); } @@ -308,7 +309,7 @@ public static boolean couldBeArrival(PickedEvent event, Hypocenter earthquake, @SuppressWarnings("RedundantIfStatement") public static boolean couldBeArrival(double eventLat, double eventLon, double eventAlt, long pWave, double quakeLat, double quakeLon, double quakeDepth, long quakeOrigin, double quakeMag, - boolean considerIntensity, boolean increasingPWindow, boolean pWaveOnly){ + boolean considerIntensity, boolean increasingPWindow, boolean pWaveOnly) { long actualTravel = pWave - quakeOrigin; double distGC = GeoUtils.greatCircleDistance(quakeLat, quakeLon, @@ -317,7 +318,7 @@ public static boolean couldBeArrival(double eventLat, double eventLon, double ev double expectedTravelPRaw = TauPTravelTimeCalculator.getPWaveTravelTime(quakeDepth, angle); - if(considerIntensity) { + if (considerIntensity) { double expectedRatio = IntensityTable.getRatio(quakeMag, GeoUtils.gcdToGeo(distGC)); if (expectedRatio < 3.0) { return false; @@ -331,7 +332,7 @@ public static boolean couldBeArrival(double eventLat, double eventLon, double ev } } - if(pWaveOnly){ + if (pWaveOnly) { return false; } @@ -366,7 +367,7 @@ private void expandExistingClusters() { private void expandCluster(Cluster cluster) { if (cluster.getEarthquake() != null && cluster.getPreviousHypocenter() != null) { - if(cluster.getPreviousHypocenter().correctEvents > 7) { + if (cluster.getPreviousHypocenter().correctEvents > 7) { expandPWaves(cluster); } } @@ -501,16 +502,16 @@ private void updateClusters() { boolean eqRemoved = earthquake != null && EarthquakeAnalysis.shouldRemove(earthquake, 0); boolean tooOld = earthquake == null && numberOfActiveEvents < minimum && GlobalQuake.instance.currentTimeMillis() - cluster.getLastUpdate() > 2 * 60 * 1000; - if ( notEnoughEvents || eqRemoved || tooOld) { + if (notEnoughEvents || eqRemoved || tooOld) { Logger.tag("Hypocs").debug("Cluster #%d marked for removal (%s || %s || %s)".formatted(cluster.id, notEnoughEvents, eqRemoved, tooOld)); toBeRemoved.add(cluster); - if(notEnoughEvents){ + if (notEnoughEvents) { toBeRemovedBadly.add(cluster); } } else { cluster.tick(); // if level changes or if it got updated (root location) - if(cluster.getLevel() != cluster.lastLevel || cluster.lastLastUpdate != cluster.getLastUpdate()){ + if (cluster.getLevel() != cluster.lastLevel || cluster.lastLastUpdate != cluster.getLastUpdate()) { GlobalQuake.instance.getEventHandler().fireEvent(new ClusterLevelUpEvent(cluster)); cluster.lastLevel = cluster.getLevel(); cluster.lastLastUpdate = cluster.getLastUpdate(); @@ -518,8 +519,8 @@ private void updateClusters() { } } - for(Cluster cluster : toBeRemovedBadly){ - if(cluster.getEarthquake() != null){ + for (Cluster cluster : toBeRemovedBadly) { + if (cluster.getEarthquake() != null) { earthquakes.remove(cluster.getEarthquake()); GlobalQuake.instance.getEventHandler().fireEvent(new QuakeRemoveEvent(cluster.getEarthquake())); } @@ -543,7 +544,7 @@ private Cluster createCluster(ArrayList validEvents) { + cluster.getAssignedEvents().size() + " events"); clusters.add(cluster); - if(GlobalQuake.instance != null){ + if (GlobalQuake.instance != null) { GlobalQuake.instance.getEventHandler().fireEvent(new ClusterCreateEvent(cluster)); } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/EarthquakeDataExport.java b/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/EarthquakeDataExport.java index 198e8e843..c23066b16 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/EarthquakeDataExport.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/EarthquakeDataExport.java @@ -8,12 +8,13 @@ import globalquake.core.earthquake.data.Earthquake; import java.util.UUID; + import org.json.JSONArray; import org.json.JSONObject; public class EarthquakeDataExport { - public static List getArchivedAndLiveEvents(){ + public static List getArchivedAndLiveEvents() { //make a copy of the earthquakes, both archived and current. List archivedQuakes = new ArrayList<>(GlobalQuake.instance.getArchive().getArchivedQuakes()); List currentEarthquakes = GlobalQuake.instance.getEarthquakeAnalysis().getEarthquakes().stream().toList(); diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/GQHypocenterSearchBenchmark.java b/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/GQHypocenterSearchBenchmark.java index 32811d307..a030e9800 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/GQHypocenterSearchBenchmark.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/GQHypocenterSearchBenchmark.java @@ -24,9 +24,9 @@ public static void main(String[] args) throws Exception { public static void performanceMeasurement() throws Exception { TauPTravelTimeCalculator.init(); - double sum = 0; + double sum = 0; - for(int i = 0; i < 5; i++) { + for (int i = 0; i < 5; i++) { sum += runStandardTest(); } @@ -154,10 +154,10 @@ private static void runSpeedTest(int station_count, long points, boolean gpu) { GQNativeFunctions.findHypocenter(stations_array, result[0], result[1], points, GQHypocs.depth_profiles.length - 1, 90.0f, 2200); } else { List events = new ArrayList<>(); - for(int i = 0; i < station_count; i++){ - events.add(new PickedEvent(r.nextLong(100000),r.nextDouble() * 90.0,r.nextDouble() * 180.0,0,100)); + for (int i = 0; i < station_count; i++) { + events.add(new PickedEvent(r.nextLong(100000), r.nextDouble() * 90.0, r.nextDouble() * 180.0, 0, 100)); } - EarthquakeAnalysis.scanArea(events, 90.0 / 360.0 * GeoUtils.EARTH_CIRCUMFERENCE, (int)points, 0, 0, (int)(TauPTravelTimeCalculator.MAX_DEPTH * 2), TauPTravelTimeCalculator.MAX_DEPTH - 1.0, FINDER_SETTINGS, true); + EarthquakeAnalysis.scanArea(events, 90.0 / 360.0 * GeoUtils.EARTH_CIRCUMFERENCE, (int) points, 0, 0, (int) (TauPTravelTimeCalculator.MAX_DEPTH * 2), TauPTravelTimeCalculator.MAX_DEPTH - 1.0, FINDER_SETTINGS, true); } } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/data/Cluster.java b/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/data/Cluster.java index 11065f7f7..3169c86a1 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/data/Cluster.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/data/Cluster.java @@ -17,303 +17,301 @@ public class Cluster implements Warnable { - public static final int MAX_LEVEL = 4; - private final UUID uuid; - private final Map assignedEvents; - private double rootLat; - private double rootLon; - public int updateCount; - private long lastUpdate; - - private Earthquake earthquake; - private Hypocenter previousHypocenter; - - private Hypocenter lastValidHypocenter; - private int level; - - public int lastEpicenterUpdate; - - private double anchorLon; - private double anchorLat; - public int revisionID; - - public static final double NONE = -999; - - public final Color color = randomColor(); - - public int lastLevel = -1; - public long lastLastUpdate = -1; - - public final int id; - - private static final AtomicInteger nextID = new AtomicInteger(0); - - private Color randomColor() { - Random random = new Random(); - - // Generate random values for the red, green, and blue components - int red = random.nextInt(256); // 0-255 - int blue = random.nextInt(256); // 0-255 - - // Create a new Color object with the random values - return new Color(red, 255, blue); - } - - public Cluster(UUID uuid, double rootLat, double rootLon, int level) { - this.assignedEvents = new ConcurrentHashMap<>(); - this.level = level; - this.id = nextID.incrementAndGet(); - this.uuid = uuid; - this.rootLat = rootLat; - this.rootLon = rootLon; - this.anchorLon = NONE; - this.anchorLat = NONE; - this.lastUpdate = GlobalQuake.instance == null ? System.currentTimeMillis() : GlobalQuake.instance.currentTimeMillis(); - this.updateCount = 0; - this.earthquake = null; - } - - public Cluster() { - this(UUID.randomUUID(), NONE, NONE, 0); - } - - public Hypocenter getPreviousHypocenter() { - return previousHypocenter; - } - - public void setPreviousHypocenter(Hypocenter hypocenter) { - this.previousHypocenter = hypocenter; - if(hypocenter != null){ - lastValidHypocenter = hypocenter; - } - } - - public Hypocenter getLastValidHypocenter() { - return lastValidHypocenter; - } - - public UUID getUuid() { - return uuid; - } - - public void addEvent() { - lastUpdate = GlobalQuake.instance == null ? System.currentTimeMillis() : GlobalQuake.instance.currentTimeMillis(); - } - - /** - * - * @return all events that were added to this cluster - */ - public Map getAssignedEvents() { - return assignedEvents; - } - - public void tick() { - if (checkForUpdates()) { - calculateRoot(anchorLat == NONE); - calculateLevel(); - lastUpdate = GlobalQuake.instance == null ? System.currentTimeMillis() : GlobalQuake.instance.currentTimeMillis(); - } - } - - - - private boolean checkForUpdates() { - int upd = 0; - for (Event e : getAssignedEvents().values()) { - upd += e.getUpdatesCount(); - } - boolean b = (upd != updateCount); - updateCount = upd; - return b; - } - - private void calculateLevel() { - double _dist_sum = 0; - int n = 0; - int lvl_1 = 0; - int lvl_2 = 0; - int lvl_3 = 0; - int lvl_4 = 0; - for (Event e : getAssignedEvents().values()) { - if(!e.isValid()){ - continue; - } - - _dist_sum += GeoUtils.greatCircleDistance(rootLat, rootLon, e.getAnalysis().getStation().getLatitude(), - e.getAnalysis().getStation().getLongitude()); - n++; - - if (e.getMaxRatio() >= 64) { - lvl_1++; - } - if (e.getMaxRatio() >= 1000) { - lvl_2++; - } - if (e.getMaxRatio() >= 10000) { - lvl_3++; - } - if (e.getMaxRatio() >= 50000) { - lvl_4++; - } - } - - double dist_avg = _dist_sum / n; - - int _level = 0; - if ((lvl_1 >= 7 || lvl_2 >= 4) && dist_avg > 10) { - _level = 1; - } - if ((lvl_2 >= 7 || lvl_3 >= 3) && dist_avg > 25) { - _level = 2; - } - if ((lvl_3 >= 5 || lvl_4 >= 3) && dist_avg > 50) { - _level = 3; - } - if ((lvl_4 >= 4) && dist_avg > 75) { - _level = 4; - } - level = _level; - } - - public void calculateRoot(boolean useAsAnchor) { - int n = 0; - double sumLat = 0; - double sumLonSin = 0; - double sumLonCos = 0; - - for (Event e : getAssignedEvents().values()) { - if (!e.isValid()) { - continue; - } - - double lat = e.getLatFromStation(); - double lon = Math.toRadians(e.getLonFromStation()); // Convert longitude to radians - - sumLat += lat; - sumLonSin += Math.sin(lon); // Sum of sin values for longitude - sumLonCos += Math.cos(lon); // Sum of cos values for longitude - n++; - } - - if (n > 0) { - rootLat = sumLat / n; - double avgLonSin = sumLonSin / n; - double avgLonCos = sumLonCos / n; - rootLon = Math.toDegrees(Math.atan2(avgLonSin, avgLonCos)); // Convert average vector back to degrees - - if (rootLon < -180) { - rootLon += 360; // Normalize longitude - } else if (rootLon > 180) { - rootLon -= 360; // Normalize longitude - } - - if(useAsAnchor) { - anchorLat = rootLat; - anchorLon = rootLon; - } - } - } - - // For testing only - public void calculateRoot(List fakeStations) { - int n = 0; - double sumLat = 0; - double sumLon = 0; - for (EarthquakeAnalysisTraining.FakeStation fakeStation : fakeStations) { - sumLat += fakeStation.lat(); - sumLon += fakeStation.lon(); - n++; - } - if (n > 0) { - rootLat = sumLat / n; - rootLon = sumLon / n; - anchorLat = rootLat; - anchorLon = rootLon; - } - } - - public double getRootLat() { - return rootLat; - } - - public double getRootLon() { - return rootLon; - } - - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public boolean containsStation(AbstractStation station) { - return getAssignedEvents().containsKey(station); - } - - public long getLastUpdate() { - return lastUpdate; - } - - public Earthquake getEarthquake() { - return earthquake; - } - - public void setEarthquake(Earthquake earthquake) { - this.earthquake = earthquake; - } - - public int getLevel() { - return level; - } - - public void updateAnchor(Hypocenter bestHypocenter) { - this.anchorLat = bestHypocenter.lat; - this.anchorLon = bestHypocenter.lon; - } - - public double getAnchorLat() { - return anchorLat; - } - - public double getAnchorLon() { - return anchorLon; - } - - @Override - public String toString() { - return "Cluster{" + - "uuid=" + uuid + - ", rootLat=" + rootLat + - ", rootLon=" + rootLon + - ", updateCount=" + updateCount + - ", lastUpdate=" + lastUpdate + - ", earthquake=" + earthquake + - ", anchorLon=" + anchorLon + - ", anchorLat=" + anchorLat + - '}'; - } - - @SuppressWarnings("unused") - @Override - public double getWarningLat() { - return getAnchorLat(); - } - - @SuppressWarnings("unused") - @Override - public double getWarningLon() { - return getAnchorLon(); - } - - public void resetAnchor() { - this.anchorLat = rootLat; - this.anchorLon = rootLon; - } - - public void updateLevel(int level) { - lastUpdate = GlobalQuake.instance == null ? System.currentTimeMillis() : GlobalQuake.instance.currentTimeMillis(); - this.level = level; - } - - public void updateRoot(double rootLat, double rootLon) { - this.rootLat = rootLat; - this.rootLon = rootLon; - lastUpdate = GlobalQuake.instance == null ? System.currentTimeMillis() : GlobalQuake.instance.currentTimeMillis(); - } + public static final int MAX_LEVEL = 4; + private final UUID uuid; + private final Map assignedEvents; + private double rootLat; + private double rootLon; + public int updateCount; + private long lastUpdate; + + private Earthquake earthquake; + private Hypocenter previousHypocenter; + + private Hypocenter lastValidHypocenter; + private int level; + + public int lastEpicenterUpdate; + + private double anchorLon; + private double anchorLat; + public int revisionID; + + public static final double NONE = -999; + + public final Color color = randomColor(); + + public int lastLevel = -1; + public long lastLastUpdate = -1; + + public final int id; + + private static final AtomicInteger nextID = new AtomicInteger(0); + + private Color randomColor() { + Random random = new Random(); + + // Generate random values for the red, green, and blue components + int red = random.nextInt(256); // 0-255 + int blue = random.nextInt(256); // 0-255 + + // Create a new Color object with the random values + return new Color(red, 255, blue); + } + + public Cluster(UUID uuid, double rootLat, double rootLon, int level) { + this.assignedEvents = new ConcurrentHashMap<>(); + this.level = level; + this.id = nextID.incrementAndGet(); + this.uuid = uuid; + this.rootLat = rootLat; + this.rootLon = rootLon; + this.anchorLon = NONE; + this.anchorLat = NONE; + this.lastUpdate = GlobalQuake.instance == null ? System.currentTimeMillis() : GlobalQuake.instance.currentTimeMillis(); + this.updateCount = 0; + this.earthquake = null; + } + + public Cluster() { + this(UUID.randomUUID(), NONE, NONE, 0); + } + + public Hypocenter getPreviousHypocenter() { + return previousHypocenter; + } + + public void setPreviousHypocenter(Hypocenter hypocenter) { + this.previousHypocenter = hypocenter; + if (hypocenter != null) { + lastValidHypocenter = hypocenter; + } + } + + public Hypocenter getLastValidHypocenter() { + return lastValidHypocenter; + } + + public UUID getUuid() { + return uuid; + } + + public void addEvent() { + lastUpdate = GlobalQuake.instance == null ? System.currentTimeMillis() : GlobalQuake.instance.currentTimeMillis(); + } + + /** + * @return all events that were added to this cluster + */ + public Map getAssignedEvents() { + return assignedEvents; + } + + public void tick() { + if (checkForUpdates()) { + calculateRoot(anchorLat == NONE); + calculateLevel(); + lastUpdate = GlobalQuake.instance == null ? System.currentTimeMillis() : GlobalQuake.instance.currentTimeMillis(); + } + } + + + private boolean checkForUpdates() { + int upd = 0; + for (Event e : getAssignedEvents().values()) { + upd += e.getUpdatesCount(); + } + boolean b = (upd != updateCount); + updateCount = upd; + return b; + } + + private void calculateLevel() { + double _dist_sum = 0; + int n = 0; + int lvl_1 = 0; + int lvl_2 = 0; + int lvl_3 = 0; + int lvl_4 = 0; + for (Event e : getAssignedEvents().values()) { + if (!e.isValid()) { + continue; + } + + _dist_sum += GeoUtils.greatCircleDistance(rootLat, rootLon, e.getAnalysis().getStation().getLatitude(), + e.getAnalysis().getStation().getLongitude()); + n++; + + if (e.getMaxRatio() >= 64) { + lvl_1++; + } + if (e.getMaxRatio() >= 1000) { + lvl_2++; + } + if (e.getMaxRatio() >= 10000) { + lvl_3++; + } + if (e.getMaxRatio() >= 50000) { + lvl_4++; + } + } + + double dist_avg = _dist_sum / n; + + int _level = 0; + if ((lvl_1 >= 7 || lvl_2 >= 4) && dist_avg > 10) { + _level = 1; + } + if ((lvl_2 >= 7 || lvl_3 >= 3) && dist_avg > 25) { + _level = 2; + } + if ((lvl_3 >= 5 || lvl_4 >= 3) && dist_avg > 50) { + _level = 3; + } + if ((lvl_4 >= 4) && dist_avg > 75) { + _level = 4; + } + level = _level; + } + + public void calculateRoot(boolean useAsAnchor) { + int n = 0; + double sumLat = 0; + double sumLonSin = 0; + double sumLonCos = 0; + + for (Event e : getAssignedEvents().values()) { + if (!e.isValid()) { + continue; + } + + double lat = e.getLatFromStation(); + double lon = Math.toRadians(e.getLonFromStation()); // Convert longitude to radians + + sumLat += lat; + sumLonSin += Math.sin(lon); // Sum of sin values for longitude + sumLonCos += Math.cos(lon); // Sum of cos values for longitude + n++; + } + + if (n > 0) { + rootLat = sumLat / n; + double avgLonSin = sumLonSin / n; + double avgLonCos = sumLonCos / n; + rootLon = Math.toDegrees(Math.atan2(avgLonSin, avgLonCos)); // Convert average vector back to degrees + + if (rootLon < -180) { + rootLon += 360; // Normalize longitude + } else if (rootLon > 180) { + rootLon -= 360; // Normalize longitude + } + + if (useAsAnchor) { + anchorLat = rootLat; + anchorLon = rootLon; + } + } + } + + // For testing only + public void calculateRoot(List fakeStations) { + int n = 0; + double sumLat = 0; + double sumLon = 0; + for (EarthquakeAnalysisTraining.FakeStation fakeStation : fakeStations) { + sumLat += fakeStation.lat(); + sumLon += fakeStation.lon(); + n++; + } + if (n > 0) { + rootLat = sumLat / n; + rootLon = sumLon / n; + anchorLat = rootLat; + anchorLon = rootLon; + } + } + + public double getRootLat() { + return rootLat; + } + + public double getRootLon() { + return rootLon; + } + + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + public boolean containsStation(AbstractStation station) { + return getAssignedEvents().containsKey(station); + } + + public long getLastUpdate() { + return lastUpdate; + } + + public Earthquake getEarthquake() { + return earthquake; + } + + public void setEarthquake(Earthquake earthquake) { + this.earthquake = earthquake; + } + + public int getLevel() { + return level; + } + + public void updateAnchor(Hypocenter bestHypocenter) { + this.anchorLat = bestHypocenter.lat; + this.anchorLon = bestHypocenter.lon; + } + + public double getAnchorLat() { + return anchorLat; + } + + public double getAnchorLon() { + return anchorLon; + } + + @Override + public String toString() { + return "Cluster{" + + "uuid=" + uuid + + ", rootLat=" + rootLat + + ", rootLon=" + rootLon + + ", updateCount=" + updateCount + + ", lastUpdate=" + lastUpdate + + ", earthquake=" + earthquake + + ", anchorLon=" + anchorLon + + ", anchorLat=" + anchorLat + + '}'; + } + + @SuppressWarnings("unused") + @Override + public double getWarningLat() { + return getAnchorLat(); + } + + @SuppressWarnings("unused") + @Override + public double getWarningLon() { + return getAnchorLon(); + } + + public void resetAnchor() { + this.anchorLat = rootLat; + this.anchorLon = rootLon; + } + + public void updateLevel(int level) { + lastUpdate = GlobalQuake.instance == null ? System.currentTimeMillis() : GlobalQuake.instance.currentTimeMillis(); + this.level = level; + } + + public void updateRoot(double rootLat, double rootLon) { + this.rootLat = rootLat; + this.rootLon = rootLon; + lastUpdate = GlobalQuake.instance == null ? System.currentTimeMillis() : GlobalQuake.instance.currentTimeMillis(); + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/data/Hypocenter.java b/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/data/Hypocenter.java index e45f7de96..4b125ba0b 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/data/Hypocenter.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/data/Hypocenter.java @@ -8,115 +8,115 @@ import java.util.List; public class Hypocenter { - public final double totalErr; + public final double totalErr; public int correctEvents; - public final double lat; - public final double lon; - public double depth; - public long origin; - - public int usedEvents; - - public double magnitude; - public List mags; - public ObviousArrivalsInfo obviousArrivalsInfo; - - public final DepthConfidenceInterval depthConfidenceInterval; - - public final List polygonConfidenceIntervals; - public double depthUncertainty; - public double locationUncertainty; - public boolean depthFixed; - - public Quality quality; - public int reducedEvents; - public int totalEvents; - public MagnitudeType magnitudeType; - - public Hypocenter(double lat, double lon, double depth, long origin, double err, int correctEvents, - DepthConfidenceInterval depthConfidenceInterval, - List polygonConfidenceIntervals) { - this.lat = lat; - this.lon = lon; - this.depth = depth; - this.origin = origin; - this.totalErr = err; - this.correctEvents = correctEvents; - this.depthConfidenceInterval = depthConfidenceInterval; - this.polygonConfidenceIntervals = polygonConfidenceIntervals; - } - - public void magnitudeUpdate(Hypocenter bestHypocenter) { - this.usedEvents = bestHypocenter.usedEvents; - this.correctEvents = bestHypocenter.correctEvents; - this.reducedEvents = bestHypocenter.reducedEvents; - this.totalEvents = bestHypocenter.totalEvents; - this.magnitude = bestHypocenter.magnitude; - this.mags = bestHypocenter.mags; - this.magnitudeType = bestHypocenter.magnitudeType; - } - - public double getCorrectness(){ - return (correctEvents) / (double) usedEvents; - } - - public int getWrongEventCount(){ - return usedEvents - correctEvents; - } - - @Override - public String toString() { - return "Hypocenter{" + - "totalErr=" + totalErr + - ", correctEvents=" + correctEvents + - ", lat=" + lat + - ", lon=" + lon + - ", depth=" + depth + - ", origin=" + origin + - ", selectedEvents=" + usedEvents + - ", magnitude=" + magnitude + - ", mags=" + mags + - ", obviousArrivalsInfo=" + obviousArrivalsInfo + - ", depthConfidenceInterval=" + depthConfidenceInterval + - '}'; - } + public final double lat; + public final double lon; + public double depth; + public long origin; + + public int usedEvents; + + public double magnitude; + public List mags; + public ObviousArrivalsInfo obviousArrivalsInfo; + + public final DepthConfidenceInterval depthConfidenceInterval; + + public final List polygonConfidenceIntervals; + public double depthUncertainty; + public double locationUncertainty; + public boolean depthFixed; + + public Quality quality; + public int reducedEvents; + public int totalEvents; + public MagnitudeType magnitudeType; + + public Hypocenter(double lat, double lon, double depth, long origin, double err, int correctEvents, + DepthConfidenceInterval depthConfidenceInterval, + List polygonConfidenceIntervals) { + this.lat = lat; + this.lon = lon; + this.depth = depth; + this.origin = origin; + this.totalErr = err; + this.correctEvents = correctEvents; + this.depthConfidenceInterval = depthConfidenceInterval; + this.polygonConfidenceIntervals = polygonConfidenceIntervals; + } + + public void magnitudeUpdate(Hypocenter bestHypocenter) { + this.usedEvents = bestHypocenter.usedEvents; + this.correctEvents = bestHypocenter.correctEvents; + this.reducedEvents = bestHypocenter.reducedEvents; + this.totalEvents = bestHypocenter.totalEvents; + this.magnitude = bestHypocenter.magnitude; + this.mags = bestHypocenter.mags; + this.magnitudeType = bestHypocenter.magnitudeType; + } + + public double getCorrectness() { + return (correctEvents) / (double) usedEvents; + } + + public int getWrongEventCount() { + return usedEvents - correctEvents; + } + + @Override + public String toString() { + return "Hypocenter{" + + "totalErr=" + totalErr + + ", correctEvents=" + correctEvents + + ", lat=" + lat + + ", lon=" + lon + + ", depth=" + depth + + ", origin=" + origin + + ", selectedEvents=" + usedEvents + + ", magnitude=" + magnitude + + ", mags=" + mags + + ", obviousArrivalsInfo=" + obviousArrivalsInfo + + ", depthConfidenceInterval=" + depthConfidenceInterval + + '}'; + } public void calculateQuality() { - PolygonConfidenceInterval lastInterval = polygonConfidenceIntervals.get(polygonConfidenceIntervals.size() - 1); - - double errOrigin = (lastInterval.maxOrigin() - lastInterval.minOrigin()) / 1000.0; - double errDepth = (depthConfidenceInterval.maxDepth() - depthConfidenceInterval.minDepth()); - - double[] result = calculateLocationQuality(lastInterval); - double errNS = result[0]; - double errEW = result[1]; - - double pct = getCorrectness() * 100.0; - int stations = usedEvents; - - this.quality = new Quality(errOrigin, errDepth, errNS, errEW, stations, pct); - } - - private static double[] calculateLocationQuality(PolygonConfidenceInterval lastInterval) { - double errNS = 0; - double errEW = 0; - - for (int i = 0; i < lastInterval.n(); i++) { - double ang = lastInterval.offset() + (i / (double) lastInterval.n()) * 360.0; - double length = lastInterval.lengths().get(i); - - if (((int) ((ang + 360.0 - 45.0) / 90)) % 2 == 1) { - if (length > errNS) { - errNS = length; - } - } else { - if (length > errEW) { - errEW = length; - } - } - } - - return new double[]{errNS, errEW}; - } + PolygonConfidenceInterval lastInterval = polygonConfidenceIntervals.get(polygonConfidenceIntervals.size() - 1); + + double errOrigin = (lastInterval.maxOrigin() - lastInterval.minOrigin()) / 1000.0; + double errDepth = (depthConfidenceInterval.maxDepth() - depthConfidenceInterval.minDepth()); + + double[] result = calculateLocationQuality(lastInterval); + double errNS = result[0]; + double errEW = result[1]; + + double pct = getCorrectness() * 100.0; + int stations = usedEvents; + + this.quality = new Quality(errOrigin, errDepth, errNS, errEW, stations, pct); + } + + private static double[] calculateLocationQuality(PolygonConfidenceInterval lastInterval) { + double errNS = 0; + double errEW = 0; + + for (int i = 0; i < lastInterval.n(); i++) { + double ang = lastInterval.offset() + (i / (double) lastInterval.n()) * 360.0; + double length = lastInterval.lengths().get(i); + + if (((int) ((ang + 360.0 - 45.0) / 90)) % 2 == 1) { + if (length > errNS) { + errNS = length; + } + } else { + if (length > errEW) { + errEW = length; + } + } + } + + return new double[]{errNS, errEW}; + } } \ No newline at end of file diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/data/HypocenterCondition.java b/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/data/HypocenterCondition.java index 89827b52d..ad1950d90 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/data/HypocenterCondition.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/data/HypocenterCondition.java @@ -2,6 +2,6 @@ public enum HypocenterCondition { - OK, NULL, DISTANT_EVENT_NOT_ENOUGH_STATIONS, NOT_ENOUGH_CORRECT_STATIONS, TOO_SHALLOW_ANGLE, PREVIOUS_WAS_BETTER, PREVIOUS_WAS_BETTER_QUALITY, + OK, NULL, DISTANT_EVENT_NOT_ENOUGH_STATIONS, NOT_ENOUGH_CORRECT_STATIONS, TOO_SHALLOW_ANGLE, PREVIOUS_WAS_BETTER, PREVIOUS_WAS_BETTER_QUALITY, } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/data/HypocenterFinderSettings.java b/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/data/HypocenterFinderSettings.java index 1a7aa5863..709e36fac 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/data/HypocenterFinderSettings.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/data/HypocenterFinderSettings.java @@ -1,5 +1,6 @@ package globalquake.core.earthquake.data; public record HypocenterFinderSettings( - double pWaveInaccuracyThreshold, double correctnessThreshold, double resolution, double resolutionGPU, int minStations, boolean useCUDA) { + double pWaveInaccuracyThreshold, double correctnessThreshold, double resolution, double resolutionGPU, + int minStations, boolean useCUDA) { } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/quality/Quality.java b/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/quality/Quality.java index b94a45fd1..5a43e2a7a 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/quality/Quality.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/quality/Quality.java @@ -30,8 +30,8 @@ public Quality(double errOrigin, double errDepth, double errNS, double errEW, in private QualityClass summarize() { QualityClass result = QualityClass.S; QualityCriteria[] allCriteria = {qualityDepth, qualityOrigin, qualityNS, qualityEW, qualityStations}; - for(QualityCriteria criteria : allCriteria){ - if(criteria.getQualityClass().ordinal() > result.ordinal()){ + for (QualityCriteria criteria : allCriteria) { + if (criteria.getQualityClass().ordinal() > result.ordinal()) { result = criteria.getQualityClass(); } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/quality/QualityClass.java b/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/quality/QualityClass.java index 27e89a4e1..9ee04e78d 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/quality/QualityClass.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/quality/QualityClass.java @@ -6,14 +6,14 @@ public enum QualityClass implements Serializable { S(new Color(0, 90, 192)), - A(new Color(0,255, 0)), - B(new Color(255,255,0)), - C(new Color(255,140,0)), - D(new Color(255,0,0)); + A(new Color(0, 255, 0)), + B(new Color(255, 255, 0)), + C(new Color(255, 140, 0)), + D(new Color(255, 0, 0)); private final Color color; - QualityClass(Color color){ + QualityClass(Color color) { this.color = color; } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/quality/QualityCriteria.java b/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/quality/QualityCriteria.java index 46a366f30..cf94fe9a8 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/quality/QualityCriteria.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/earthquake/quality/QualityCriteria.java @@ -8,7 +8,7 @@ public final class QualityCriteria { private final double value; private final boolean smallerBetter; - public QualityCriteria(double[] thresholds, double value, boolean smallerBetter){ + public QualityCriteria(double[] thresholds, double value, boolean smallerBetter) { this.thresholds = thresholds; this.value = value; this.smallerBetter = smallerBetter; @@ -20,9 +20,9 @@ public double getValue() { public QualityClass getQualityClass() { int result = 0; - for(double threshold : thresholds){ - if(smallerBetter ? value > threshold : value < threshold){ - result ++; + for (double threshold : thresholds) { + if (smallerBetter ? value > threshold : value < threshold) { + result++; } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/events/GlobalQuakeEventHandler.java b/GlobalQuakeCore/src/main/java/globalquake/core/events/GlobalQuakeEventHandler.java index 8b1567951..0c74333ab 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/events/GlobalQuakeEventHandler.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/events/GlobalQuakeEventHandler.java @@ -24,19 +24,19 @@ public GlobalQuakeEventHandler runHandler() { return this; } - public void stopHandler(){ + public void stopHandler() { GlobalQuake.instance.stopService(defaultExecutor); GlobalQuake.instance.stopService(seedlinkExecutor); eventListeners.clear(); } - public void registerEventListener(GlobalQuakeEventListener eventListener){ + public void registerEventListener(GlobalQuakeEventListener eventListener) { eventListeners.add(eventListener); } - public void fireEvent(GlobalQuakeEvent event){ + public void fireEvent(GlobalQuakeEvent event) { getExecutorFor(event).submit(() -> { - if(event.shouldLog()) { + if (event.shouldLog()) { Logger.tag("Event").trace("Event fired: %s".formatted(event.toString())); } for (GlobalQuakeEventListener eventListener : eventListeners) { @@ -50,7 +50,7 @@ public void fireEvent(GlobalQuakeEvent event){ } private ExecutorService getExecutorFor(GlobalQuakeEvent event) { - if(event instanceof SeedlinkEvent){ + if (event instanceof SeedlinkEvent) { return seedlinkExecutor; } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/events/GlobalQuakeEventListener.java b/GlobalQuakeCore/src/main/java/globalquake/core/events/GlobalQuakeEventListener.java index e93d9af82..c4b9d8aeb 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/events/GlobalQuakeEventListener.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/events/GlobalQuakeEventListener.java @@ -4,19 +4,27 @@ public class GlobalQuakeEventListener { - public void onClusterCreate(ClusterCreateEvent event) {} + public void onClusterCreate(ClusterCreateEvent event) { + } - public void onQuakeCreate(QuakeCreateEvent event) {} + public void onQuakeCreate(QuakeCreateEvent event) { + } - public void onQuakeUpdate(QuakeUpdateEvent event) {} + public void onQuakeUpdate(QuakeUpdateEvent event) { + } - public void onQuakeRemove(QuakeRemoveEvent event) {} + public void onQuakeRemove(QuakeRemoveEvent event) { + } - public void onQuakeArchive(QuakeArchiveEvent event) {} + public void onQuakeArchive(QuakeArchiveEvent event) { + } - public void onNewData(SeedlinkDataEvent event) {} + public void onNewData(SeedlinkDataEvent event) { + } - public void onClusterLevelup(ClusterLevelUpEvent event) {} + public void onClusterLevelup(ClusterLevelUpEvent event) { + } - public void onQuakeReport(QuakeReportEvent event) {} + public void onQuakeReport(QuakeReportEvent event) { + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/events/specific/GlobalQuakeEvent.java b/GlobalQuakeCore/src/main/java/globalquake/core/events/specific/GlobalQuakeEvent.java index 19c7b235c..fcc3902c3 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/events/specific/GlobalQuakeEvent.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/events/specific/GlobalQuakeEvent.java @@ -6,6 +6,8 @@ public interface GlobalQuakeEvent { void run(GlobalQuakeEventListener eventListener); - default boolean shouldLog() {return true;} + default boolean shouldLog() { + return true; + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/events/specific/QuakeReportEvent.java b/GlobalQuakeCore/src/main/java/globalquake/core/events/specific/QuakeReportEvent.java index 9c7cf9793..2f0c83b88 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/events/specific/QuakeReportEvent.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/events/specific/QuakeReportEvent.java @@ -6,7 +6,8 @@ import java.awt.image.BufferedImage; -public record QuakeReportEvent(Earthquake earthquake, ArchivedQuake archivedQuake, BufferedImage map, BufferedImage intensities) implements GlobalQuakeEvent { +public record QuakeReportEvent(Earthquake earthquake, ArchivedQuake archivedQuake, BufferedImage map, + BufferedImage intensities) implements GlobalQuakeEvent { @Override public void run(GlobalQuakeEventListener eventListener) { diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/events/specific/SeedlinkEvent.java b/GlobalQuakeCore/src/main/java/globalquake/core/events/specific/SeedlinkEvent.java index a15556efc..66178608c 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/events/specific/SeedlinkEvent.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/events/specific/SeedlinkEvent.java @@ -2,7 +2,7 @@ import globalquake.core.events.GlobalQuakeEventListener; -public interface SeedlinkEvent extends GlobalQuakeEvent{ +public interface SeedlinkEvent extends GlobalQuakeEvent { void run(GlobalQuakeEventListener eventListener); diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/exception/FatalApplicationException.java b/GlobalQuakeCore/src/main/java/globalquake/core/exception/FatalApplicationException.java index 5dc5fd31f..b33159471 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/exception/FatalApplicationException.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/exception/FatalApplicationException.java @@ -2,18 +2,18 @@ public class FatalApplicationException extends Exception implements FatalError { - @SuppressWarnings("unused") - public FatalApplicationException(Throwable cause) { - super(cause); - } - - public FatalApplicationException(String message, Throwable cause) { - super(message, cause); - } + @SuppressWarnings("unused") + public FatalApplicationException(Throwable cause) { + super(cause); + } - @Override - public String getUserMessage() { - return super.getMessage(); - } + public FatalApplicationException(String message, Throwable cause) { + super(message, cause); + } + + @Override + public String getUserMessage() { + return super.getMessage(); + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/exception/FatalError.java b/GlobalQuakeCore/src/main/java/globalquake/core/exception/FatalError.java index 35b5c98c8..62e6e1d04 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/exception/FatalError.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/exception/FatalError.java @@ -1,5 +1,5 @@ package globalquake.core.exception; -public interface FatalError extends ApplicationException{ +public interface FatalError extends ApplicationException { } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/exception/FatalIOException.java b/GlobalQuakeCore/src/main/java/globalquake/core/exception/FatalIOException.java index ad5a622d0..a81462428 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/exception/FatalIOException.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/exception/FatalIOException.java @@ -1,9 +1,9 @@ package globalquake.core.exception; -public class FatalIOException extends FatalApplicationException{ +public class FatalIOException extends FatalApplicationException { - public FatalIOException(String message, Throwable cause) { - super(message, cause); - } + public FatalIOException(String message, Throwable cause) { + super(message, cause); + } } \ No newline at end of file diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/exception/action/IgnoreAction.java b/GlobalQuakeCore/src/main/java/globalquake/core/exception/action/IgnoreAction.java index f77707c45..dd2a2657f 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/exception/action/IgnoreAction.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/exception/action/IgnoreAction.java @@ -10,19 +10,19 @@ public class IgnoreAction extends AbstractAction { - public IgnoreAction() { - super("Ignore"); - putValue(SHORT_DESCRIPTION, "Ignore the error and continue (unsafe)"); + public IgnoreAction() { + super("Ignore"); + putValue(SHORT_DESCRIPTION, "Ignore the error and continue (unsafe)"); putValue(MNEMONIC_KEY, KeyEvent.VK_I); - } + } - @Override - public void actionPerformed(ActionEvent e) { - Window w = SwingUtilities.getWindowAncestor((Component) e.getSource()); + @Override + public void actionPerformed(ActionEvent e) { + Window w = SwingUtilities.getWindowAncestor((Component) e.getSource()); - if (w != null) { - w.setVisible(false); - } - } + if (w != null) { + w.setVisible(false); + } + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/exception/action/TerminateAction.java b/GlobalQuakeCore/src/main/java/globalquake/core/exception/action/TerminateAction.java index 63d3e26d9..7d27acc0c 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/exception/action/TerminateAction.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/exception/action/TerminateAction.java @@ -9,7 +9,7 @@ */ public final class TerminateAction extends AbstractAction { - public TerminateAction() { + public TerminateAction() { super("Terminate"); putValue(SHORT_DESCRIPTION, "Terminates the application"); putValue(MNEMONIC_KEY, KeyEvent.VK_T); diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/geo/DistanceUnit.java b/GlobalQuakeCore/src/main/java/globalquake/core/geo/DistanceUnit.java index 416996902..11aa0d880 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/geo/DistanceUnit.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/geo/DistanceUnit.java @@ -9,8 +9,8 @@ public enum DistanceUnit { private final String shortName; private final double kmRatio; - DistanceUnit(String longName, String shortName, double kmRatio){ - this.longName=longName; + DistanceUnit(String longName, String shortName, double kmRatio) { + this.longName = longName; this.shortName = shortName; this.kmRatio = kmRatio; } @@ -34,7 +34,7 @@ public String toString() { public String format(double distance, int i) { double result = distance * getKmRatio(); - if(i == 0){ + if (i == 0) { return "%.0f%s".formatted(result, getShortName()); } return ("%%.%df%%s".formatted(i)).formatted(result, getShortName()); diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/geo/taup/TauPTravelTable.java b/GlobalQuakeCore/src/main/java/globalquake/core/geo/taup/TauPTravelTable.java index 3d3e136bc..8fe3d9e15 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/geo/taup/TauPTravelTable.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/geo/taup/TauPTravelTable.java @@ -49,7 +49,7 @@ public TauPTravelTable() throws TauModelException, IOException { private static void fill(float[][] array, TauP_Time timeModel, String phases, double minAngle, double maxAngle) { List depths = new ArrayList<>(); - for (int depthI = 0; depthI <= (int)(TauPTravelTimeCalculator.MAX_DEPTH / TauPTravelTimeCalculator.DEPTH_RESOLUTION); depthI++) { + for (int depthI = 0; depthI <= (int) (TauPTravelTimeCalculator.MAX_DEPTH / TauPTravelTimeCalculator.DEPTH_RESOLUTION); depthI++) { double depth = depthI * TauPTravelTimeCalculator.DEPTH_RESOLUTION; depths.add(depth); } @@ -59,7 +59,7 @@ private static void fill(float[][] array, TauP_Time timeModel, String phases, do TauP_Time timeTool = new TauP_Time(timeModel.getTauModelName()); timeTool.parsePhaseList(phases); - for (int angI = (int)(minAngle / TauPTravelTimeCalculator.ANG_RESOLUTION); angI <= maxAngle / TauPTravelTimeCalculator.ANG_RESOLUTION; angI ++) { + for (int angI = (int) (minAngle / TauPTravelTimeCalculator.ANG_RESOLUTION); angI <= maxAngle / TauPTravelTimeCalculator.ANG_RESOLUTION; angI++) { double ang = angI * TauPTravelTimeCalculator.ANG_RESOLUTION; timeTool.setSourceDepth(depth); timeTool.calculate(ang); diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/geo/taup/TauPTravelTimeCalculator.java b/GlobalQuakeCore/src/main/java/globalquake/core/geo/taup/TauPTravelTimeCalculator.java index 2d1000216..455c52908 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/geo/taup/TauPTravelTimeCalculator.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/geo/taup/TauPTravelTimeCalculator.java @@ -24,17 +24,17 @@ public static TauPTravelTable getTravelTable() { public static void init() throws FatalApplicationException { try { travelTable = loadTravelTable("travel_table/travel_table.dat"); - }catch(Exception e){ + } catch (Exception e) { throw new FatalApplicationException(e); } } - public static void main(String[] args) throws Exception{ + public static void main(String[] args) throws Exception { createTravelTable(); } @SuppressWarnings("unused") - private static void createTravelTable() throws Exception{ + private static void createTravelTable() throws Exception { TauPTravelTable travelTable = new TauPTravelTable(); ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("travel_table.dat")); out.writeObject(travelTable); @@ -44,7 +44,7 @@ private static void createTravelTable() throws Exception{ @SuppressWarnings("SameParameterValue") private static TauPTravelTable loadTravelTable(String path) throws FatalIOException { var url = ClassLoader.getSystemClassLoader().getResource(path); - if(url == null){ + if (url == null) { throw new FatalIOException("Unable to load travel table!", new NullPointerException()); } @@ -52,7 +52,7 @@ private static TauPTravelTable loadTravelTable(String path) throws FatalIOExcept try { ObjectInput in = new ObjectInputStream(url.openStream()); res = (TauPTravelTable) in.readObject(); - }catch(IOException | ClassNotFoundException e){ + } catch (IOException | ClassNotFoundException e) { throw new FatalIOException("Unable to load travel table!", e); } @@ -60,24 +60,23 @@ private static TauPTravelTable loadTravelTable(String path) throws FatalIOExcept } - - public static double getPWaveTravelTime(double depth, double angle){ + public static double getPWaveTravelTime(double depth, double angle) { return interpolateWaves(travelTable.p_travel_table, TauPTravelTable.P_S_MIN_ANGLE, TauPTravelTable.P_S_MAX_ANGLE, depth, angle, false); } - public static double getPWaveTravelTimeFast(double depth, double angle){ + public static double getPWaveTravelTimeFast(double depth, double angle) { return interpolateWaves(travelTable.p_travel_table, TauPTravelTable.P_S_MIN_ANGLE, TauPTravelTable.P_S_MAX_ANGLE, depth, angle, true); } - public static double getSWaveTravelTime(double depth, double angle){ + public static double getSWaveTravelTime(double depth, double angle) { return interpolateWaves(travelTable.s_travel_table, TauPTravelTable.P_S_MIN_ANGLE, TauPTravelTable.P_S_MAX_ANGLE, depth, angle, false); } - public static double getPKIKPWaveTravelTime(double depth, double angle){ + public static double getPKIKPWaveTravelTime(double depth, double angle) { return interpolateWaves(travelTable.pkikp_travel_table, TauPTravelTable.PKIKP_MIN_ANGLE, TauPTravelTable.PKIKP_MAX_ANGLE, depth, angle, false); } - public static double getPKPWaveTravelTime(double depth, double angle){ + public static double getPKPWaveTravelTime(double depth, double angle) { return interpolateWaves(travelTable.pkp_travel_table, TauPTravelTable.PKP_MIN_ANGLE, TauPTravelTable.PKP_MAX_ANGLE, depth, angle, false); } @@ -86,17 +85,17 @@ private static double getMaxTime(float[][] table) { } public static double getPWaveTravelAngle(double depth, double timeSeconds) { - if(timeSeconds < 0 || - timeSeconds > getMaxTime(travelTable.p_travel_table)){ - return NO_ARRIVAL; + if (timeSeconds < 0 || + timeSeconds > getMaxTime(travelTable.p_travel_table)) { + return NO_ARRIVAL; } return binarySearchTime((angle) -> getPWaveTravelTime(depth, angle), timeSeconds, 1e-4, TauPTravelTable.P_S_MIN_ANGLE, TauPTravelTable.P_S_MAX_ANGLE); } public static double getSWaveTravelAngle(double depth, double timeSeconds) { - if(timeSeconds < 0 || timeSeconds > getMaxTime(travelTable.s_travel_table)){ - return NO_ARRIVAL; + if (timeSeconds < 0 || timeSeconds > getMaxTime(travelTable.s_travel_table)) { + return NO_ARRIVAL; } return binarySearchTime((angle) -> getSWaveTravelTime(depth, angle), timeSeconds, 1e-4, TauPTravelTable.P_S_MIN_ANGLE, TauPTravelTable.P_S_MAX_ANGLE); @@ -122,7 +121,7 @@ public static double binarySearchTime(Function func, double targ double mid = left + (right - left) / 2.0; midValue = func.apply(mid); - if(midValue == NO_ARRIVAL){ + if (midValue == NO_ARRIVAL) { return NO_ARRIVAL; } @@ -133,7 +132,7 @@ public static double binarySearchTime(Function func, double targ } } - if(Math.abs(target - midValue) > 0.5){ + if (Math.abs(target - midValue) > 0.5) { return NO_ARRIVAL; } @@ -144,10 +143,10 @@ public static double binarySearchTime(Function func, double targ private static double interpolateWaves(float[][] array, double minAng, double maxAng, double depth, double angle, boolean fast) { double x = (depth / MAX_DEPTH) * (array.length - 1); double y = ((angle - minAng) / (maxAng - minAng)) * (array[0].length - 1); - if(x < 0 || y < 0 || x > array.length - 1 || y > array[0].length - 1){ + if (x < 0 || y < 0 || x > array.length - 1 || y > array[0].length - 1) { return NO_ARRIVAL; } - return fast? fastbilinearInterpolation(array, x, y) : bilinearInterpolation(array, x, y); + return fast ? fastbilinearInterpolation(array, x, y) : bilinearInterpolation(array, x, y); } private static double fastbilinearInterpolation(float[][] array, double x, double y) { @@ -168,7 +167,7 @@ private static double fastbilinearInterpolation(float[][] array, double x, doubl } private static double bilinearInterpolation(float[][] array, double x, double y) { - if(x < 0 || y < 0){ + if (x < 0 || y < 0) { return NO_ARRIVAL; } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/intensity/IntensityScale.java b/GlobalQuakeCore/src/main/java/globalquake/core/intensity/IntensityScale.java index 03a438d60..eb76fc557 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/intensity/IntensityScale.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/intensity/IntensityScale.java @@ -10,15 +10,16 @@ public interface IntensityScale { List getLevels(); String getNameShort(); + @SuppressWarnings("unused") String getNameLong(); double getDarkeningFactor(); - default Level getLevel(double pga){ + default Level getLevel(double pga) { Level result = null; - for(Level level : getLevels()){ - if(pga < level.getPga()){ + for (Level level : getLevels()) { + if (pga < level.getPga()) { return result; } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/intensity/IntensityScales.java b/GlobalQuakeCore/src/main/java/globalquake/core/intensity/IntensityScales.java index 7a6cf9e8b..c214ee2cb 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/intensity/IntensityScales.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/intensity/IntensityScales.java @@ -9,7 +9,8 @@ public class IntensityScales { public static final IntensityScale MMI = new MMIIntensityScale(); public static final IntensityScale[] INTENSITY_SCALES = {MMI, SHINDO}; - public static IntensityScale getIntensityScale(){ + + public static IntensityScale getIntensityScale() { int index = Settings.intensityScaleIndex; return INTENSITY_SCALES[(index < 0 || index >= INTENSITY_SCALES.length) ? 0 : index]; } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/intensity/IntensityTable.java b/GlobalQuakeCore/src/main/java/globalquake/core/intensity/IntensityTable.java index 4eb6c5900..4f9a16736 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/intensity/IntensityTable.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/intensity/IntensityTable.java @@ -15,7 +15,7 @@ public static double getRatio(double mag, double dist) { public static double getIntensity(double mag, double dist) { double limit = 1200; - if(mag > 7.5){ + if (mag > 7.5) { limit += (mag - 7.5) * 500; } if (mag > 9) { diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/intensity/MMIIntensityScale.java b/GlobalQuakeCore/src/main/java/globalquake/core/intensity/MMIIntensityScale.java index f3a01be20..d1acf8dcd 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/intensity/MMIIntensityScale.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/intensity/MMIIntensityScale.java @@ -5,69 +5,69 @@ import java.util.List; @SuppressWarnings("unused") -public class MMIIntensityScale implements IntensityScale{ +public class MMIIntensityScale implements IntensityScale { - public static final Level I; + public static final Level I; - public static final Level II; + public static final Level II; - public static final Level III; + public static final Level III; - public static final Level IV; + public static final Level IV; - public static final Level V; + public static final Level V; - public static final Level VI; + public static final Level VI; - public static final Level VII; + public static final Level VII; - public static final Level VIII; + public static final Level VIII; - public static final Level IX; + public static final Level IX; - public static final Level X; - public static final Level XI; - public static final Level XII; - private static final List levels = new ArrayList<>(); + public static final Level X; + public static final Level XI; + public static final Level XII; + private static final List levels = new ArrayList<>(); - static { - levels.add(I = new Level("I", 0.5, new Color(170,170,170))); // 1 - levels.add(II = new Level("II", 1.0, new Color(200, 190, 240))); // 5 - levels.add(III = new Level("III", 2.1, new Color(132, 162, 232))); // 10 - levels.add(IV = new Level("IV", 5.0, new Color(130, 214, 255))); // 30 - levels.add(V = new Level("V", 11.0, new Color(85, 242, 15))); // 70 - levels.add(VI = new Level("VI", 26.0, new Color(255, 255, 0))); // 140 - levels.add(VII = new Level("VII", 60.0, new Color(255, 200, 0))); // 250 - levels.add(VIII = new Level("VIII", 140.0, new Color(255, 120, 0))); // 500 - levels.add(IX = new Level("IX", 321.8, new Color(255, 0, 0))); // 800 - levels.add(X = new Level("X", 740.0, new Color(190, 0, 0))); // 1000 - levels.add(XI = new Level("XI", 1702.0, new Color(130, 0, 0))); // 1300 - levels.add(XII = new Level("XII", 3000.0, new Color(65, 0, 0))); // 2000 - } + static { + levels.add(I = new Level("I", 0.5, new Color(170, 170, 170))); // 1 + levels.add(II = new Level("II", 1.0, new Color(200, 190, 240))); // 5 + levels.add(III = new Level("III", 2.1, new Color(132, 162, 232))); // 10 + levels.add(IV = new Level("IV", 5.0, new Color(130, 214, 255))); // 30 + levels.add(V = new Level("V", 11.0, new Color(85, 242, 15))); // 70 + levels.add(VI = new Level("VI", 26.0, new Color(255, 255, 0))); // 140 + levels.add(VII = new Level("VII", 60.0, new Color(255, 200, 0))); // 250 + levels.add(VIII = new Level("VIII", 140.0, new Color(255, 120, 0))); // 500 + levels.add(IX = new Level("IX", 321.8, new Color(255, 0, 0))); // 800 + levels.add(X = new Level("X", 740.0, new Color(190, 0, 0))); // 1000 + levels.add(XI = new Level("XI", 1702.0, new Color(130, 0, 0))); // 1300 + levels.add(XII = new Level("XII", 3000.0, new Color(65, 0, 0))); // 2000 + } - @Override - public List getLevels() { - return levels; - } + @Override + public List getLevels() { + return levels; + } - @Override - public String getNameShort() { - return "MMI"; - } + @Override + public String getNameShort() { + return "MMI"; + } - @Override - public String getNameLong() { - return "Modified Mercalli intensity scale"; - } + @Override + public String getNameLong() { + return "Modified Mercalli intensity scale"; + } - @Override - public double getDarkeningFactor() { - return 0.62; - } + @Override + public double getDarkeningFactor() { + return 0.62; + } - @Override - public String toString() { - return getNameLong(); - } + @Override + public String toString() { + return getNameLong(); + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/intensity/ShindoIntensityScale.java b/GlobalQuakeCore/src/main/java/globalquake/core/intensity/ShindoIntensityScale.java index b9b292984..e24cb35ad 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/intensity/ShindoIntensityScale.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/intensity/ShindoIntensityScale.java @@ -5,54 +5,54 @@ import java.util.List; @SuppressWarnings("unused") -public class ShindoIntensityScale implements IntensityScale{ - - public static final Level ICHI; - public static final Level NI; - public static final Level SAN; - public static final Level YON; - public static final Level GO_JAKU; - public static final Level GO_KYOU; - public static final Level ROKU_JAKU; - public static final Level ROKU_KYOU; - public static final Level NANA; - private static final List levels = new ArrayList<>(); - - static { - levels.add(ICHI = new Level("1", 0.8, new Color(120, 135, 135))); - levels.add(NI = new Level("2", 2.5, new Color(20, 135, 205))); - levels.add(SAN = new Level("3", 8, new Color(19, 154, 76))); - levels.add(YON = new Level("4", 25, new Color(220, 165, 0))); - levels.add(GO_JAKU = new Level("5","-", 80, new Color(241, 138, 46))); - levels.add(GO_KYOU = new Level("5","+", 140, new Color(216, 78, 14))); - levels.add(ROKU_JAKU = new Level("6","-", 250, new Color(235, 26, 0))); - levels.add(ROKU_KYOU = new Level("6","+", 315, new Color(165, 2, 7))); - levels.add(NANA = new Level("7", 400, new Color(150, 0, 150))); - } - - @Override - public List getLevels() { - return levels; - } - - @Override - public String getNameShort() { - return "Shindo"; - } - - @Override - public String getNameLong() { - return "Shindo intensity scale"; - } - - @Override - public double getDarkeningFactor() { - return 0.9; - } - - - @Override - public String toString() { - return getNameLong(); - } +public class ShindoIntensityScale implements IntensityScale { + + public static final Level ICHI; + public static final Level NI; + public static final Level SAN; + public static final Level YON; + public static final Level GO_JAKU; + public static final Level GO_KYOU; + public static final Level ROKU_JAKU; + public static final Level ROKU_KYOU; + public static final Level NANA; + private static final List levels = new ArrayList<>(); + + static { + levels.add(ICHI = new Level("1", 0.8, new Color(120, 135, 135))); + levels.add(NI = new Level("2", 2.5, new Color(20, 135, 205))); + levels.add(SAN = new Level("3", 8, new Color(19, 154, 76))); + levels.add(YON = new Level("4", 25, new Color(220, 165, 0))); + levels.add(GO_JAKU = new Level("5", "-", 80, new Color(241, 138, 46))); + levels.add(GO_KYOU = new Level("5", "+", 140, new Color(216, 78, 14))); + levels.add(ROKU_JAKU = new Level("6", "-", 250, new Color(235, 26, 0))); + levels.add(ROKU_KYOU = new Level("6", "+", 315, new Color(165, 2, 7))); + levels.add(NANA = new Level("7", 400, new Color(150, 0, 150))); + } + + @Override + public List getLevels() { + return levels; + } + + @Override + public String getNameShort() { + return "Shindo"; + } + + @Override + public String getNameLong() { + return "Shindo intensity scale"; + } + + @Override + public double getDarkeningFactor() { + return 0.9; + } + + + @Override + public String toString() { + return getNameLong(); + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/lab/GlobalQuakeLab.java b/GlobalQuakeCore/src/main/java/globalquake/core/lab/GlobalQuakeLab.java index 07d257859..8f1d704d9 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/lab/GlobalQuakeLab.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/lab/GlobalQuakeLab.java @@ -58,7 +58,7 @@ public static void traverseDirectories(File folder) { if (file.isDirectory()) { System.err.println(file.getAbsolutePath()); traverseDirectories(file); // Recursive call for subdirectory - } else if(file.getName().endsWith(".dat")){ + } else if (file.getName().endsWith(".dat")) { tryFile(file, folder); // Call tryFile for each file } } catch (Exception e) { @@ -92,7 +92,7 @@ private static void inspectArchivedQuake(ArchivedQuake archivedQuake, File folde private static void residualsInspection(ArchivedQuake archivedQuake, File folder) throws IOException { long origin = archivedQuake.getOrigin(); - String filePath = new File(folder,"residuals.csv").getAbsolutePath(); + String filePath = new File(folder, "residuals.csv").getAbsolutePath(); double depth = archivedQuake.getDepth(); @@ -140,7 +140,7 @@ private static void depthInspection(ArchivedQuake archivedQuake, File folder) { List exactPickedEvents = createListOfExactPickedEvents(pickedEvents); calculateDistances(exactPickedEvents, archivedQuake.getLat(), archivedQuake.getLon()); - String filePath = new File(folder,"heuristic.csv").getAbsolutePath(); + String filePath = new File(folder, "heuristic.csv").getAbsolutePath(); try (FileWriter writer = new FileWriter(filePath)) { writer.write("depth,err,correct,heuristic\n"); diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/regions/GQPolygon.java b/GlobalQuakeCore/src/main/java/globalquake/core/regions/GQPolygon.java index 981600a77..e045c339f 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/regions/GQPolygon.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/regions/GQPolygon.java @@ -10,13 +10,13 @@ public class GQPolygon { private final float[] lats; private final float[] lons; - public GQPolygon(org.geojson.Polygon polygon){ + public GQPolygon(org.geojson.Polygon polygon) { List list = polygon.getCoordinates().get(0); this.size = list.size(); lats = new float[size]; lons = new float[size]; int i = 0; - for(LngLatAlt lngLatAlt : list){ + for (LngLatAlt lngLatAlt : list) { lats[i] = (float) lngLatAlt.getLatitude(); lons[i] = (float) lngLatAlt.getLongitude(); i++; diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/regions/RegionUpdater.java b/GlobalQuakeCore/src/main/java/globalquake/core/regions/RegionUpdater.java index d3d9aba98..7385f0904 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/regions/RegionUpdater.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/regions/RegionUpdater.java @@ -8,7 +8,7 @@ public class RegionUpdater { public RegionUpdater(Regional target) { this.target = target; - if(target.getRegion() == null) { + if (target.getRegion() == null) { target.setRegion(DEFAULT_REGION); } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/regions/Regions.java b/GlobalQuakeCore/src/main/java/globalquake/core/regions/Regions.java index 08653d5f2..88e3d390d 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/regions/Regions.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/regions/Regions.java @@ -72,7 +72,7 @@ public static void init() throws IOException { parseGeoJson("polygons_converted/italy_provinces.geojson", raw_polygonsIT, regionsIT, NONE); parseGeoJson("polygons_converted/region_dataset.geojson", null, regionSearchHD, NONE); - for(List list : List.of(regionsUS, regionsAK, regionsJP, regionsNZ, regionsHW, regionsIT)){ + for (List list : List.of(regionsUS, regionsAK, regionsJP, regionsNZ, regionsHW, regionsIT)) { regionSearchHD.addAll(list); } @@ -83,11 +83,11 @@ public static void init() throws IOException { private static void loadLookupTable() throws IOException { shorelineLookup = LookupTableIO.importLookupTableFromFile(); - if(shorelineLookup == null){ + if (shorelineLookup == null) { System.err.println("No lookup table found! Generating..."); double start = System.currentTimeMillis(); boolean exportResult = LookupTableIO.exportLookupTableToFile(); - System.out.println("Generating took: " + (System.currentTimeMillis() - start)/1000 + "s"); + System.out.println("Generating took: " + (System.currentTimeMillis() - start) / 1000 + "s"); if (exportResult) { System.out.println("Lookup table successfully generated! Loading " + shorelineLookup.size() + " items."); @@ -130,13 +130,13 @@ public static double getOceanDistance(double lat, double lon, boolean gcd, doubl double closestDistance = Double.MAX_VALUE; Point2D.Double point = new Point2D.Double(lon, lat); for (Region reg : regionsUHD) { - for(Path2D.Float path : reg.paths()){ - if(path.contains(point)){ + for (Path2D.Float path : reg.paths()) { + if (path.contains(point)) { return depth; } } for (GQPolygon polygon : reg.raws()) { - for(int i = 0; i < polygon.getSize(); i++) { + for (int i = 0; i < polygon.getSize(); i++) { double pLat = polygon.getLats()[i]; double pLon = polygon.getLons()[i]; double dist = gcd ? GeoUtils.greatCircleDistance(pLat, pLon, lat, lon) : @@ -162,7 +162,7 @@ private static boolean isOcean(double lat, double lng, List regions) { int i = 0; for (Path2D.Float path : reg.paths()) { if (reg.bounds().get(i).contains(point)) { - if(path.contains(point)) { + if (path.contains(point)) { return false; } } @@ -173,13 +173,13 @@ private static boolean isOcean(double lat, double lng, List regions) { return true; } - public static String getName(double lat, double lon, List regions){ + public static String getName(double lat, double lon, List regions) { Point2D.Double point = new Point2D.Double(lon, lat); for (Region reg : regions) { int i = 0; for (Path2D.Float path : reg.paths()) { if (reg.bounds().get(i).contains(point)) { - if(path.contains(point)) { + if (path.contains(point)) { return reg.name(); } } @@ -190,10 +190,10 @@ public static String getName(double lat, double lon, List regions){ return null; } - public static String getExtendedName(double lat, double lon){ + public static String getExtendedName(double lat, double lon) { String localName = getName(lat, lon, regionSearchHD); - if(localName != null){ + if (localName != null) { return localName; } @@ -202,7 +202,7 @@ public static String getExtendedName(double lat, double lon){ public static String getRegion(double lat, double lon) { String extendedName = getExtendedName(lat, lon); - if(extendedName != null){ + if (extendedName != null) { return extendedName; } @@ -212,7 +212,7 @@ public static String getRegion(double lat, double lon) { double closestDistance = Double.MAX_VALUE; for (Region reg : regionsMD) { for (GQPolygon polygon : reg.raws()) { - for(int i = 0; i < polygon.getSize(); i++) { + for (int i = 0; i < polygon.getSize(); i++) { float pLat = polygon.getLats()[i]; float pLon = polygon.getLons()[i]; double dist = GeoUtils.greatCircleDistance(pLat, pLon, lat, lon); @@ -228,9 +228,9 @@ public static String getRegion(double lat, double lon) { String closestNameExtended = closest; - if(closestDistance != Double.MAX_VALUE) { + if (closestDistance != Double.MAX_VALUE) { String closestExtended = getExtendedName(closestLat, closestLon); - if(closestExtended != null){ + if (closestExtended != null) { closestNameExtended = closestExtended; } } @@ -249,14 +249,14 @@ public static String getRegion(double lat, double lon) { public static double getShorelineDistance(double lat, double lon) { String extendedName = getExtendedName(lat, lon); - if(extendedName != null){ + if (extendedName != null) { return 0; } double closestDistance = Double.MAX_VALUE; for (Region reg : regionsMD) { for (GQPolygon polygon : reg.raws()) { - for(int i = 0; i < polygon.getSize(); i++) { + for (int i = 0; i < polygon.getSize(); i++) { float pLat = polygon.getLats()[i]; float pLon = polygon.getLons()[i]; double dist = GeoUtils.greatCircleDistance(pLat, pLon, lat, lon); @@ -334,14 +334,14 @@ public static double interpolate( double lat, double lon, HashMap lookupTable ) { - if(lookupTable.containsKey(String.format("%.6f,%.6f", lat, lon))){ + if (lookupTable.containsKey(String.format("%.6f,%.6f", lat, lon))) { return lookupTable.get(String.format("%.6f,%.6f", lat, lon)); } double tmp = lat - Math.floor(lat); double x0, x1, y0, y1; - if(tmp < 0.5) { + if (tmp < 0.5) { x0 = (int) Math.floor(lat); x1 = x0 + 0.5; } else { @@ -351,7 +351,7 @@ public static double interpolate( tmp = lon - Math.floor(lon); - if(tmp < 0.5) { + if (tmp < 0.5) { y0 = (int) Math.floor(lon); y1 = y0 + 0.5; } else { @@ -364,26 +364,26 @@ public static double interpolate( return -1; } - String first = String.format("%.6f,%.6f", x0, y0); - String second = String.format("%.6f,%.6f", x0, y1); - String third = String.format("%.6f,%.6f", x1, y0); - String fourth = String.format("%.6f,%.6f", x1, y1); + String first = String.format("%.6f,%.6f", x0, y0); + String second = String.format("%.6f,%.6f", x0, y1); + String third = String.format("%.6f,%.6f", x1, y0); + String fourth = String.format("%.6f,%.6f", x1, y1); double f00 = lookupTable.getOrDefault(first, (double) 0); double f01 = lookupTable.getOrDefault(second, (double) 0); double f10 = lookupTable.getOrDefault(third, (double) 0); double f11 = lookupTable.getOrDefault(fourth, (double) 0); - double r1 = ((x1 - lat)/(x1 - x0) * f00) + ((lat - x0)/(x1 - x0) * f10); - double r2 = ((x1 - lat)/(x1 - x0) * f01) + ((lat - x0)/(x1 - x0) * f11); + double r1 = ((x1 - lat) / (x1 - x0) * f00) + ((lat - x0) / (x1 - x0) * f10); + double r2 = ((x1 - lat) / (x1 - x0) * f01) + ((lat - x0) / (x1 - x0) * f11); - double result = ((y1 - lon)/(y1 - y0) * r1) + ((lon - y0)/(y1 - y0) * r2); + double result = ((y1 - lon) / (y1 - y0) * r1) + ((lon - y0) / (y1 - y0) * r2); return Double.isNaN(result) ? 0 : result; } - public static void main(String[] args) throws Exception{ + public static void main(String[] args) throws Exception { System.out.println("INIT"); init(); @@ -395,7 +395,7 @@ public static void main(String[] args) throws Exception{ assert shorelineLookup != null; double interpolation = interpolate(lat, lon, shorelineLookup); - if (Double.isNaN(interpolation) || interpolation == -1){ + if (Double.isNaN(interpolation) || interpolation == -1) { System.err.println("Values couldn't be interpolated, using legacy method..."); double shorelineDistance = getShorelineDistance(lat, lon); shorelineLookup.putIfAbsent(String.format("%.6f,%.6f", lat, lon), shorelineDistance); @@ -405,7 +405,7 @@ public static void main(String[] args) throws Exception{ } boolean exportResult = LookupTableIO.exportLookupTableToFile(shorelineLookup); - if(exportResult){ + if (exportResult) { System.out.println("Lookup Table was successfully exported."); } else { System.err.println("Lookup Table export failed"); @@ -461,9 +461,9 @@ public static void parseGeoJson(String path, List raw, List r private static String fetchName(Feature f) { String name; - for(String str : NAME_NAMES){ + for (String str : NAME_NAMES) { name = f.getProperty(str); - if(name != null){ + if (name != null) { return name; } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/report/DistanceIntensityRecord.java b/GlobalQuakeCore/src/main/java/globalquake/core/report/DistanceIntensityRecord.java index b74508a9a..c89ab59df 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/report/DistanceIntensityRecord.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/report/DistanceIntensityRecord.java @@ -1,13 +1,13 @@ package globalquake.core.report; -public class DistanceIntensityRecord{ - final double mag; - final double dist; - final double intensity; - - public DistanceIntensityRecord(double mag, double dist, double intensity) { - this.mag=mag; - this.dist=dist; - this.intensity=intensity; - } +public class DistanceIntensityRecord { + final double mag; + final double dist; + final double intensity; + + public DistanceIntensityRecord(double mag, double dist, double intensity) { + this.mag = mag; + this.dist = dist; + this.intensity = intensity; + } } \ No newline at end of file diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/report/IntensityGraphs.java b/GlobalQuakeCore/src/main/java/globalquake/core/report/IntensityGraphs.java index ed1ee3d11..d9d5bf9d6 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/report/IntensityGraphs.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/report/IntensityGraphs.java @@ -67,7 +67,6 @@ public static void main(String[] args) throws IOException { recs.add(new DistanceIntensityRecord(3.0, 700, 1e1)); - drawGraph(g, w, h, recs, MagnitudeType.DEFAULT, false); ImageIO.write(img, "PNG", new File("aaa29.png")); @@ -166,7 +165,7 @@ public static void drawGraph(Graphics2D g, int w, int h, List activeReaders = new ConcurrentLinkedQueue<>(); - - public static void main(String[] args) throws Exception{ - SeedlinkReader reader = new SeedlinkReader("rtserve.iris.washington.edu", 18000); - reader.selectData("AK", "D25K", List.of("BHZ")); - reader.endHandshake(); - - SortedSet set = new TreeSet<>(Comparator.comparing(dataRecord -> dataRecord.getStartBtime().toInstant().toEpochMilli())); - - while(reader.hasNext() && set.size() < 10){ - SeedlinkPacket pack = reader.readPacket(); - DataRecord dataRecord = pack.getMiniSeed(); - System.out.println(pack.getMiniSeed().getStartTime()+" - "+pack.getMiniSeed().getLastSampleTime()+" x "+pack.getMiniSeed().getEndTime()+" @ "+pack.getMiniSeed().getSampleRate()); - System.out.println(pack.getMiniSeed().getControlHeader().getSequenceNum()); - if(!set.add(dataRecord)){ - System.out.println("ERR ALREADY CONTAINS"); - } - } - - reader.close(); - for(DataRecord dataRecord : set){ - System.err.println(dataRecord.getStartTime()+" - "+dataRecord.getLastSampleTime()+" x "+dataRecord.getEndTime()+" @ "+dataRecord.getSampleRate()); - System.err.println(dataRecord.oneLineSummary()); - } - } - - public void run() { - createCache(); - seedlinkReaderService = Executors.newCachedThreadPool(); - GlobalQuake.instance.getStationDatabaseManager().getStationDatabase().getDatabaseReadLock().lock(); - - try{ - GlobalQuake.instance.getStationDatabaseManager().getStationDatabase().getSeedlinkNetworks().forEach( - seedlinkServer -> seedlinkReaderService.submit(() -> runSeedlinkThread(seedlinkServer, RECONNECT_DELAY))); - } finally { - GlobalQuake.instance.getStationDatabaseManager().getStationDatabase().getDatabaseReadLock().unlock(); - } - } - - private final Map stationCache = new HashMap<>(); - - private void createCache() { - for (AbstractStation s : GlobalQuake.instance.getStationManager().getStations()) { - if (s instanceof GlobalStation) { - stationCache.put("%s %s".formatted(s.getNetworkCode(), s.getStationCode()), (GlobalStation) s); - } - } - } - private void runSeedlinkThread(SeedlinkNetwork seedlinkNetwork, int reconnectDelay) { - seedlinkNetwork.status = SeedlinkStatus.CONNECTING; - seedlinkNetwork.connectedStations = 0; - - SeedlinkReader reader = null; - try { - Logger.info("Connecting to seedlink server \"" + seedlinkNetwork.getName() + "\""); - reader = new SeedlinkReader(seedlinkNetwork.getHost(), seedlinkNetwork.getPort(), SEEDLINK_TIMEOUT, false, SEEDLINK_TIMEOUT); - activeReaders.add(reader); - - reader.sendHello(); - - reconnectDelay = RECONNECT_DELAY; // if connect succeeded then reset the delay - - int errors = 0; - - for (AbstractStation station : GlobalQuake.instance.getStationManager().getStations()) { - if (station.getSeedlinkNetwork() != null && station.getSeedlinkNetwork().equals(seedlinkNetwork)) { - Logger.trace("Connecting to %s %s %s %s [%s]".formatted(station.getStationCode(), station.getNetworkCode(), station.getChannelName(), station.getLocationCode(), seedlinkNetwork.getName())); - try { - reader.selectData(station.getNetworkCode(), station.getStationCode(), List.of("%s%s".formatted(station.getLocationCode(), - station.getChannelName()))); - seedlinkNetwork.connectedStations++; - }catch(SeedlinkException seedlinkException){ - Logger.warn("Unable to connect to %s %s %s %s [%s]!".formatted(station.getStationCode(), station.getNetworkCode(), station.getChannelName(), station.getLocationCode(), seedlinkNetwork.getName())); - errors++; - if(errors > seedlinkNetwork.selectedStations * 0.1){ - Logger.warn("Too many errors in seedlink network %s, resetting!".formatted(seedlinkNetwork.getName())); - throw seedlinkException; - } - } - } - } - - if(seedlinkNetwork.connectedStations == 0){ - Logger.info("No stations connected to "+seedlinkNetwork.getName()); - seedlinkNetwork.status = SeedlinkStatus.DISCONNECTED; - return; - } - - reader.endHandshake(); - seedlinkNetwork.status = SeedlinkStatus.RUNNING; - - while (reader.hasNext()) { - SeedlinkPacket slp = reader.readPacket(); - try { - newPacket(slp.getMiniSeed()); - } catch(SocketException | SeedFormatException se){ - Logger.trace(se); - } catch (Exception e) { - Logger.error(e); - } - } - - reader.close(); - } catch (Exception e) { - Logger.warn("Seedlink reader failed for seedlink `%s`: %s".formatted(seedlinkNetwork.getName(), e.getMessage())); - } finally { - if(reader != null){ - try { - reader.close(); - } catch (Exception ex) { - Logger.error(ex); - } - activeReaders.remove(reader); - } - } - - seedlinkNetwork.status = SeedlinkStatus.DISCONNECTED; - seedlinkNetwork.connectedStations = 0; - Logger.warn("%s Disconnected, Reconnecting after %d seconds...".formatted(seedlinkNetwork.getName(), reconnectDelay)); - - try { - Thread.sleep(reconnectDelay * 1000L); - if(reconnectDelay < 60 * 5) { - reconnectDelay *= 2; - } - } catch (InterruptedException ignored) { - Logger.warn("Seedlink reader thread for %s interrupted".formatted(seedlinkNetwork.getName())); - return; - } - - int finalReconnectDelay = reconnectDelay; - seedlinkReaderService.submit(() -> runSeedlinkThread(seedlinkNetwork, finalReconnectDelay)); - } - - private void newPacket(DataRecord dr) { - if (lastData == null || dr.getLastSampleBtime().toInstant().isAfter(lastData)) { - lastData = dr.getLastSampleBtime().toInstant(); - } - - String network = dr.getHeader().getNetworkCode().replaceAll(" ", ""); - String station = dr.getHeader().getStationIdentifier().replaceAll(" ", ""); - var globalStation = stationCache.get("%s %s".formatted(network, station)); - if(globalStation == null){ - Logger.trace("Seedlink sent data for %s %s, but that was never selected!".formatted(network, station)); - }else { - globalStation.addRecord(dr); - } - } - - public void stop() { - if(seedlinkReaderService != null) { - seedlinkReaderService.shutdownNow(); + protected static final int RECONNECT_DELAY = 10; + private static final int SEEDLINK_TIMEOUT = 90; + private Instant lastData; + + private ExecutorService seedlinkReaderService; + + private final Queue activeReaders = new ConcurrentLinkedQueue<>(); + + public static void main(String[] args) throws Exception { + SeedlinkReader reader = new SeedlinkReader("rtserve.iris.washington.edu", 18000); + reader.selectData("AK", "D25K", List.of("BHZ")); + reader.endHandshake(); + + SortedSet set = new TreeSet<>(Comparator.comparing(dataRecord -> dataRecord.getStartBtime().toInstant().toEpochMilli())); + + while (reader.hasNext() && set.size() < 10) { + SeedlinkPacket pack = reader.readPacket(); + DataRecord dataRecord = pack.getMiniSeed(); + System.out.println(pack.getMiniSeed().getStartTime() + " - " + pack.getMiniSeed().getLastSampleTime() + " x " + pack.getMiniSeed().getEndTime() + " @ " + pack.getMiniSeed().getSampleRate()); + System.out.println(pack.getMiniSeed().getControlHeader().getSequenceNum()); + if (!set.add(dataRecord)) { + System.out.println("ERR ALREADY CONTAINS"); + } + } + + reader.close(); + for (DataRecord dataRecord : set) { + System.err.println(dataRecord.getStartTime() + " - " + dataRecord.getLastSampleTime() + " x " + dataRecord.getEndTime() + " @ " + dataRecord.getSampleRate()); + System.err.println(dataRecord.oneLineSummary()); + } + } + + public void run() { + createCache(); + seedlinkReaderService = Executors.newCachedThreadPool(); + GlobalQuake.instance.getStationDatabaseManager().getStationDatabase().getDatabaseReadLock().lock(); + + try { + GlobalQuake.instance.getStationDatabaseManager().getStationDatabase().getSeedlinkNetworks().forEach( + seedlinkServer -> seedlinkReaderService.submit(() -> runSeedlinkThread(seedlinkServer, RECONNECT_DELAY))); + } finally { + GlobalQuake.instance.getStationDatabaseManager().getStationDatabase().getDatabaseReadLock().unlock(); + } + } + + private final Map stationCache = new HashMap<>(); + + private void createCache() { + for (AbstractStation s : GlobalQuake.instance.getStationManager().getStations()) { + if (s instanceof GlobalStation) { + stationCache.put("%s %s".formatted(s.getNetworkCode(), s.getStationCode()), (GlobalStation) s); + } + } + } + + private void runSeedlinkThread(SeedlinkNetwork seedlinkNetwork, int reconnectDelay) { + seedlinkNetwork.status = SeedlinkStatus.CONNECTING; + seedlinkNetwork.connectedStations = 0; + + SeedlinkReader reader = null; + try { + Logger.info("Connecting to seedlink server \"" + seedlinkNetwork.getName() + "\""); + reader = new SeedlinkReader(seedlinkNetwork.getHost(), seedlinkNetwork.getPort(), SEEDLINK_TIMEOUT, false, SEEDLINK_TIMEOUT); + activeReaders.add(reader); + + reader.sendHello(); + + reconnectDelay = RECONNECT_DELAY; // if connect succeeded then reset the delay + + int errors = 0; + + for (AbstractStation station : GlobalQuake.instance.getStationManager().getStations()) { + if (station.getSeedlinkNetwork() != null && station.getSeedlinkNetwork().equals(seedlinkNetwork)) { + Logger.trace("Connecting to %s %s %s %s [%s]".formatted(station.getStationCode(), station.getNetworkCode(), station.getChannelName(), station.getLocationCode(), seedlinkNetwork.getName())); + try { + reader.selectData(station.getNetworkCode(), station.getStationCode(), List.of("%s%s".formatted(station.getLocationCode(), + station.getChannelName()))); + seedlinkNetwork.connectedStations++; + } catch (SeedlinkException seedlinkException) { + Logger.warn("Unable to connect to %s %s %s %s [%s]!".formatted(station.getStationCode(), station.getNetworkCode(), station.getChannelName(), station.getLocationCode(), seedlinkNetwork.getName())); + errors++; + if (errors > seedlinkNetwork.selectedStations * 0.1) { + Logger.warn("Too many errors in seedlink network %s, resetting!".formatted(seedlinkNetwork.getName())); + throw seedlinkException; + } + } + } + } + + if (seedlinkNetwork.connectedStations == 0) { + Logger.info("No stations connected to " + seedlinkNetwork.getName()); + seedlinkNetwork.status = SeedlinkStatus.DISCONNECTED; + return; + } + + reader.endHandshake(); + seedlinkNetwork.status = SeedlinkStatus.RUNNING; + + while (reader.hasNext()) { + SeedlinkPacket slp = reader.readPacket(); + try { + newPacket(slp.getMiniSeed()); + } catch (SocketException | SeedFormatException se) { + Logger.trace(se); + } catch (Exception e) { + Logger.error(e); + } + } + + reader.close(); + } catch (Exception e) { + Logger.warn("Seedlink reader failed for seedlink `%s`: %s".formatted(seedlinkNetwork.getName(), e.getMessage())); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (Exception ex) { + Logger.error(ex); + } + activeReaders.remove(reader); + } + } + + seedlinkNetwork.status = SeedlinkStatus.DISCONNECTED; + seedlinkNetwork.connectedStations = 0; + Logger.warn("%s Disconnected, Reconnecting after %d seconds...".formatted(seedlinkNetwork.getName(), reconnectDelay)); + + try { + Thread.sleep(reconnectDelay * 1000L); + if (reconnectDelay < 60 * 5) { + reconnectDelay *= 2; + } + } catch (InterruptedException ignored) { + Logger.warn("Seedlink reader thread for %s interrupted".formatted(seedlinkNetwork.getName())); + return; + } + + int finalReconnectDelay = reconnectDelay; + seedlinkReaderService.submit(() -> runSeedlinkThread(seedlinkNetwork, finalReconnectDelay)); + } + + private void newPacket(DataRecord dr) { + if (lastData == null || dr.getLastSampleBtime().toInstant().isAfter(lastData)) { + lastData = dr.getLastSampleBtime().toInstant(); + } + + String network = dr.getHeader().getNetworkCode().replaceAll(" ", ""); + String station = dr.getHeader().getStationIdentifier().replaceAll(" ", ""); + var globalStation = stationCache.get("%s %s".formatted(network, station)); + if (globalStation == null) { + Logger.trace("Seedlink sent data for %s %s, but that was never selected!".formatted(network, station)); + } else { + globalStation.addRecord(dr); + } + } + + public void stop() { + if (seedlinkReaderService != null) { + seedlinkReaderService.shutdownNow(); for (Iterator iterator = activeReaders.iterator(); iterator.hasNext(); ) { SeedlinkReader reader = iterator.next(); reader.close(); - iterator.remove(); - } - try { - if(!seedlinkReaderService.awaitTermination(10, TimeUnit.SECONDS)){ - Logger.error("Unable to terminate seedlinkReaderService!"); - } - } catch (InterruptedException e) { - Logger.error(e); - } - } - stationCache.clear(); - } + iterator.remove(); + } + try { + if (!seedlinkReaderService.awaitTermination(10, TimeUnit.SECONDS)) { + Logger.error("Unable to terminate seedlinkReaderService!"); + } + } catch (InterruptedException e) { + Logger.error(e); + } + } + stationCache.clear(); + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/station/AbstractStation.java b/GlobalQuakeCore/src/main/java/globalquake/core/station/AbstractStation.java index f34f1b3c7..849e80fe4 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/station/AbstractStation.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/station/AbstractStation.java @@ -14,200 +14,207 @@ public abstract class AbstractStation { - public static final long INTERVAL_STORAGE_TIME = 30 * 60 * 1000; - public static final long INTERVAL_MAX_GAP = 5 * 1000; - - private static final int RATIO_HISTORY_SECONDS = 60; - private final String networkCode; - private final String stationCode; - private final String channelName; - private final String locationCode; - private final double lat; - private final double lon; - private final double alt; - private final BetterAnalysis analysis; - private final int id; - private final SeedlinkNetwork seedlinkNetwork; - - private final Deque ratioHistory = new LinkedBlockingDeque<>(); - private final double sensitivity; - public boolean disabled = false; - public double _lastRenderSize; + public static final long INTERVAL_STORAGE_TIME = 30 * 60 * 1000; + public static final long INTERVAL_MAX_GAP = 5 * 1000; + + private static final int RATIO_HISTORY_SECONDS = 60; + private final String networkCode; + private final String stationCode; + private final String channelName; + private final String locationCode; + private final double lat; + private final double lon; + private final double alt; + private final BetterAnalysis analysis; + private final int id; + private final SeedlinkNetwork seedlinkNetwork; + + private final Deque ratioHistory = new LinkedBlockingDeque<>(); + private final double sensitivity; + public boolean disabled = false; + public double _lastRenderSize; private Collection nearbyStations; - private final Deque intervals = new ConcurrentLinkedDeque<>(); - - public AbstractStation(String networkCode, String stationCode, String channelName, - String locationCode, double lat, double lon, double alt, - int id, SeedlinkNetwork seedlinkNetwork, double sensitivity) { - this.networkCode = networkCode; - this.stationCode = stationCode; - this.channelName = channelName; - this.locationCode = locationCode; - this.lat = lat; - this.lon = lon; - this.alt = alt; - this.analysis = new BetterAnalysis(this); - this.id = id; - this.seedlinkNetwork = seedlinkNetwork; - this.sensitivity = sensitivity; - } - - public StationState getStateAt(long time) { - for(StationInterval interval : intervals) { - if(time >= interval.getStart() && time < interval.getEnd()){ - return interval.getState(); - } - } - return StationState.UNKNOWN; - } - - public Event getEventAt(long time, long tolerance){ - if(getAnalysis() == null){ - return null; - } - - for(Event event : getAnalysis().getDetectedEvents()){ - if(!event.isValid()){ - continue; - } - if(time >= event.getpWave() - tolerance && (!event.hasEnded() || time < event.getEnd() - tolerance)){ - return event; - } - } - - return null; - } - - public void reportState(StationState state, long time) { - while(intervals.peekFirst() != null && time - intervals.peekFirst().getEnd() > INTERVAL_STORAGE_TIME){ - intervals.removeFirst(); - } - StationInterval lastInterval = getIntervals().peekLast(); - if(lastInterval == null){ - getIntervals().add(new StationInterval(time, time, state)); - return; - } - - if(time - lastInterval.getEnd() > INTERVAL_MAX_GAP){ - getIntervals().add(new StationInterval(time, time, state)); - return; - } - - lastInterval.setEnd(time); - - if(lastInterval.getState() != state){ - getIntervals().add(new StationInterval(time, time, state)); - } - } - - public Deque getIntervals() { - return intervals; - } - - public double getAlt() { - return alt; - } - - public String getChannelName() { - return channelName; - } - - public double getLatitude() { - return lat; - } - - public String getLocationCode() { - return locationCode; - } - - public double getLongitude() { - return lon; - } - - public String getNetworkCode() { - return networkCode; - } - - public String getStationCode() { - return stationCode; - } - - public Analysis getAnalysis() { - return analysis; - } - - public boolean hasData() { - return getDelayMS() != -1 && getDelayMS() < 5 * 60 * 1000; - } - - public boolean hasDisplayableData() { return false; } - - public boolean isInEventMode() {return false;} - - public long getDelayMS() { return 0;} + private final Deque intervals = new ConcurrentLinkedDeque<>(); + + public AbstractStation(String networkCode, String stationCode, String channelName, + String locationCode, double lat, double lon, double alt, + int id, SeedlinkNetwork seedlinkNetwork, double sensitivity) { + this.networkCode = networkCode; + this.stationCode = stationCode; + this.channelName = channelName; + this.locationCode = locationCode; + this.lat = lat; + this.lon = lon; + this.alt = alt; + this.analysis = new BetterAnalysis(this); + this.id = id; + this.seedlinkNetwork = seedlinkNetwork; + this.sensitivity = sensitivity; + } + + public StationState getStateAt(long time) { + for (StationInterval interval : intervals) { + if (time >= interval.getStart() && time < interval.getEnd()) { + return interval.getState(); + } + } + return StationState.UNKNOWN; + } + + public Event getEventAt(long time, long tolerance) { + if (getAnalysis() == null) { + return null; + } + + for (Event event : getAnalysis().getDetectedEvents()) { + if (!event.isValid()) { + continue; + } + if (time >= event.getpWave() - tolerance && (!event.hasEnded() || time < event.getEnd() - tolerance)) { + return event; + } + } + + return null; + } + + public void reportState(StationState state, long time) { + while (intervals.peekFirst() != null && time - intervals.peekFirst().getEnd() > INTERVAL_STORAGE_TIME) { + intervals.removeFirst(); + } + StationInterval lastInterval = getIntervals().peekLast(); + if (lastInterval == null) { + getIntervals().add(new StationInterval(time, time, state)); + return; + } + + if (time - lastInterval.getEnd() > INTERVAL_MAX_GAP) { + getIntervals().add(new StationInterval(time, time, state)); + return; + } + + lastInterval.setEnd(time); + + if (lastInterval.getState() != state) { + getIntervals().add(new StationInterval(time, time, state)); + } + } + + public Deque getIntervals() { + return intervals; + } + + public double getAlt() { + return alt; + } + + public String getChannelName() { + return channelName; + } + + public double getLatitude() { + return lat; + } + + public String getLocationCode() { + return locationCode; + } + + public double getLongitude() { + return lon; + } + + public String getNetworkCode() { + return networkCode; + } + + public String getStationCode() { + return stationCode; + } + + public Analysis getAnalysis() { + return analysis; + } + + public boolean hasData() { + return getDelayMS() != -1 && getDelayMS() < 5 * 60 * 1000; + } + + public boolean hasDisplayableData() { + return false; + } + + public boolean isInEventMode() { + return false; + } + + public long getDelayMS() { + return 0; + } public void second(long time) { - if (getAnalysis()._maxRatio > 0) { - ratioHistory.add(Settings.debugSendPGV && isSensitivityValid() ? getAnalysis()._maxVelocity : getAnalysis()._maxRatio); - getAnalysis()._maxRatioReset = true; + if (getAnalysis()._maxRatio > 0) { + ratioHistory.add(Settings.debugSendPGV && isSensitivityValid() ? getAnalysis()._maxVelocity : getAnalysis()._maxRatio); + getAnalysis()._maxRatioReset = true; - if (ratioHistory.size() >= RATIO_HISTORY_SECONDS) { - ratioHistory.remove(); - } - } + if (ratioHistory.size() >= RATIO_HISTORY_SECONDS) { + ratioHistory.remove(); + } + } - getAnalysis().second(time); - } + getAnalysis().second(time); + } - public double getMaxRatio60S() { - var opt = ratioHistory.stream().max(Double::compareTo); - return opt.orElse(0.0); - } + public double getMaxRatio60S() { + var opt = ratioHistory.stream().max(Double::compareTo); + return opt.orElse(0.0); + } - public void reset() { - ratioHistory.clear(); - } + public void reset() { + ratioHistory.clear(); + } - public int getId() { - return id; - } + public int getId() { + return id; + } - public void setNearbyStations(Collection nearbyStations) { - this.nearbyStations = nearbyStations; - } + public void setNearbyStations(Collection nearbyStations) { + this.nearbyStations = nearbyStations; + } - public Collection getNearbyStations() { - return nearbyStations; - } + public Collection getNearbyStations() { + return nearbyStations; + } - public void analyse() {} + public void analyse() { + } public SeedlinkNetwork getSeedlinkNetwork() { - return seedlinkNetwork; - } + return seedlinkNetwork; + } - @Override - public String toString() { - return getIdentifier(); - } + @Override + public String toString() { + return getIdentifier(); + } - public String getIdentifier(){ - return "%s %s %s %s".formatted(getNetworkCode(), getStationCode(), getChannelName(), getLocationCode()); - } + public String getIdentifier() { + return "%s %s %s %s".formatted(getNetworkCode(), getStationCode(), getChannelName(), getLocationCode()); + } - public double getSensitivity() { - return sensitivity; - } + public double getSensitivity() { + return sensitivity; + } - public abstract InputType getInputType(); + public abstract InputType getInputType(); - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public boolean isSensitivityValid(){ - return getInputType() != InputType.UNKNOWN && sensitivity > 0; - } + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + public boolean isSensitivityValid() { + return getInputType() != InputType.UNKNOWN && sensitivity > 0; + } public void clear() { - getNearbyStations().clear(); - } + getNearbyStations().clear(); + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/station/GlobalStation.java b/GlobalQuakeCore/src/main/java/globalquake/core/station/GlobalStation.java index a22195c6b..34fe35677 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/station/GlobalStation.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/station/GlobalStation.java @@ -16,100 +16,100 @@ public class GlobalStation extends AbstractStation { - private static final long MAX_STRETCH_SECONDS = 60; - private final Object recordsQueueLock = new Object(); - - private final SortedSet records; - private final InputType inputType; - - private Instant nextExpectedLog = null; - - - public GlobalStation(String networkCode, String stationCode, String channelName, - String locationCode, double lat, double lon, double alt, - int id, SeedlinkNetwork seedlinkNetwork, double sensitivity, InputType inputType) { - super(networkCode, stationCode, channelName, locationCode, lat, lon, alt, id, seedlinkNetwork, sensitivity); - this.records = new TreeSet<>(Comparator.comparing(dataRecord -> dataRecord.getStartBtime().toInstant().toEpochMilli())); - this.inputType = inputType; - } - - public void addRecord(DataRecord dr) { - synchronized (recordsQueueLock) { - records.add(dr); - } - } - - @Override - public void analyse() { - synchronized (recordsQueueLock){ - while(!records.isEmpty()){ - DataRecord oldest = records.first(); - - Instant startTime = oldest.getStartBtime().toInstant(); - - if(nextExpectedLog == null){ - records.remove(oldest); - process(oldest); - continue; - } - - if(Math.abs(ChronoUnit.MILLIS.between(startTime, nextExpectedLog)) < 60) { - records.remove(oldest); - process(oldest); - }else if(startTime.isBefore(nextExpectedLog)){ - records.remove(oldest); + private static final long MAX_STRETCH_SECONDS = 60; + private final Object recordsQueueLock = new Object(); + + private final SortedSet records; + private final InputType inputType; + + private Instant nextExpectedLog = null; + + + public GlobalStation(String networkCode, String stationCode, String channelName, + String locationCode, double lat, double lon, double alt, + int id, SeedlinkNetwork seedlinkNetwork, double sensitivity, InputType inputType) { + super(networkCode, stationCode, channelName, locationCode, lat, lon, alt, id, seedlinkNetwork, sensitivity); + this.records = new TreeSet<>(Comparator.comparing(dataRecord -> dataRecord.getStartBtime().toInstant().toEpochMilli())); + this.inputType = inputType; + } + + public void addRecord(DataRecord dr) { + synchronized (recordsQueueLock) { + records.add(dr); + } + } + + @Override + public void analyse() { + synchronized (recordsQueueLock) { + while (!records.isEmpty()) { + DataRecord oldest = records.first(); + + Instant startTime = oldest.getStartBtime().toInstant(); + + if (nextExpectedLog == null) { + records.remove(oldest); + process(oldest); + continue; + } + + if (Math.abs(ChronoUnit.MILLIS.between(startTime, nextExpectedLog)) < 60) { + records.remove(oldest); + process(oldest); + } else if (startTime.isBefore(nextExpectedLog)) { + records.remove(oldest); } else { - long gapSeconds = nextExpectedLog.until(startTime, ChronoUnit.SECONDS); - long stretchSeconds = startTime.until(records.last().getPredictedNextStartBtime().toInstant(), ChronoUnit.SECONDS); - if(gapSeconds > MAX_STRETCH_SECONDS || stretchSeconds > MAX_STRETCH_SECONDS){ - records.remove(oldest); - process(oldest); - continue; - } - - break; - } - } - } - } - - @Override - public InputType getInputType() { - return inputType; - } - - private void process(DataRecord record) { - nextExpectedLog = record.getPredictedNextStartBtime().toInstant(); - - if (!isTimeValid(record)) { - return; - } - - getAnalysis().analyse(record); - GlobalQuake.instance.getEventHandler().fireEvent(new SeedlinkDataEvent(this, record)); - } - - - private boolean isTimeValid(DataRecord record) { - Instant latest = Instant.ofEpochMilli(GlobalQuake.instance.currentTimeMillis()).plus(16, ChronoUnit.SECONDS); - Instant earliest = Instant.ofEpochMilli(GlobalQuake.instance.currentTimeMillis()).minus(Settings.logsStoreTimeMinutes, ChronoUnit.MINUTES); - return record.getStartBtime().toInstant().isAfter(earliest) & record.getStartBtime().toInstant().isBefore(latest); - } - - @Override - public boolean hasDisplayableData() { - return hasData() && getAnalysis().getNumRecords() >= 3; - } - - @Override - public long getDelayMS() { - return getAnalysis().getLastRecord() == 0 ? -1 : GlobalQuake.instance.currentTimeMillis() - getAnalysis().getLastRecord(); - } - - @Override - public boolean isInEventMode() { - Event event = getAnalysis() == null ? null : getAnalysis().getLatestEvent(); - return event != null && event.isValid() && !event.hasEnded(); - } + long gapSeconds = nextExpectedLog.until(startTime, ChronoUnit.SECONDS); + long stretchSeconds = startTime.until(records.last().getPredictedNextStartBtime().toInstant(), ChronoUnit.SECONDS); + if (gapSeconds > MAX_STRETCH_SECONDS || stretchSeconds > MAX_STRETCH_SECONDS) { + records.remove(oldest); + process(oldest); + continue; + } + + break; + } + } + } + } + + @Override + public InputType getInputType() { + return inputType; + } + + private void process(DataRecord record) { + nextExpectedLog = record.getPredictedNextStartBtime().toInstant(); + + if (!isTimeValid(record)) { + return; + } + + getAnalysis().analyse(record); + GlobalQuake.instance.getEventHandler().fireEvent(new SeedlinkDataEvent(this, record)); + } + + + private boolean isTimeValid(DataRecord record) { + Instant latest = Instant.ofEpochMilli(GlobalQuake.instance.currentTimeMillis()).plus(16, ChronoUnit.SECONDS); + Instant earliest = Instant.ofEpochMilli(GlobalQuake.instance.currentTimeMillis()).minus(Settings.logsStoreTimeMinutes, ChronoUnit.MINUTES); + return record.getStartBtime().toInstant().isAfter(earliest) & record.getStartBtime().toInstant().isBefore(latest); + } + + @Override + public boolean hasDisplayableData() { + return hasData() && getAnalysis().getNumRecords() >= 3; + } + + @Override + public long getDelayMS() { + return getAnalysis().getLastRecord() == 0 ? -1 : GlobalQuake.instance.currentTimeMillis() - getAnalysis().getLastRecord(); + } + + @Override + public boolean isInEventMode() { + Event event = getAnalysis() == null ? null : getAnalysis().getLatestEvent(); + return event != null && event.isValid() && !event.hasEnded(); + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/station/StationInterval.java b/GlobalQuakeCore/src/main/java/globalquake/core/station/StationInterval.java index ac68035a5..80bd0d778 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/station/StationInterval.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/station/StationInterval.java @@ -7,7 +7,7 @@ public class StationInterval { private final long start; private long end; - public StationInterval(long start, long end, StationState state){ + public StationInterval(long start, long end, StationState state) { this.start = start; this.end = end; this.state = state; diff --git a/GlobalQuakeCore/src/main/java/globalquake/core/training/ClusterAnalysisTraining.java b/GlobalQuakeCore/src/main/java/globalquake/core/training/ClusterAnalysisTraining.java index 779f72ced..b90b9d665 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/core/training/ClusterAnalysisTraining.java +++ b/GlobalQuakeCore/src/main/java/globalquake/core/training/ClusterAnalysisTraining.java @@ -23,7 +23,7 @@ public class ClusterAnalysisTraining { private static final int MINUTE = 1000 * 60; private static final boolean PKIKP = false; - private static final boolean P = true; + private static final boolean P = true; public static class SimulatedStation extends AbstractStation { @@ -55,7 +55,7 @@ public static void main(String[] args) throws Exception { Settings.maxEvents = 30; System.out.println("Running"); - for(int i = 0; i < 1; i++) { + for (int i = 0; i < 1; i++) { SimulatedStation.nextId.set(0); long a = System.currentTimeMillis(); runTest(5000); @@ -75,7 +75,7 @@ public static void runTest(int numStations) { double maxDist = 180; - for(int i = 0; i < numStations; i++){ + for (int i = 0; i < numStations; i++) { double dist = r.nextDouble() * maxDist / 360.0 * GeoUtils.EARTH_CIRCUMFERENCE; double[] vals = GeoUtils.moveOnGlobe(0, 0, dist, r.nextDouble() * 360.0); @@ -92,7 +92,7 @@ public static void runTest(int numStations) { ClusterAnalysis clusterAnalysis = new ClusterAnalysis(earthquakes, stations); EarthquakeAnalysis earthquakeAnalysis = new EarthquakeAnalysis(clusterAnalysis, earthquakes); - System.out.println("Init done with "+stations.size()+" stations"); + System.out.println("Init done with " + stations.size() + " stations"); int notDetected = 0; int oneDetected = 0; @@ -114,7 +114,7 @@ public static void runTest(int numStations) { while (simulatedQuakesCount < MAX_QUAKES) { - if(allSimulatedEarthquakes.size() < MAX_QUAKES && r.nextDouble() < 0.2){ + if (allSimulatedEarthquakes.size() < MAX_QUAKES && r.nextDouble() < 0.2) { double dist = r.nextDouble() * maxDist / 360.0 * GeoUtils.EARTH_CIRCUMFERENCE; double[] vals = GeoUtils.moveOnGlobe(0, 0, dist, r.nextDouble() * 360.0); double depth = r.nextDouble() * 600.0; @@ -125,16 +125,16 @@ public static void runTest(int numStations) { allSimulatedEarthquakes.add(earthquake); } - for(SimulatedEarthquake simulatedEarthquake : simulatedEarthquakes){ - for(Earthquake earthquake : earthquakes){ + for (SimulatedEarthquake simulatedEarthquake : simulatedEarthquakes) { + for (Earthquake earthquake : earthquakes) { double rawP = TauPTravelTimeCalculator.getPWaveTravelTime(simulatedEarthquake.depth, 0); - if(rawP < 0){ + if (rawP < 0) { continue; } long expectedArrival = (long) (simulatedEarthquake.origin + 1000 * rawP); double rawPA = TauPTravelTimeCalculator.getPWaveTravelTime(earthquake.getDepth(), 0); - if(rawPA < 0){ + if (rawPA < 0) { continue; } @@ -142,7 +142,7 @@ public static void runTest(int numStations) { long err = Math.abs(expectedArrival - actualArrival); - if(err < simulatedEarthquake.maxError){ + if (err < simulatedEarthquake.maxError) { simulatedEarthquake.maxError = err; } } @@ -163,34 +163,34 @@ public static void runTest(int numStations) { System.out.printf("time passed: %.2f%n", time / 1000.0); - if(clusterAnalysis.getClusters().isEmpty()){ + if (clusterAnalysis.getClusters().isEmpty()) { notDetected++; - } else if(clusterAnalysis.getClusters().size() == 1){ + } else if (clusterAnalysis.getClusters().size() == 1) { oneDetected++; } else { tooManyDetected++; } - if(earthquakes.size() > maxQuakes){ + if (earthquakes.size() > maxQuakes) { maxQuakes = earthquakes.size(); } - if(clusterAnalysis.getClusters().size() > maxClusters){ + if (clusterAnalysis.getClusters().size() > maxClusters) { maxClusters = clusterAnalysis.getClusters().size(); } - time += step*5; + time += step * 5; } - System.out.println("Total Events: "+eventC); + System.out.println("Total Events: " + eventC); System.out.println("\n========== SUMMARY =========="); System.out.printf("Counts: %d | %d | %d%n", notDetected, oneDetected, tooManyDetected); - System.err.println("Final cluster count: "+clusterAnalysis.getClusters().size()); - System.err.println("Max clusters count: "+maxClusters); - System.err.println("Final quakes count: "+earthquakes.size()); - System.err.println("Max quakes count: "+maxQuakes); + System.err.println("Final cluster count: " + clusterAnalysis.getClusters().size()); + System.err.println("Max clusters count: " + maxClusters); + System.err.println("Final quakes count: " + earthquakes.size()); + System.err.println("Max quakes count: " + maxQuakes); - for(SimulatedEarthquake simulatedEarthquake : allSimulatedEarthquakes){ + for (SimulatedEarthquake simulatedEarthquake : allSimulatedEarthquakes) { System.err.println(simulatedEarthquake); } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/sounds/GQSound.java b/GlobalQuakeCore/src/main/java/globalquake/sounds/GQSound.java index fff582d1f..eebe10b80 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/sounds/GQSound.java +++ b/GlobalQuakeCore/src/main/java/globalquake/sounds/GQSound.java @@ -29,14 +29,14 @@ public class GQSound { public static final Map descriptions = new HashMap<>(); - static{ + static { descriptions.put("level_0.wav", "Triggered once so-called Cluster is created. " + - "\nThis happens if 4 or more stations detect shaking in close proximity."); + "\nThis happens if 4 or more stations detect shaking in close proximity."); descriptions.put("level_1.wav", "Triggered when cluster reaches level 1. " + - "\nThis happens when at least 7 stations reach 64 counts or at least 4 stations reach 1,000 counts."); + "\nThis happens when at least 7 stations reach 64 counts or at least 4 stations reach 1,000 counts."); descriptions.put("level_2.wav", "Triggered when cluster reaches level 2. " + @@ -72,7 +72,7 @@ public class GQSound { descriptions.put("found.wav", "Earthquake epicenter determined for the first time and it appears on the map."); } - public GQSound(String filename){ + public GQSound(String filename) { this(filename, descriptions.getOrDefault(filename, "[No description provided]")); } @@ -91,7 +91,7 @@ public void load(boolean externalOnly) throws FatalIOException { ClassLoader.getSystemClassLoader().getResourceAsStream("sounds/" + filename); if (audioInStream == null) { - throw new IOException("Sound file not found: %s (from file = %s)".formatted(filename, Files.exists(soundPath))); + throw new IOException("Sound file not found: %s (from file = %s)".formatted(filename, Files.exists(soundPath))); } AudioInputStream audioIn = AudioSystem.getAudioInputStream( @@ -99,12 +99,12 @@ public void load(boolean externalOnly) throws FatalIOException { Clip clip = AudioSystem.getClip(); clip.open(audioIn); this.clip = clip; - } catch(Exception e) { + } catch (Exception e) { throw new FatalIOException("Failed to load sound: " + filename, e); } } - public void export(Path exportPath) throws IOException{ + public void export(Path exportPath) throws IOException { Path exportedFilePath = exportPath.resolve(filename); if (!Files.exists(exportedFilePath)) { // Check if the file already exists InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("sounds/" + filename); diff --git a/GlobalQuakeCore/src/main/java/globalquake/sounds/Sounds.java b/GlobalQuakeCore/src/main/java/globalquake/sounds/Sounds.java index f226c2818..ea35566a5 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/sounds/Sounds.java +++ b/GlobalQuakeCore/src/main/java/globalquake/sounds/Sounds.java @@ -15,93 +15,93 @@ public class Sounds { - public static final File EXPORT_DIR = new File(GlobalQuake.mainFolder, "sounds/"); - - public static final File VOLUMES_FILE = new File(EXPORT_DIR, "soundVolumes.properties"); - public static final GQSound level_0 = new GQSound("level_0.wav"); - public static final GQSound level_1 = new GQSound("level_1.wav"); - public static final GQSound level_2 = new GQSound("level_2.wav"); - public static final GQSound level_3 = new GQSound("level_3.wav"); - public static final GQSound level_4 = new GQSound("level_4.wav"); - public static final GQSound intensify = new GQSound("intensify.wav"); - public static final GQSound felt = new GQSound("felt.wav"); - public static final GQSound eew_warning = new GQSound("eew_warning.wav"); - public static final GQSound felt_strong = new GQSound("felt_strong.wav"); - public static final GQSound countdown = new GQSound("countdown.wav"); - public static final GQSound countdown2 = new GQSound("countdown.wav"); - public static final GQSound update = new GQSound("update.wav"); - public static final GQSound found = new GQSound("found.wav"); - - public static final GQSound[] ALL_SOUNDS = { - found, - update, - level_0, - level_1, - level_2, - level_3, - level_4, - intensify, - felt, - felt_strong, - eew_warning, - countdown, - countdown2, // workaround - }; - - public static final GQSound[] ALL_ACTUAL_SOUNDS = { - found, - update, - level_0, - level_1, - level_2, - level_3, - level_4, - intensify, - felt, - felt_strong, - eew_warning, - countdown, - }; - - public static boolean soundsAvailable = true; - - private static final ExecutorService soundService = Executors.newCachedThreadPool(); - - public static void exportSounds() throws IOException { - Path exportPath = Paths.get(EXPORT_DIR.getAbsolutePath()); - if (!Files.exists(exportPath)) { - Files.createDirectory(exportPath); - writeReadmeFile(exportPath); - } - - try { - for (GQSound gqSound : ALL_ACTUAL_SOUNDS) { - gqSound.export(exportPath); - } - } catch(IOException e){ - GlobalQuake.getErrorHandler().handleWarning(new RuntimeApplicationException("Unable to export sounds to %s!".formatted(exportPath.toString()))); - } - } - - - public static void loadSounds() { - try { - for (GQSound gqSound : ALL_SOUNDS) { - gqSound.load(false); - } - soundsAvailable = true; - } catch(FatalIOException e){ - soundsAvailable = false; - if(GlobalQuake.errorHandler != null) { - GlobalQuake.errorHandler.handleWarning(e); - }else{ - Logger.error(e); - } - } - } - - private static void writeReadmeFile(Path exportPath) throws IOException { - String readmeContent = """ + public static final File EXPORT_DIR = new File(GlobalQuake.mainFolder, "sounds/"); + + public static final File VOLUMES_FILE = new File(EXPORT_DIR, "soundVolumes.properties"); + public static final GQSound level_0 = new GQSound("level_0.wav"); + public static final GQSound level_1 = new GQSound("level_1.wav"); + public static final GQSound level_2 = new GQSound("level_2.wav"); + public static final GQSound level_3 = new GQSound("level_3.wav"); + public static final GQSound level_4 = new GQSound("level_4.wav"); + public static final GQSound intensify = new GQSound("intensify.wav"); + public static final GQSound felt = new GQSound("felt.wav"); + public static final GQSound eew_warning = new GQSound("eew_warning.wav"); + public static final GQSound felt_strong = new GQSound("felt_strong.wav"); + public static final GQSound countdown = new GQSound("countdown.wav"); + public static final GQSound countdown2 = new GQSound("countdown.wav"); + public static final GQSound update = new GQSound("update.wav"); + public static final GQSound found = new GQSound("found.wav"); + + public static final GQSound[] ALL_SOUNDS = { + found, + update, + level_0, + level_1, + level_2, + level_3, + level_4, + intensify, + felt, + felt_strong, + eew_warning, + countdown, + countdown2, // workaround + }; + + public static final GQSound[] ALL_ACTUAL_SOUNDS = { + found, + update, + level_0, + level_1, + level_2, + level_3, + level_4, + intensify, + felt, + felt_strong, + eew_warning, + countdown, + }; + + public static boolean soundsAvailable = true; + + private static final ExecutorService soundService = Executors.newCachedThreadPool(); + + public static void exportSounds() throws IOException { + Path exportPath = Paths.get(EXPORT_DIR.getAbsolutePath()); + if (!Files.exists(exportPath)) { + Files.createDirectory(exportPath); + writeReadmeFile(exportPath); + } + + try { + for (GQSound gqSound : ALL_ACTUAL_SOUNDS) { + gqSound.export(exportPath); + } + } catch (IOException e) { + GlobalQuake.getErrorHandler().handleWarning(new RuntimeApplicationException("Unable to export sounds to %s!".formatted(exportPath.toString()))); + } + } + + + public static void loadSounds() { + try { + for (GQSound gqSound : ALL_SOUNDS) { + gqSound.load(false); + } + soundsAvailable = true; + } catch (FatalIOException e) { + soundsAvailable = false; + if (GlobalQuake.errorHandler != null) { + GlobalQuake.errorHandler.handleWarning(e); + } else { + Logger.error(e); + } + } + } + + private static void writeReadmeFile(Path exportPath) throws IOException { + String readmeContent = """ README This directory contains the exported sound files from GlobalQuake. @@ -111,98 +111,99 @@ private static void writeReadmeFile(Path exportPath) throws IOException { Enjoy customizing your sound experience!"""; - Files.writeString(exportPath.resolve("README.txt"), readmeContent, StandardOpenOption.CREATE); - } - - public static void load() throws Exception { - exportSounds(); - loadSounds(); - loadVolumes(); - } - - public static void playSound(GQSound sound) { - if(!Settings.enableSound || !soundsAvailable || sound == null || sound.getClip() == null) { - return; - } - - soundService.submit(() -> { - try { - playClipRuntime(sound); - } catch(Exception e){ - Logger.error(e); - } - }); - } - - private static void loadVolumes() { - if(!VOLUMES_FILE.exists()){ - Logger.info("Sound volumes file doesn't exist, aborting!"); - return; - } - Properties properties = new Properties(); - - try (FileInputStream inputStream = new FileInputStream(VOLUMES_FILE)) { - // Load properties from the file - properties.load(inputStream); - - for (GQSound sound : ALL_ACTUAL_SOUNDS) { - // Retrieve the volume from the properties file using the filename as the key - String volumeString = properties.getProperty(sound.getFilename()); - if (volumeString != null) { - // Parse the volume as a double and set it in the GQSound instance - sound.volume = Math.max(0.0, Math.min(1.0, Double.parseDouble(volumeString))); - } - } - } catch (IOException | NumberFormatException e) { - Logger.error(new RuntimeApplicationException("Unable to load sound volumes!", e)); - } - - countdown2.volume = countdown.volume; // workaround - } - public static void storeVolumes() { - Properties properties = new Properties(); - - for (GQSound sound : ALL_ACTUAL_SOUNDS) { - // Use the filename as the key and the volume as the value - properties.setProperty(sound.getFilename(), String.valueOf(sound.volume)); - } - - try (FileOutputStream outputStream = new FileOutputStream(VOLUMES_FILE)) { - // Store the properties in the file - properties.store(outputStream, "Sound Volumes"); - } catch (IOException e) { - Logger.error(new RuntimeApplicationException("Unable to store sound volumes!", e)); - } - } - - private static void playClipRuntime(GQSound sound) { - Clip clip = sound.getClip(); - clip.stop(); - clip.flush(); - clip.setFramePosition(0); - - double volume = Math.max(0.0, Math.min(1.0, sound.volume * (Settings.globalVolume / 100.0))); - FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); - gainControl.setValue(20f * (float) Math.log10(volume)); - - clip.start(); + Files.writeString(exportPath.resolve("README.txt"), readmeContent, StandardOpenOption.CREATE); + } + + public static void load() throws Exception { + exportSounds(); + loadSounds(); + loadVolumes(); + } + + public static void playSound(GQSound sound) { + if (!Settings.enableSound || !soundsAvailable || sound == null || sound.getClip() == null) { + return; + } + + soundService.submit(() -> { + try { + playClipRuntime(sound); + } catch (Exception e) { + Logger.error(e); + } + }); + } + + private static void loadVolumes() { + if (!VOLUMES_FILE.exists()) { + Logger.info("Sound volumes file doesn't exist, aborting!"); + return; + } + Properties properties = new Properties(); + + try (FileInputStream inputStream = new FileInputStream(VOLUMES_FILE)) { + // Load properties from the file + properties.load(inputStream); + + for (GQSound sound : ALL_ACTUAL_SOUNDS) { + // Retrieve the volume from the properties file using the filename as the key + String volumeString = properties.getProperty(sound.getFilename()); + if (volumeString != null) { + // Parse the volume as a double and set it in the GQSound instance + sound.volume = Math.max(0.0, Math.min(1.0, Double.parseDouble(volumeString))); + } + } + } catch (IOException | NumberFormatException e) { + Logger.error(new RuntimeApplicationException("Unable to load sound volumes!", e)); + } + + countdown2.volume = countdown.volume; // workaround + } + + public static void storeVolumes() { + Properties properties = new Properties(); + + for (GQSound sound : ALL_ACTUAL_SOUNDS) { + // Use the filename as the key and the volume as the value + properties.setProperty(sound.getFilename(), String.valueOf(sound.volume)); + } + + try (FileOutputStream outputStream = new FileOutputStream(VOLUMES_FILE)) { + // Store the properties in the file + properties.store(outputStream, "Sound Volumes"); + } catch (IOException e) { + Logger.error(new RuntimeApplicationException("Unable to store sound volumes!", e)); + } + } + + private static void playClipRuntime(GQSound sound) { + Clip clip = sound.getClip(); + clip.stop(); + clip.flush(); + clip.setFramePosition(0); + + double volume = Math.max(0.0, Math.min(1.0, sound.volume * (Settings.globalVolume / 100.0))); + FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); + gainControl.setValue(20f * (float) Math.log10(volume)); + + clip.start(); try { Thread.sleep(clip.getMicrosecondLength() / 1000); } catch (InterruptedException e) { throw new RuntimeException(e); } - } + } - public static void main(String[] args) throws Exception { - GlobalQuake.prepare(new File("."), null); - load(); + public static void main(String[] args) throws Exception { + GlobalQuake.prepare(new File("."), null); + load(); - playSound(level_2); + playSound(level_2); - Thread.sleep(3000); + Thread.sleep(3000); - System.exit(0); - } + System.exit(0); + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/StationCountPanel.java b/GlobalQuakeCore/src/main/java/globalquake/ui/StationCountPanel.java index ceea815e8..b539ec9ad 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/StationCountPanel.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/StationCountPanel.java @@ -37,16 +37,16 @@ public void recalculate() { int sel = 0; int unb = 0; manager.getStationDatabase().getDatabaseReadLock().lock(); - try{ - for(Network network : manager.getStationDatabase().getNetworks()){ - for(Station station: network.getStations()){ - for(Channel channel:station.getChannels()){ + try { + for (Network network : manager.getStationDatabase().getNetworks()) { + for (Station station : network.getStations()) { + for (Channel channel : station.getChannels()) { tot++; - if(channel.isAvailable()){ + if (channel.isAvailable()) { ava++; } - if(channel.equals(station.getSelectedChannel())){ - if(channel.isAvailable()){ + if (channel.equals(station.getSelectedChannel())) { + if (channel.isAvailable()) { sel++; } else { unb++; @@ -64,12 +64,12 @@ public void recalculate() { unavailable.setCount(unb); } - static class CounterPanel extends JPanel - { + static class CounterPanel extends JPanel { private final String name; private final JLabel label; private int count; - public CounterPanel(String name, Color color){ + + public CounterPanel(String name, Color color) { this.name = name; add(new StationIcon(color)); add(label = new JLabel()); @@ -97,7 +97,7 @@ private static class StationIcon extends JPanel { public StationIcon(Color color) { this.color = color; - setPreferredSize(new Dimension(22,22)); + setPreferredSize(new Dimension(22, 22)); } @Override @@ -109,7 +109,7 @@ public void paint(Graphics gr) { Path2D path = new Path2D.Double(); path.moveTo(0, size * (Math.sqrt(3) / 2.0)); path.lineTo(size, size * (Math.sqrt(3) / 2.0)); - path.lineTo(size/ 2.0, 0); + path.lineTo(size / 2.0, 0); path.closePath(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/action/RestoreDatabaseAction.java b/GlobalQuakeCore/src/main/java/globalquake/ui/action/RestoreDatabaseAction.java index 0e81ce739..0206e52ff 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/action/RestoreDatabaseAction.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/action/RestoreDatabaseAction.java @@ -12,7 +12,7 @@ public class RestoreDatabaseAction extends AbstractAction { private final StationDatabaseManager databaseManager; private final Window parent; - public RestoreDatabaseAction(Window parent, StationDatabaseManager databaseManager){ + public RestoreDatabaseAction(Window parent, StationDatabaseManager databaseManager) { super("Restore Defaults"); this.databaseManager = databaseManager; this.parent = parent; diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/action/seedlink/AddSeedlinkNetworkAction.java b/GlobalQuakeCore/src/main/java/globalquake/ui/action/seedlink/AddSeedlinkNetworkAction.java index 4b98f19ed..c57533ad6 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/action/seedlink/AddSeedlinkNetworkAction.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/action/seedlink/AddSeedlinkNetworkAction.java @@ -13,7 +13,7 @@ public class AddSeedlinkNetworkAction extends AbstractAction { private final StationDatabaseManager databaseManager; private final Window parent; - public AddSeedlinkNetworkAction(Window parent, StationDatabaseManager databaseManager){ + public AddSeedlinkNetworkAction(Window parent, StationDatabaseManager databaseManager) { super("Add"); this.databaseManager = databaseManager; this.parent = parent; diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/action/seedlink/EditSeedlinkNetworkAction.java b/GlobalQuakeCore/src/main/java/globalquake/ui/action/seedlink/EditSeedlinkNetworkAction.java index 1c38c9bb6..a055131eb 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/action/seedlink/EditSeedlinkNetworkAction.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/action/seedlink/EditSeedlinkNetworkAction.java @@ -18,7 +18,7 @@ public class EditSeedlinkNetworkAction extends AbstractAction { private JTable table; - public EditSeedlinkNetworkAction(Window parent, StationDatabaseManager databaseManager){ + public EditSeedlinkNetworkAction(Window parent, StationDatabaseManager databaseManager) { super("Edit"); this.databaseManager = databaseManager; this.parent = parent; diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/action/seedlink/RemoveSeedlinkNetworkAction.java b/GlobalQuakeCore/src/main/java/globalquake/ui/action/seedlink/RemoveSeedlinkNetworkAction.java index e82b5fc06..f263857c2 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/action/seedlink/RemoveSeedlinkNetworkAction.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/action/seedlink/RemoveSeedlinkNetworkAction.java @@ -19,7 +19,7 @@ public class RemoveSeedlinkNetworkAction extends AbstractAction { private JTable table; - public RemoveSeedlinkNetworkAction(StationDatabaseManager databaseManager, Component parent){ + public RemoveSeedlinkNetworkAction(StationDatabaseManager databaseManager, Component parent) { super("Remove"); this.parent = parent; this.databaseManager = databaseManager; @@ -52,14 +52,14 @@ public void actionPerformed(ActionEvent actionEvent) { } databaseManager.getStationDatabase().getDatabaseWriteLock().lock(); - try{ + try { java.util.List toBeRemoved = new ArrayList<>(); - for(int i:selectedRows){ + for (int i : selectedRows) { SeedlinkNetwork seedlinkNetwork = tableModel.getEntity(table.getRowSorter().convertRowIndexToModel(i)); toBeRemoved.add(seedlinkNetwork); } databaseManager.removeAllSeedlinks(toBeRemoved); - }finally { + } finally { databaseManager.getStationDatabase().getDatabaseWriteLock().unlock(); } diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/action/source/AddStationSourceAction.java b/GlobalQuakeCore/src/main/java/globalquake/ui/action/source/AddStationSourceAction.java index a1b94486f..75dc3288a 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/action/source/AddStationSourceAction.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/action/source/AddStationSourceAction.java @@ -13,7 +13,7 @@ public class AddStationSourceAction extends AbstractAction { private final StationDatabaseManager databaseManager; private final Window parent; - public AddStationSourceAction(Window parent, StationDatabaseManager databaseManager){ + public AddStationSourceAction(Window parent, StationDatabaseManager databaseManager) { super("Add"); this.databaseManager = databaseManager; this.parent = parent; diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/action/source/EditStationSourceAction.java b/GlobalQuakeCore/src/main/java/globalquake/ui/action/source/EditStationSourceAction.java index a4d035313..7600cdd08 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/action/source/EditStationSourceAction.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/action/source/EditStationSourceAction.java @@ -18,7 +18,7 @@ public class EditStationSourceAction extends AbstractAction { private JTable table; - public EditStationSourceAction(Window parent, StationDatabaseManager databaseManager){ + public EditStationSourceAction(Window parent, StationDatabaseManager databaseManager) { super("Edit"); this.databaseManager = databaseManager; this.parent = parent; diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/action/source/RemoveStationSourceAction.java b/GlobalQuakeCore/src/main/java/globalquake/ui/action/source/RemoveStationSourceAction.java index d318831bf..5b4b47bf4 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/action/source/RemoveStationSourceAction.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/action/source/RemoveStationSourceAction.java @@ -20,7 +20,7 @@ public class RemoveStationSourceAction extends AbstractAction { private JTable table; - public RemoveStationSourceAction(StationDatabaseManager databaseManager, Component parent){ + public RemoveStationSourceAction(StationDatabaseManager databaseManager, Component parent) { super("Remove"); this.parent = parent; this.databaseManager = databaseManager; @@ -53,14 +53,14 @@ public void actionPerformed(ActionEvent actionEvent) { } databaseManager.getStationDatabase().getDatabaseWriteLock().lock(); - try{ + try { List toBeRemoved = new ArrayList<>(); - for(int i:selectedRows){ + for (int i : selectedRows) { StationSource stationSource = tableModel.getEntity(table.getRowSorter().convertRowIndexToModel(i)); toBeRemoved.add(stationSource); } databaseManager.removeAllStationSources(toBeRemoved); - }finally { + } finally { databaseManager.getStationDatabase().getDatabaseWriteLock().unlock(); } diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/database/SeedlinkServersPanel.java b/GlobalQuakeCore/src/main/java/globalquake/ui/database/SeedlinkServersPanel.java index d7e623da2..2f25bff87 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/database/SeedlinkServersPanel.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/database/SeedlinkServersPanel.java @@ -25,7 +25,7 @@ public class SeedlinkServersPanel extends JPanel { private final JButton launchButton; public SeedlinkServersPanel(Window parent, StationDatabaseManager manager, AbstractAction restoreDatabaseAction, - JButton selectButton, JButton launchButton) { + JButton selectButton, JButton launchButton) { this.manager = manager; this.selectButton = selectButton; this.launchButton = launchButton; @@ -65,7 +65,7 @@ public SeedlinkServersPanel(Window parent, StationDatabaseManager manager, Abstr private JPanel createActionsPanel(AbstractAction restoreDatabaseAction) { JPanel actionsPanel = new JPanel(); - actionsPanel.setLayout( new GridLayout(2,6,5,5)); + actionsPanel.setLayout(new GridLayout(2, 6, 5, 5)); actionsPanel.add(new JButton(addSeedlinkNetworkAction)); actionsPanel.add(new JButton(editSeedlinkNetworkAction)); diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/database/StationSourcesPanel.java b/GlobalQuakeCore/src/main/java/globalquake/ui/database/StationSourcesPanel.java index f084bb396..b0f8dcb0a 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/database/StationSourcesPanel.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/database/StationSourcesPanel.java @@ -62,7 +62,7 @@ public StationSourcesPanel(Window parent, StationDatabaseManager manager, Abstra private JPanel createActionsPanel(AbstractAction restoreDatabaseAction) { JPanel actionsPanel = new JPanel(); - actionsPanel.setLayout( new GridLayout(2,6,5,5)); + actionsPanel.setLayout(new GridLayout(2, 6, 5, 5)); actionsPanel.add(new JButton(addStationSourceAction)); actionsPanel.add(new JButton(editStationSourceAction)); diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/globe/GlobePanel.java b/GlobalQuakeCore/src/main/java/globalquake/ui/globe/GlobePanel.java index cbe17bdc7..5baad40bb 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/globe/GlobePanel.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/globe/GlobePanel.java @@ -81,7 +81,7 @@ public void mouseMoved(MouseEvent e) { public void mouseDragged(MouseEvent e) { lastMouse = e.getPoint(); renderer.mouseMoved(e); - if(cinemaMode){ + if (cinemaMode) { Logger.info("Cinema mode disabled by dragging"); setCinemaMode(false); } @@ -147,7 +147,7 @@ public void mouseClicked(MouseEvent e) { }); addMouseWheelListener(e -> { - if(cinemaMode){ + if (cinemaMode) { Logger.info("Cinema mode disabled by scrolling"); setCinemaMode(false); } @@ -213,7 +213,7 @@ public void run() { } private void runAnimation(Animation animation) { - if(animation == null){ + if (animation == null) { return; } @@ -230,13 +230,13 @@ private void runAnimation(Animation animation) { @Override public void run() { Animation next = nextAnimation; - if(animation != next){ + if (animation != next) { this.cancel(); runAnimation(next); latch.countDown(); return; } - if(!cinemaMode){ + if (!cinemaMode) { Logger.info("Animation aborted!"); this.cancel(); latch.countDown(); @@ -244,7 +244,7 @@ public void run() { } double t = (double) step[0] / steps; double t1 = -Math.cos(t * Math.PI) * 0.5 + 0.5; - double t2 = Math.sin(t * Math.PI) * Math.max(1.6, animation.initialScroll() + animation.targetScroll()) * (distGC / 14000.0); + double t2 = Math.sin(t * Math.PI) * Math.max(1.6, animation.initialScroll() + animation.targetScroll()) * (distGC / 14000.0); double currentScroll = t2 + animation.initialScroll() + t * (animation.targetScroll() - animation.initialScroll()); double currentLatitude = animation.initialLat() + t1 * (animation.targetLat() - animation.initialLat()); double currentLongitude = animation.initialLon() + t1 * (animation.targetLon() - animation.initialLon()); @@ -254,7 +254,7 @@ public void run() { renderer.updateCamera(createRenderProperties()); - if(step[0] == steps){ + if (step[0] == steps) { this.cancel(); latch.countDown(); } @@ -283,8 +283,8 @@ public synchronized void jumpTo(double targetLat, double targetLon, double targe renderer.updateCamera(createRenderProperties()); } - public synchronized void smoothTransition(double targetLat, double targetLon, double targetScroll){ - if(!cinemaMode || (System.currentTimeMillis() - lastJump < 1000)){ + public synchronized void smoothTransition(double targetLat, double targetLon, double targetScroll) { + if (!cinemaMode || (System.currentTimeMillis() - lastJump < 1000)) { return; } @@ -295,11 +295,11 @@ public synchronized void smoothTransition(double targetLat, double targetLon, do targetLat %= 360; targetLon %= 360; - if(Math.abs((startLon + 360) - targetLon) < Math.abs(startLon - targetLon)){ + if (Math.abs((startLon + 360) - targetLon) < Math.abs(startLon - targetLon)) { startLon += 360; } - if(Math.abs(startLon - (targetLon + 360)) < Math.abs(startLon - targetLon)){ + if (Math.abs(startLon - (targetLon + 360)) < Math.abs(startLon - targetLon)) { targetLon += 360; } @@ -377,7 +377,7 @@ public boolean interactionAllowed() { } @SuppressWarnings("BooleanMethodIsAlwaysInverted") - private boolean _interactionAllowed(){ + private boolean _interactionAllowed() { return interactionAllowed() && !cinemaMode; } @@ -385,7 +385,7 @@ private void handleClick(int x, int y) { ArrayList> clicked = new ArrayList<>(); renderer.getRenderFeatures().parallelStream().forEach(feature -> { for (RenderEntity entity : feature.getEntities()) { - if(!feature.isEntityVisible(entity)){ + if (!feature.isEntityVisible(entity)) { continue; } Point2D centerCoords = feature.getCenterCoords(entity); @@ -472,7 +472,7 @@ public void paint(Graphics gr) { } private void checkCinemaMode() { - if(!cinemaMode && Settings.cinemaModeReenable && System.currentTimeMillis() - lastCinemaModeCheck > CINEMA_MODE_CHECK_INTERVAL){ + if (!cinemaMode && Settings.cinemaModeReenable && System.currentTimeMillis() - lastCinemaModeCheck > CINEMA_MODE_CHECK_INTERVAL) { setCinemaMode(true); } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/globe/GlobeRenderer.java b/GlobalQuakeCore/src/main/java/globalquake/ui/globe/GlobeRenderer.java index 2ad0a174e..c7a47f037 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/globe/GlobeRenderer.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/globe/GlobeRenderer.java @@ -43,7 +43,7 @@ public class GlobeRenderer { private final List> renderFeatures; private Point lastMouse; - public GlobeRenderer(){ + public GlobeRenderer() { renderFeatures = new ArrayList<>(); } @@ -89,7 +89,7 @@ public void updateCamera(RenderProperties properties) { renderProperties = properties; } - public Point2D projectPoint(Vector3D pos, RenderProperties renderProperties){ + public Point2D projectPoint(Vector3D pos, RenderProperties renderProperties) { Point2D point2D = new Point2D(); project(point2D, pos.getX(), pos.getY(), pos.getZ(), GeoUtils.EARTH_RADIUS + renderProperties.getRenderPrecomputedValues().camera_altitude, @@ -99,7 +99,7 @@ public Point2D projectPoint(Vector3D pos, RenderProperties renderProperties){ } public boolean project3D(Path2D.Float result, Polygon3D polygon3D, boolean canClip, RenderProperties renderProperties) { - if(polygon3D == null || polygon3D.getBoundingBoxCorner(0) == null){ + if (polygon3D == null || polygon3D.getBoundingBoxCorner(0) == null) { return false; } Point2D point2D = new Point2D(); @@ -182,7 +182,7 @@ public boolean project3D(Path2D.Float result, Polygon3D polygon3D, boolean canCl } - if(canClip && mask != 0){ + if (canClip && mask != 0) { return false; } @@ -235,7 +235,7 @@ private void bowAlgorithm(Point2D point2D, Path2D.Float result, Vector3D bowStar ground(point2D, renderProperties); - if(!bow) { + if (!bow) { result.lineTo(startX, startY); result.moveTo(point2D.x, point2D.y); return; @@ -249,8 +249,8 @@ private void bowAlgorithm(Point2D point2D, Path2D.Float result, Vector3D bowStar double x_mid = (startX + endX) / 2.0; double y_mid = (startY + endY) / 2.0; - point2D.x=x_mid; - point2D.y=y_mid; + point2D.x = x_mid; + point2D.y = y_mid; ground(point2D, renderProperties); @@ -258,7 +258,7 @@ private void bowAlgorithm(Point2D point2D, Path2D.Float result, Vector3D bowStar drawBow(point2D, result, point2D.x, point2D.y, endX, endY, renderProperties); } - private void drawBow(Point2D point2D, Path2D.Float result, double startX, double startY, double endX, double endY, RenderProperties renderProperties){ + private void drawBow(Point2D point2D, Path2D.Float result, double startX, double startY, double endX, double endY, RenderProperties renderProperties) { double dx = endX - startX; double dy = endY - startY; @@ -272,7 +272,7 @@ private void drawBow(Point2D point2D, Path2D.Float result, double startX, double } } - void ground(Point2D point2D, RenderProperties renderProperties){ + void ground(Point2D point2D, RenderProperties renderProperties) { double dist = Math.sqrt(Math.pow(point2D.x - renderProperties.width / 2.0, 2) + Math.pow(point2D.y - renderProperties.height / 2.0, 2)); point2D.x = renderProperties.width / 2.0 + (point2D.x - renderProperties.width / 2.0) * (renderProperties.getRenderPrecomputedValues().horizonDist / dist); @@ -307,7 +307,7 @@ public synchronized void render(Graphics2D graphics, RenderProperties props) { }); } - public synchronized void addFeature(RenderFeature renderFeature){ + public synchronized void addFeature(RenderFeature renderFeature) { renderFeatures.add(renderFeature); } @@ -327,7 +327,7 @@ public static Vector3D createVec3D(Point2D centerCoords) { public void createNGon(Polygon3D polygon3D, double lat, double lon, double radius, double altitude, double startAngle, double step) { polygon3D.reset(); - if(radius < 1e-6){ + if (radius < 1e-6) { return; } Point2DGQ point = new Point2DGQ(); @@ -391,7 +391,7 @@ public void createSquare(Polygon3D polygon3D, double lat, double lon, double rad public List getAllInside(RenderFeature renderFeature, Shape shape, RenderProperties renderPropertiesLocal) { List result = new ArrayList<>(); renderFeature.getEntities().forEach(renderEntity -> { - if(isMouseInside(renderFeature.getCenterCoords(renderEntity), shape, renderPropertiesLocal)){ + if (isMouseInside(renderFeature.getCenterCoords(renderEntity), shape, renderPropertiesLocal)) { result.add(renderEntity.getOriginal()); } }); @@ -407,16 +407,16 @@ public double pxToDeg(double px, RenderProperties renderProperties) { } public boolean isMouseNearby(Point2D coords, double dist, boolean moved, RenderProperties renderProperties) { - if(lastMouse == null || coords == null){ + if (lastMouse == null || coords == null) { return false; } - if(moved && !hasMouseMovedRecently()){ + if (moved && !hasMouseMovedRecently()) { return false; } Vector3D vect; Point2D point = projectPoint(vect = new Vector3D(getX_3D(coords.x, coords.y, 0), getY_3D(coords.x, coords.y, 0), getZ_3D(coords.x, coords.y, 0)), renderProperties); - return isAboveHorizon(vect, renderProperties) && Math.sqrt(Math.pow(point.x - lastMouse.x, 2) + Math.pow(point.y - lastMouse.y, 2)) <= dist; + return isAboveHorizon(vect, renderProperties) && Math.sqrt(Math.pow(point.x - lastMouse.x, 2) + Math.pow(point.y - lastMouse.y, 2)) <= dist; } public boolean hasMouseMovedRecently() { @@ -424,13 +424,13 @@ public boolean hasMouseMovedRecently() { } public boolean isMouseInside(Point2D coords, Shape shape, RenderProperties renderProperties) { - if(coords == null || shape == null){ + if (coords == null || shape == null) { return false; } Vector3D vect; Point2D point = projectPoint(vect = new Vector3D(getX_3D(coords.x, coords.y, 0), getY_3D(coords.x, coords.y, 0), getZ_3D(coords.x, coords.y, 0)), renderProperties); - return isAboveHorizon(vect, renderProperties) && shape.contains(point.toAwt()); + return isAboveHorizon(vect, renderProperties) && shape.contains(point.toAwt()); } public void mouseMoved(MouseEvent e) { @@ -443,7 +443,7 @@ public Point getLastMouse() { } public double getAngularDistance(Point2D centerCoords, RenderProperties renderProperties) { - if(centerCoords == null){ + if (centerCoords == null) { return Double.NaN; } return GeoUtils.greatCircleDistance(centerCoords.x, centerCoords.y, renderProperties.centerLat, renderProperties.centerLon) / GeoUtils.EARTH_CIRCUMFERENCE * 360.0; diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/globe/Point2D.java b/GlobalQuakeCore/src/main/java/globalquake/ui/globe/Point2D.java index d4f0537c7..9ef9163ba 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/globe/Point2D.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/globe/Point2D.java @@ -2,14 +2,15 @@ public class Point2D { - public Point2D(){ + public Point2D() { } - public Point2D(double x, double y){ - this.x=x; - this.y=y; + public Point2D(double x, double y) { + this.x = x; + this.y = y; } + public double x; public double y; diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/globe/RenderPrecomputedValues.java b/GlobalQuakeCore/src/main/java/globalquake/ui/globe/RenderPrecomputedValues.java index e96e59400..1e18b2540 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/globe/RenderPrecomputedValues.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/globe/RenderPrecomputedValues.java @@ -20,7 +20,7 @@ public class RenderPrecomputedValues { public final double sinPitch; public double horizonDist; - public RenderPrecomputedValues(RenderProperties renderProperties){ + public RenderPrecomputedValues(RenderProperties renderProperties) { camera_altitude = GeoUtils.EARTH_RADIUS * renderProperties.scroll; double cameraYaw = -FastMath.toRadians(renderProperties.centerLon); @@ -34,9 +34,9 @@ public RenderPrecomputedValues(RenderProperties renderProperties){ cameraPoint = new Vector3D(getX_3D(renderProperties.centerLat, renderProperties.centerLon, camera_altitude * 1000), getY_3D(renderProperties.centerLat, renderProperties.centerLon, camera_altitude * 1000), GlobeRenderer.getZ_3D(renderProperties.centerLat, renderProperties.centerLon, camera_altitude * 1000)); - } + } - public void part2(GlobeRenderer renderer, RenderProperties renderProperties){ + public void part2(GlobeRenderer renderer, RenderProperties renderProperties) { double[] moved = GeoUtils.moveOnGlobe(renderProperties.centerLat, renderProperties.centerLon, 1, 0); Vector3D surfacePoint = new Vector3D(getX_3D(renderProperties.centerLat, renderProperties.centerLon, 0), diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/globe/RenderProperties.java b/GlobalQuakeCore/src/main/java/globalquake/ui/globe/RenderProperties.java index 95999e90b..ffb7b491e 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/globe/RenderProperties.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/globe/RenderProperties.java @@ -1,6 +1,6 @@ package globalquake.ui.globe; -public class RenderProperties{ +public class RenderProperties { public final double centerLat; public final double centerLon; public final double scroll; diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/globe/feature/FeatureGeoPolygons.java b/GlobalQuakeCore/src/main/java/globalquake/ui/globe/feature/FeatureGeoPolygons.java index 9f238994d..a485580d1 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/globe/feature/FeatureGeoPolygons.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/globe/feature/FeatureGeoPolygons.java @@ -22,7 +22,7 @@ public class FeatureGeoPolygons extends RenderFeature { private final double minScroll; private final double maxScroll; - public FeatureGeoPolygons(List polygonList, double minScroll, double maxScroll){ + public FeatureGeoPolygons(List polygonList, double minScroll, double maxScroll) { super(1); this.polygonList = polygonList; this.minScroll = minScroll; @@ -36,7 +36,7 @@ public Collection getElements() { @Override public boolean isEnabled(RenderProperties properties) { - return properties.scroll >=minScroll && properties.scroll < maxScroll; + return properties.scroll >= minScroll && properties.scroll < maxScroll; } @Override @@ -57,7 +57,7 @@ public boolean needsCreatePolygon(RenderEntity entity, boolean proper @Override public void createPolygon(GlobeRenderer renderer, RenderEntity entity, RenderProperties renderProperties) { Polygon3D result_pol = new Polygon3D(); - for(int i = 0; i < entity.getOriginal().getSize(); i++){ + for (int i = 0; i < entity.getOriginal().getSize(); i++) { float lat = entity.getOriginal().getLats()[i]; float lon = entity.getOriginal().getLons()[i]; Vector3D vec = GlobeRenderer.createVec3D(new Vector2D(lat, lon), 0); @@ -83,7 +83,7 @@ public Point2D getCenterCoords(RenderEntity entity) { @Override public void render(GlobeRenderer renderer, Graphics2D graphics, RenderEntity entity, RenderProperties renderProperties) { RenderElement element = entity.getRenderElement(0); - if(!element.shouldDraw){ + if (!element.shouldDraw) { return; } graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/globe/feature/FeatureHorizon.java b/GlobalQuakeCore/src/main/java/globalquake/ui/globe/feature/FeatureHorizon.java index 8de6db3e4..3bdcb1d54 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/globe/feature/FeatureHorizon.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/globe/feature/FeatureHorizon.java @@ -9,12 +9,12 @@ import java.awt.*; import java.util.Collection; -public class FeatureHorizon extends RenderFeature{ +public class FeatureHorizon extends RenderFeature { private final java.util.List points; private final double quality; - public FeatureHorizon(Point2D center, double quality){ + public FeatureHorizon(Point2D center, double quality) { super(1); points = java.util.List.of(center); this.quality = quality; @@ -28,13 +28,13 @@ public Collection getElements() { @Override public void createPolygon(GlobeRenderer renderer, RenderEntity entity, RenderProperties renderProperties) { RenderElement element = entity.getRenderElement(0); - if(element.getPolygon() == null){ + if (element.getPolygon() == null) { element.setPolygon(new Polygon3D()); } renderer.createCircle(element.getPolygon(), renderProperties.centerLat, renderProperties.centerLon, - renderProperties.getRenderPrecomputedValues().maxAngle / (2*Math.PI) * GeoUtils.EARTH_CIRCUMFERENCE, 0, quality); + renderProperties.getRenderPrecomputedValues().maxAngle / (2 * Math.PI) * GeoUtils.EARTH_CIRCUMFERENCE, 0, quality); } @Override @@ -56,13 +56,13 @@ public boolean needsProject(RenderEntity entity, boolean propertiesChan public void project(GlobeRenderer renderer, RenderEntity entity, RenderProperties renderProperties) { RenderElement element = entity.getRenderElement(0); element.getShape().reset(); - element.shouldDraw = renderer.project3D(element.getShape(), element.getPolygon(), false, renderProperties); + element.shouldDraw = renderer.project3D(element.getShape(), element.getPolygon(), false, renderProperties); } @Override public void render(GlobeRenderer renderer, Graphics2D graphics, RenderEntity entity, RenderProperties renderProperties) { RenderElement element = entity.getRenderElement(0); - if(!element.shouldDraw){ + if (!element.shouldDraw) { return; } graphics.setColor(FeatureGeoPolygons.oceanColor); diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/globe/feature/RenderEntity.java b/GlobalQuakeCore/src/main/java/globalquake/ui/globe/feature/RenderEntity.java index a670e0510..290ea902d 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/globe/feature/RenderEntity.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/globe/feature/RenderEntity.java @@ -6,10 +6,10 @@ public class RenderEntity { private final RenderElement[] renderElements; - public RenderEntity(E original, int renderElements){ + public RenderEntity(E original, int renderElements) { this.original = original; this.renderElements = new RenderElement[renderElements]; - for(int i = 0; i < renderElements; i++){ + for (int i = 0; i < renderElements; i++) { this.renderElements[i] = new RenderElement(); } } @@ -18,7 +18,7 @@ public E getOriginal() { return original; } - public RenderElement getRenderElement(int index){ + public RenderElement getRenderElement(int index) { return renderElements[index]; } diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/globe/feature/RenderFeature.java b/GlobalQuakeCore/src/main/java/globalquake/ui/globe/feature/RenderFeature.java index e45839e16..65d753e60 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/globe/feature/RenderFeature.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/globe/feature/RenderFeature.java @@ -25,29 +25,29 @@ public abstract class RenderFeature { private ConcurrentHashMap> entities = new ConcurrentHashMap<>(); private ConcurrentHashMap> entities_temp = new ConcurrentHashMap<>(); - public RenderFeature(int renderElements){ + public RenderFeature(int renderElements) { this.renderElements = renderElements; } - private void swapEntities(){ + private void swapEntities() { var entities3 = entities; entities = entities_temp; entities_temp = entities3; } - public final boolean updateEntities(){ + public final boolean updateEntities() { int hash; - if(getElements() instanceof Monitorable){ + if (getElements() instanceof Monitorable) { hash = ((Monitorable) getElements()).getMonitorState(); - }else { + } else { hash = getElements().hashCode(); - if(needsUpdateEntities() && !warned){ + if (needsUpdateEntities() && !warned) { Logger.warn("Render Features with non-monitorable elements might not be updating correctly! %s".formatted(this)); warned = true; } } - if(hash != lastHash) { + if (hash != lastHash) { entities_temp.clear(); getElements().parallelStream().forEach(element -> entities_temp.put(element, entities.getOrDefault(element, new RenderEntity<>(element, renderElements)))); swapEntities(); @@ -60,7 +60,7 @@ public final boolean updateEntities(){ return false; } - public boolean isEnabled(RenderProperties renderProperties){ + public boolean isEnabled(RenderProperties renderProperties) { return true; } @@ -68,15 +68,15 @@ public boolean needsUpdateEntities() { return getEntities().isEmpty(); } - public boolean needsCreatePolygon(RenderEntity entity, boolean propertiesChanged){ + public boolean needsCreatePolygon(RenderEntity entity, boolean propertiesChanged) { return Arrays.stream(entity.getRenderElements()).anyMatch(renderElement -> renderElement.getPolygon() == null); } - public boolean needsProject(RenderEntity entity, boolean propertiesChanged){ + public boolean needsProject(RenderEntity entity, boolean propertiesChanged) { return propertiesChanged || Arrays.stream(entity.getRenderElements()).anyMatch(renderElement -> renderElement.getShape() == null); } - public final boolean propertiesChanged(RenderProperties properties){ + public final boolean propertiesChanged(RenderProperties properties) { boolean result = properties != lastProperties; lastProperties = properties; return result; @@ -86,7 +86,7 @@ public final void process(GlobeRenderer renderer, RenderProperties renderPropert boolean entitiesUpdated = false; boolean settingsChanged = Settings.changes != settingsChanges; settingsChanges = Settings.changes; - if(needsUpdateEntities() || settingsChanged) { + if (needsUpdateEntities() || settingsChanged) { entitiesUpdated = updateEntities(); } @@ -94,9 +94,9 @@ public final void process(GlobeRenderer renderer, RenderProperties renderPropert boolean finalEntitiesUpdated = entitiesUpdated; getEntities().parallelStream().forEach(entity -> { - if(finalEntitiesUpdated || settingsChanged || needsCreatePolygon(entity, propertiesChanged)) + if (finalEntitiesUpdated || settingsChanged || needsCreatePolygon(entity, propertiesChanged)) createPolygon(renderer, entity, renderProperties); - if(finalEntitiesUpdated || settingsChanged || needsProject(entity, propertiesChanged)) + if (finalEntitiesUpdated || settingsChanged || needsProject(entity, propertiesChanged)) project(renderer, entity, renderProperties); }); } @@ -111,7 +111,9 @@ public final Collection> getEntities() { public abstract void render(GlobeRenderer renderer, Graphics2D graphics, RenderEntity entity, RenderProperties renderProperties); - public boolean isEntityVisible(RenderEntity entity) {return true;} + public boolean isEntityVisible(RenderEntity entity) { + return true; + } public void renderAll(GlobeRenderer renderer, Graphics2D graphics, RenderProperties properties) { getEntities().stream().filter(this::isEntityVisible).forEach(entity -> { diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/settings/AlertSettingsPanel.java b/GlobalQuakeCore/src/main/java/globalquake/ui/settings/AlertSettingsPanel.java index 21817fcdd..7d3d3e803 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/settings/AlertSettingsPanel.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/settings/AlertSettingsPanel.java @@ -50,7 +50,7 @@ private Component createPingsTab() { createPossibleShakingPanel(panel); createEarthquakeSoundsPanel(panel); - JPanel eewThresholdPanel = new JPanel(new GridLayout(3,1)); + JPanel eewThresholdPanel = new JPanel(new GridLayout(3, 1)); eewThresholdPanel.setBorder(BorderFactory.createTitledBorder("EEW")); eewThresholdPanel.add(new JLabel("Trigger eew_warning.wav sound effect if estimated intensity at land reaches: ")); @@ -62,7 +62,7 @@ private Component createPingsTab() { maxClusterLevelPanel.add(new JLabel("and the associated Cluster has level at least: ")); comboBoxEEWClusterLevel = new JComboBox<>(); - for(int i : IntStream.rangeClosed(0, Cluster.MAX_LEVEL).toArray()){ + for (int i : IntStream.rangeClosed(0, Cluster.MAX_LEVEL).toArray()) { comboBoxEEWClusterLevel.addItem(i); } @@ -81,9 +81,9 @@ private Component createPingsTab() { private void createEarthquakeSoundsPanel(JPanel panel) { chkBoxEarthquakeSounds = new JCheckBox("Play sound alerts if earthquake is bigger than (magnitude): ", Settings.enableEarthquakeSounds); - textFieldQuakeMinMag = new JTextField(String.valueOf(Settings.earthquakeSoundsMinMagnitude) ,12); + textFieldQuakeMinMag = new JTextField(String.valueOf(Settings.earthquakeSoundsMinMagnitude), 12); textFieldQuakeMinMag.setEnabled(chkBoxEarthquakeSounds.isSelected()); - textFieldQuakeMaxDist = new JTextField("1",12); + textFieldQuakeMaxDist = new JTextField("1", 12); textFieldQuakeMaxDist.setEnabled(chkBoxEarthquakeSounds.isSelected()); chkBoxEarthquakeSounds.addChangeListener(changeEvent -> { @@ -91,7 +91,7 @@ private void createEarthquakeSoundsPanel(JPanel panel) { textFieldQuakeMaxDist.setEnabled(chkBoxEarthquakeSounds.isSelected()); }); - JPanel earthquakePanel = new JPanel(new GridLayout(2,1)); + JPanel earthquakePanel = new JPanel(new GridLayout(2, 1)); earthquakePanel.setBorder(BorderFactory.createTitledBorder("Earthquake alerts")); JPanel quakeMagpanel = new JPanel(); @@ -113,13 +113,13 @@ private void createEarthquakeSoundsPanel(JPanel panel) { private void createPossibleShakingPanel(JPanel panel) { chkBoxPossibleShaking = new JCheckBox("Play sound if possible shaking is detected closer than (%s): ".formatted(Settings.getSelectedDistanceUnit().getShortName()), Settings.alertPossibleShaking); - textFieldPossibleShakingDistance = new JTextField(String.valueOf(Settings.alertPossibleShakingDistance) ,12); + textFieldPossibleShakingDistance = new JTextField(String.valueOf(Settings.alertPossibleShakingDistance), 12); textFieldPossibleShakingDistance.setEnabled(chkBoxPossibleShaking.isSelected()); chkBoxPossibleShaking.addChangeListener(changeEvent -> textFieldPossibleShakingDistance.setEnabled(chkBoxPossibleShaking.isSelected())); - JPanel possibleShakingPanel = new JPanel(new GridLayout(1,1)); + JPanel possibleShakingPanel = new JPanel(new GridLayout(1, 1)); possibleShakingPanel.setBorder(BorderFactory.createTitledBorder("Possible shaking detection")); JPanel regionMagPanel = new JPanel(); @@ -168,7 +168,7 @@ private Component createAlertDialogSettings() { textFieldLocalDist.setEnabled(chkBoxLocal.isSelected()); chkBoxLocal.addChangeListener(changeEvent -> textFieldLocalDist.setEnabled(chkBoxLocal.isSelected())); - JPanel localPanel = new JPanel(new GridLayout(1,1)); + JPanel localPanel = new JPanel(new GridLayout(1, 1)); localPanel.setBorder(BorderFactory.createTitledBorder("Local area")); JPanel nearbyPanel = new JPanel(); @@ -180,9 +180,9 @@ private Component createAlertDialogSettings() { panel.add(localPanel); chkBoxRegion = new JCheckBox("Alert earthquakes larger than (magnitude): ", Settings.alertRegion); - textFieldRegionMag = new JTextField(String.valueOf(Settings.alertRegionMag) ,12); + textFieldRegionMag = new JTextField(String.valueOf(Settings.alertRegionMag), 12); textFieldRegionMag.setEnabled(chkBoxRegion.isSelected()); - textFieldRegionDist = new JTextField("1",12); + textFieldRegionDist = new JTextField("1", 12); textFieldRegionDist.setEnabled(chkBoxRegion.isSelected()); chkBoxRegion.addChangeListener(changeEvent -> { @@ -190,7 +190,7 @@ private Component createAlertDialogSettings() { textFieldRegionDist.setEnabled(chkBoxRegion.isSelected()); }); - JPanel regionPanel = new JPanel(new GridLayout(2,1)); + JPanel regionPanel = new JPanel(new GridLayout(2, 1)); regionPanel.setBorder(BorderFactory.createTitledBorder("Regional area")); JPanel regionMagPanel = new JPanel(); @@ -210,7 +210,7 @@ private Component createAlertDialogSettings() { panel.add(regionPanel); - JPanel globalPanel = new JPanel(new GridLayout(1,1)); + JPanel globalPanel = new JPanel(new GridLayout(1, 1)); globalPanel.setBorder(BorderFactory.createTitledBorder("Global")); checkBoxGlobal = new JCheckBox("Alert earthquakes larger than (magnitude): ", Settings.alertGlobal); @@ -228,10 +228,10 @@ private Component createAlertDialogSettings() { panel.add(globalPanel); - JPanel panel2 = new JPanel(new GridLayout(2,1)); + JPanel panel2 = new JPanel(new GridLayout(2, 1)); - panel2.add( chkBoxFocus = new JCheckBox("Focus main window if the conditions above are met", Settings.focusOnEvent)); - panel2.add( chkBoxJumpToAlert = new JCheckBox("Jump directly to the warned event", Settings.jumpToAlert)); + panel2.add(chkBoxFocus = new JCheckBox("Focus main window if the conditions above are met", Settings.focusOnEvent)); + panel2.add(chkBoxJumpToAlert = new JCheckBox("Jump directly to the warned event", Settings.jumpToAlert)); panel.add(panel2); diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/settings/DebugSettingsPanel.java b/GlobalQuakeCore/src/main/java/globalquake/ui/settings/DebugSettingsPanel.java index a795fb4bd..73634dcf5 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/settings/DebugSettingsPanel.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/settings/DebugSettingsPanel.java @@ -15,7 +15,7 @@ public class DebugSettingsPanel extends SettingsPanel { public DebugSettingsPanel() { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - setBorder(new EmptyBorder(5,5,5,5)); + setBorder(new EmptyBorder(5, 5, 5, 5)); add(chkBoxReports = new JCheckBox("Enable Earthquake Reports", Settings.reportsEnabled)); add(new JLabel(" Reports will be stored in %s".formatted(EarthquakeReporter.ANALYSIS_FOLDER.getPath()))); diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/settings/GeneralSettingsPanel.java b/GlobalQuakeCore/src/main/java/globalquake/ui/settings/GeneralSettingsPanel.java index b0bafb549..3bf73674c 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/settings/GeneralSettingsPanel.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/settings/GeneralSettingsPanel.java @@ -17,206 +17,206 @@ import java.util.Objects; public class GeneralSettingsPanel extends SettingsPanel { - private JComboBox comboBoxScale; - private JCheckBox chkBoxHomeLoc; + private JComboBox comboBoxScale; + private JCheckBox chkBoxHomeLoc; - private JTextField textFieldLat; - private JTextField textFieldLon; - private JComboBox distanceUnitJComboBox; - private JComboBox timezoneCombobox; + private JTextField textFieldLat; + private JTextField textFieldLon; + private JComboBox distanceUnitJComboBox; + private JComboBox timezoneCombobox; - private JSlider sliderStoreTime; + private JSlider sliderStoreTime; - public GeneralSettingsPanel(SettingsFrame settingsFrame) { - setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + public GeneralSettingsPanel(SettingsFrame settingsFrame) { + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - createHomeLocationSettings(); - //createAlertsDialogSettings(); - add(createIntensitySettingsPanel()); - createOtherSettings(settingsFrame); - add(createSettingStoreTime()); - } + createHomeLocationSettings(); + //createAlertsDialogSettings(); + add(createIntensitySettingsPanel()); + createOtherSettings(settingsFrame); + add(createSettingStoreTime()); + } - private void createOtherSettings(SettingsFrame settingsFrame) { - JPanel panel = new JPanel(); - panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); - panel.setBorder(BorderFactory.createTitledBorder("Other")); + private void createOtherSettings(SettingsFrame settingsFrame) { + JPanel panel = new JPanel(); + panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); + panel.setBorder(BorderFactory.createTitledBorder("Other")); - JPanel row1 = new JPanel(); + JPanel row1 = new JPanel(); - row1.add(new JLabel("Distance units: ")); + row1.add(new JLabel("Distance units: ")); - distanceUnitJComboBox = new JComboBox<>(DistanceUnit.values()); - distanceUnitJComboBox.setSelectedIndex(Math.max(0, Math.min(distanceUnitJComboBox.getItemCount() - 1, Settings.distanceUnitsIndex))); + distanceUnitJComboBox = new JComboBox<>(DistanceUnit.values()); + distanceUnitJComboBox.setSelectedIndex(Math.max(0, Math.min(distanceUnitJComboBox.getItemCount() - 1, Settings.distanceUnitsIndex))); - distanceUnitJComboBox.addItemListener(itemEvent -> { - Settings.distanceUnitsIndex = distanceUnitJComboBox.getSelectedIndex(); - settingsFrame.refreshUI(); + distanceUnitJComboBox.addItemListener(itemEvent -> { + Settings.distanceUnitsIndex = distanceUnitJComboBox.getSelectedIndex(); + settingsFrame.refreshUI(); }); - row1.add(distanceUnitJComboBox); + row1.add(distanceUnitJComboBox); - JPanel row2 = new JPanel(); + JPanel row2 = new JPanel(); - row2.add(new JLabel("Timezone: ")); - Comparator zoneIdComparator = Comparator.comparingInt(zone -> zone.getRules().getOffset(Instant.now()).getTotalSeconds()); + row2.add(new JLabel("Timezone: ")); + Comparator zoneIdComparator = Comparator.comparingInt(zone -> zone.getRules().getOffset(Instant.now()).getTotalSeconds()); - // Use a DefaultComboBoxModel for better control and management - DefaultComboBoxModel timezoneModel = new DefaultComboBoxModel<>(); + // Use a DefaultComboBoxModel for better control and management + DefaultComboBoxModel timezoneModel = new DefaultComboBoxModel<>(); - // Populate the model with available timezones and sort them using the custom Comparator - ZoneId.getAvailableZoneIds().stream() - .map(ZoneId::of) - .sorted(zoneIdComparator) - .forEach(timezoneModel::addElement); + // Populate the model with available timezones and sort them using the custom Comparator + ZoneId.getAvailableZoneIds().stream() + .map(ZoneId::of) + .sorted(zoneIdComparator) + .forEach(timezoneModel::addElement); - // Create the JComboBox with the populated and sorted model - timezoneCombobox = new JComboBox<>(timezoneModel); + // Create the JComboBox with the populated and sorted model + timezoneCombobox = new JComboBox<>(timezoneModel); - // this assures that default timezone will always be selected - timezoneCombobox.setSelectedItem(ZoneId.systemDefault()); + // this assures that default timezone will always be selected + timezoneCombobox.setSelectedItem(ZoneId.systemDefault()); - // if theres valid timezone in the settings then it will be selected - timezoneCombobox.setSelectedItem(ZoneId.of(Settings.timezoneStr)); + // if theres valid timezone in the settings then it will be selected + timezoneCombobox.setSelectedItem(ZoneId.of(Settings.timezoneStr)); - // Add the JComboBox to your UI - row2.add(timezoneCombobox); + // Add the JComboBox to your UI + row2.add(timezoneCombobox); - timezoneCombobox.setRenderer(new DefaultListCellRenderer(){ - @Override - public Component getListCellRendererComponent(JList list, Object value, int index, - boolean isSelected, boolean cellHasFocus) { - JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + timezoneCombobox.setRenderer(new DefaultListCellRenderer() { + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, + boolean isSelected, boolean cellHasFocus) { + JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - if (value instanceof ZoneId zoneId) { + if (value instanceof ZoneId zoneId) { String offset = zoneId.getRules().getOffset(Instant.now()).toString(); - label.setText(String.format("%s (%s)", zoneId, offset)); - } + label.setText(String.format("%s (%s)", zoneId, offset)); + } - return label; - } - }); + return label; + } + }); - timezoneCombobox.addActionListener(new AbstractAction() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - Settings.timezoneStr = ((ZoneId) Objects.requireNonNull(timezoneCombobox.getSelectedItem())).getId(); - Settings.initTimezoneSettings(); - } - }); + timezoneCombobox.addActionListener(new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + Settings.timezoneStr = ((ZoneId) Objects.requireNonNull(timezoneCombobox.getSelectedItem())).getId(); + Settings.initTimezoneSettings(); + } + }); - row2.add(timezoneCombobox); + row2.add(timezoneCombobox); - panel.add(row1); - panel.add(row2); + panel.add(row1); + panel.add(row2); - add(panel); - } + add(panel); + } - private void createHomeLocationSettings() { - JPanel outsidePanel = new JPanel(new BorderLayout()); - outsidePanel.setBorder(BorderFactory.createTitledBorder("Home location settings")); + private void createHomeLocationSettings() { + JPanel outsidePanel = new JPanel(new BorderLayout()); + outsidePanel.setBorder(BorderFactory.createTitledBorder("Home location settings")); - JPanel homeLocationPanel = new JPanel(); - homeLocationPanel.setLayout(new GridLayout(2,1)); + JPanel homeLocationPanel = new JPanel(); + homeLocationPanel.setLayout(new GridLayout(2, 1)); - JLabel lblLat = new JLabel("Home Latitude: "); - JLabel lblLon = new JLabel("Home Longitude: "); + JLabel lblLat = new JLabel("Home Latitude: "); + JLabel lblLon = new JLabel("Home Longitude: "); - textFieldLat = new JTextField(20); - textFieldLat.setText(String.format("%s", Settings.homeLat)); - textFieldLat.setColumns(10); + textFieldLat = new JTextField(20); + textFieldLat.setText(String.format("%s", Settings.homeLat)); + textFieldLat.setColumns(10); - textFieldLon = new JTextField(20); - textFieldLon.setText(String.format("%s", Settings.homeLon)); - textFieldLon.setColumns(10); + textFieldLon = new JTextField(20); + textFieldLon.setText(String.format("%s", Settings.homeLon)); + textFieldLon.setColumns(10); - JPanel latPanel = new JPanel(); - //latPanel.setLayout(new BoxLayout(latPanel, BoxLayout.X_AXIS)); + JPanel latPanel = new JPanel(); + //latPanel.setLayout(new BoxLayout(latPanel, BoxLayout.X_AXIS)); - latPanel.add(lblLat); - latPanel.add(textFieldLat); + latPanel.add(lblLat); + latPanel.add(textFieldLat); - JPanel lonPanel = new JPanel(); - //lonPanel.setLayout(new BoxLayout(lonPanel, BoxLayout.X_AXIS)); + JPanel lonPanel = new JPanel(); + //lonPanel.setLayout(new BoxLayout(lonPanel, BoxLayout.X_AXIS)); - lonPanel.add(lblLon); - lonPanel.add(textFieldLon); + lonPanel.add(lblLon); + lonPanel.add(textFieldLon); - homeLocationPanel.add(latPanel); - homeLocationPanel.add(lonPanel); + homeLocationPanel.add(latPanel); + homeLocationPanel.add(lonPanel); - JTextArea infoLocation = new JTextArea("Home location will be used for playing additional alarm \n sounds if an earthquake occurs nearby"); - infoLocation.setBorder(new EmptyBorder(5,5,5,5)); - infoLocation.setLineWrap(true); - infoLocation.setEditable(false); - infoLocation.setBackground(homeLocationPanel.getBackground()); + JTextArea infoLocation = new JTextArea("Home location will be used for playing additional alarm \n sounds if an earthquake occurs nearby"); + infoLocation.setBorder(new EmptyBorder(5, 5, 5, 5)); + infoLocation.setLineWrap(true); + infoLocation.setEditable(false); + infoLocation.setBackground(homeLocationPanel.getBackground()); - chkBoxHomeLoc = new JCheckBox("Display home location"); - chkBoxHomeLoc.setSelected(Settings.displayHomeLocation); - outsidePanel.add(chkBoxHomeLoc); + chkBoxHomeLoc = new JCheckBox("Display home location"); + chkBoxHomeLoc.setSelected(Settings.displayHomeLocation); + outsidePanel.add(chkBoxHomeLoc); - outsidePanel.add(homeLocationPanel, BorderLayout.NORTH); - outsidePanel.add(infoLocation, BorderLayout.CENTER); - outsidePanel.add(chkBoxHomeLoc, BorderLayout.SOUTH); + outsidePanel.add(homeLocationPanel, BorderLayout.NORTH); + outsidePanel.add(infoLocation, BorderLayout.CENTER); + outsidePanel.add(chkBoxHomeLoc, BorderLayout.SOUTH); - add(outsidePanel); - } + add(outsidePanel); + } - private Component createSettingStoreTime() { - sliderStoreTime = HypocenterAnalysisSettingsPanel.createSettingsSlider(2, 20, 2, 1); + private Component createSettingStoreTime() { + sliderStoreTime = HypocenterAnalysisSettingsPanel.createSettingsSlider(2, 20, 2, 1); - JLabel label = new JLabel(); - ChangeListener changeListener = changeEvent -> label.setText("Waveform data storage time (minutes): %d".formatted( - sliderStoreTime.getValue())); + JLabel label = new JLabel(); + ChangeListener changeListener = changeEvent -> label.setText("Waveform data storage time (minutes): %d".formatted( + sliderStoreTime.getValue())); - sliderStoreTime.addChangeListener(changeListener); + sliderStoreTime.addChangeListener(changeListener); - sliderStoreTime.setValue(Settings.logsStoreTimeMinutes); - changeListener.stateChanged(null); + sliderStoreTime.setValue(Settings.logsStoreTimeMinutes); + changeListener.stateChanged(null); - return HypocenterAnalysisSettingsPanel.createCoolLayout(sliderStoreTime, label, "5", - """ + return HypocenterAnalysisSettingsPanel.createCoolLayout(sliderStoreTime, label, "5", + """ In GlobalQuake, waveform data poses the highest demand on your system's RAM. If you're encountering memory constraints, you have two options: either reduce the number of selected stations or lower this specific value. """); - } + } - private JPanel createIntensitySettingsPanel() { - JPanel panel = new JPanel(new GridLayout(2,1)); - panel.setBorder(BorderFactory.createTitledBorder("Intensity Scale")); + private JPanel createIntensitySettingsPanel() { + JPanel panel = new JPanel(new GridLayout(2, 1)); + panel.setBorder(BorderFactory.createTitledBorder("Intensity Scale")); - comboBoxScale = new JComboBox<>(IntensityScales.INTENSITY_SCALES); - comboBoxScale.setSelectedIndex(Settings.intensityScaleIndex); + comboBoxScale = new JComboBox<>(IntensityScales.INTENSITY_SCALES); + comboBoxScale.setSelectedIndex(Settings.intensityScaleIndex); - JPanel div = new JPanel(); - div.add(comboBoxScale); - panel.add(div, BorderLayout.CENTER); + JPanel div = new JPanel(); + div.add(comboBoxScale); + panel.add(div, BorderLayout.CENTER); - JLabel lbl = new JLabel(); - lbl.setFont(new Font("Calibri", Font.PLAIN, 13)); - lbl.setText("Keep in mind that the displayed intensities are estimated, not measured"); + JLabel lbl = new JLabel(); + lbl.setFont(new Font("Calibri", Font.PLAIN, 13)); + lbl.setText("Keep in mind that the displayed intensities are estimated, not measured"); - panel.add(lbl, BorderLayout.SOUTH); + panel.add(lbl, BorderLayout.SOUTH); - return panel; - } + return panel; + } - @Override - public void save() { - Settings.homeLat = parseDouble(textFieldLat.getText(), "Home latitude", -90, 90); - Settings.homeLon = parseDouble(textFieldLon.getText(), "Home longitude", -180, 180); - Settings.intensityScaleIndex = comboBoxScale.getSelectedIndex(); - Settings.displayHomeLocation = chkBoxHomeLoc.isSelected(); - Settings.distanceUnitsIndex = distanceUnitJComboBox.getSelectedIndex(); - Settings.timezoneStr = ((ZoneId) Objects.requireNonNull(timezoneCombobox.getSelectedItem())).getId(); - Settings.logsStoreTimeMinutes = sliderStoreTime.getValue(); - } + @Override + public void save() { + Settings.homeLat = parseDouble(textFieldLat.getText(), "Home latitude", -90, 90); + Settings.homeLon = parseDouble(textFieldLon.getText(), "Home longitude", -180, 180); + Settings.intensityScaleIndex = comboBoxScale.getSelectedIndex(); + Settings.displayHomeLocation = chkBoxHomeLoc.isSelected(); + Settings.distanceUnitsIndex = distanceUnitJComboBox.getSelectedIndex(); + Settings.timezoneStr = ((ZoneId) Objects.requireNonNull(timezoneCombobox.getSelectedItem())).getId(); + Settings.logsStoreTimeMinutes = sliderStoreTime.getValue(); + } - @Override - public String getTitle() { - return "General"; - } + @Override + public String getTitle() { + return "General"; + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/settings/GraphicsSettingsPanel.java b/GlobalQuakeCore/src/main/java/globalquake/ui/settings/GraphicsSettingsPanel.java index 33146b318..11459aba4 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/settings/GraphicsSettingsPanel.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/settings/GraphicsSettingsPanel.java @@ -11,7 +11,7 @@ import java.time.Instant; import java.time.format.DateTimeFormatter; -public class GraphicsSettingsPanel extends SettingsPanel{ +public class GraphicsSettingsPanel extends SettingsPanel { private JCheckBox chkBoxScheme; private JSlider sliderFpsIdle; @@ -71,7 +71,7 @@ public GraphicsSettingsPanel() { private Component createCinemaModeTab() { JPanel panel = new JPanel(); - panel.setBorder(new EmptyBorder(6,6,6,6)); + panel.setBorder(new EmptyBorder(6, 6, 6, 6)); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); textFieldTime = new JTextField(String.valueOf(Settings.cinemaModeSwitchTime), 12); @@ -83,12 +83,12 @@ private Component createCinemaModeTab() { panel.add(timePanel); JPanel zoomPanel = new JPanel(); - zoomPanel.setBorder(new EmptyBorder(5,5,5,5)); + zoomPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); zoomPanel.setLayout(new BoxLayout(zoomPanel, BoxLayout.X_AXIS)); zoomPanel.add(new JLabel("Zoom multiplier (move right to zoom in):")); - sliderZoomMul = new JSlider(JSlider.HORIZONTAL, 20,500, Settings.cinemaModeZoomMultiplier); + sliderZoomMul = new JSlider(JSlider.HORIZONTAL, 20, 500, Settings.cinemaModeZoomMultiplier); sliderZoomMul.setMinorTickSpacing(10); sliderZoomMul.setMajorTickSpacing(50); sliderZoomMul.setPaintTicks(true); @@ -120,11 +120,11 @@ private Component createGeneralTab() { sliderFpsIdle.setPaintTicks(true); sliderFpsIdle.setMajorTickSpacing(10); sliderFpsIdle.setMinorTickSpacing(5); - sliderFpsIdle.setBorder(new EmptyBorder(5,5,10,5)); + sliderFpsIdle.setBorder(new EmptyBorder(5, 5, 10, 5)); - JLabel label = new JLabel("FPS limit: "+sliderFpsIdle.getValue()); + JLabel label = new JLabel("FPS limit: " + sliderFpsIdle.getValue()); - sliderFpsIdle.addChangeListener(changeEvent -> label.setText("FPS limit: "+sliderFpsIdle.getValue())); + sliderFpsIdle.addChangeListener(changeEvent -> label.setText("FPS limit: " + sliderFpsIdle.getValue())); performancePanel.add(label); performancePanel.add(sliderFpsIdle); @@ -136,7 +136,7 @@ private Component createGeneralTab() { comboBoxDateFormat = new JComboBox<>(); Instant now = Instant.now(); - for(DateTimeFormatter formatter: Settings.DATE_FORMATS){ + for (DateTimeFormatter formatter : Settings.DATE_FORMATS) { comboBoxDateFormat.addItem(formatter.format(now)); } @@ -148,7 +148,7 @@ private Component createGeneralTab() { panel.add(dateFormatPanel); - JPanel mainWindowPanel = new JPanel(new GridLayout(4,2)); + JPanel mainWindowPanel = new JPanel(new GridLayout(4, 2)); mainWindowPanel.setBorder(new TitledBorder("Main Screen")); mainWindowPanel.add(chkBoxDisplaySystemInfo = new JCheckBox("Display system info", Settings.displaySystemInfo)); @@ -162,7 +162,7 @@ private Component createGeneralTab() { panel.add(mainWindowPanel); - JPanel clustersPanel = new JPanel(new GridLayout(3,1)); + JPanel clustersPanel = new JPanel(new GridLayout(3, 1)); clustersPanel.setBorder(new TitledBorder("Cluster settings")); clustersPanel.add(chkBoxClusterRoots = new JCheckBox("Display Clusters (possible shaking locations)", Settings.displayClusterRoots)); @@ -171,7 +171,7 @@ private Component createGeneralTab() { panel.add(clustersPanel); - JPanel antialiasPanel = new JPanel(new GridLayout(3,1)); + JPanel antialiasPanel = new JPanel(new GridLayout(3, 1)); antialiasPanel.setBorder(new TitledBorder("Antialiasing")); antialiasPanel.add(chkBoxAntialiasStations = new JCheckBox("Stations", Settings.antialiasing)); antialiasPanel.add(chkBoxAntialiasClusters = new JCheckBox("Clusters", Settings.antialiasingClusters)); @@ -190,7 +190,7 @@ private Component createEventsTab() { JPanel timePanel = new JPanel(); timePanel.setLayout(new BoxLayout(timePanel, BoxLayout.X_AXIS)); - timePanel.setBorder(new EmptyBorder(5,5,5,5)); + timePanel.setBorder(new EmptyBorder(5, 5, 5, 5)); chkBoxEnableTimeFilter = new JCheckBox("Don't display older than (hours): "); chkBoxEnableTimeFilter.setSelected(Settings.oldEventsTimeFilterEnabled); @@ -206,7 +206,7 @@ private Component createEventsTab() { eventsPanel.add(timePanel); JPanel magnitudePanel = new JPanel(); - magnitudePanel.setBorder(new EmptyBorder(5,5,5,5)); + magnitudePanel.setBorder(new EmptyBorder(5, 5, 5, 5)); magnitudePanel.setLayout(new BoxLayout(magnitudePanel, BoxLayout.X_AXIS)); chkBoxEnableMagnitudeFilter = new JCheckBox("Don't display smaller than (magnitude): "); @@ -224,7 +224,7 @@ private Component createEventsTab() { JPanel removeOldPanel = new JPanel(); removeOldPanel.setLayout(new BoxLayout(removeOldPanel, BoxLayout.X_AXIS)); - removeOldPanel.setBorder(new EmptyBorder(5,5,5,5)); + removeOldPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); textFieldMaxArchived = new JTextField(Settings.maxArchivedQuakes.toString(), 12); @@ -235,10 +235,10 @@ private Component createEventsTab() { JPanel opacityPanel = new JPanel(); - opacityPanel.setBorder(new EmptyBorder(5,5,5,5)); + opacityPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); opacityPanel.setLayout(new BoxLayout(opacityPanel, BoxLayout.X_AXIS)); - sliderOpacity = new JSlider(JSlider.HORIZONTAL,0,100, Settings.oldEventsOpacity.intValue()); + sliderOpacity = new JSlider(JSlider.HORIZONTAL, 0, 100, Settings.oldEventsOpacity.intValue()); sliderOpacity.setMajorTickSpacing(10); sliderOpacity.setMinorTickSpacing(2); sliderOpacity.setPaintTicks(true); @@ -272,7 +272,7 @@ private Component createEventsTab() { public void actionPerformed(ActionEvent actionEvent) { for (int i = 0; i < colorButtons.length; i++) { JRadioButton button = colorButtons[i]; - if(button.isSelected()){ + if (button.isSelected()) { Settings.selectedEventColorIndex = i; break; } @@ -280,7 +280,7 @@ public void actionPerformed(ActionEvent actionEvent) { } }; - for(JRadioButton button : colorButtons) { + for (JRadioButton button : colorButtons) { bg.add(button); button.addActionListener(colorButtonActionListener); colorsPanel.add(button); @@ -294,7 +294,7 @@ public void actionPerformed(ActionEvent actionEvent) { qualityFilterPanel.add(new JLabel("Only show old events with quality equal or better than: ")); comboBoxQuality = new JComboBox<>(QualityClass.values()); - comboBoxQuality.setSelectedIndex(Math.max(0, Math.min(QualityClass.values().length-1, Settings.qualityFilter))); + comboBoxQuality.setSelectedIndex(Math.max(0, Math.min(QualityClass.values().length - 1, Settings.qualityFilter))); qualityFilterPanel.add(comboBoxQuality); eventsPanel.add(qualityFilterPanel); @@ -309,7 +309,7 @@ private Component createStationsTab() { stationsPanel.setLayout(new BoxLayout(stationsPanel, BoxLayout.Y_AXIS)); stationsPanel.setBorder(BorderFactory.createTitledBorder("Stations")); - JPanel checkBoxes = new JPanel(new GridLayout(1,2)); + JPanel checkBoxes = new JPanel(new GridLayout(1, 2)); checkBoxes.setBorder(BorderFactory.createTitledBorder("Appearance")); chkBoxScheme = new JCheckBox("Use old color scheme (exaggerated)"); @@ -336,7 +336,7 @@ private Component createStationsTab() { public void actionPerformed(ActionEvent actionEvent) { for (int i = 0; i < buttons.length; i++) { JRadioButton button = buttons[i]; - if(button.isSelected()){ + if (button.isSelected()) { Settings.stationsShapeIndex = i; break; } @@ -344,7 +344,7 @@ public void actionPerformed(ActionEvent actionEvent) { } }; - for(JRadioButton button : buttons){ + for (JRadioButton button : buttons) { buttonGroup.add(button); stationsShapePanel.add(button); button.addActionListener(shapeActionListener); @@ -354,7 +354,7 @@ public void actionPerformed(ActionEvent actionEvent) { stationsPanel.add(stationsShapePanel); - JPanel intensityPanel = new JPanel(new GridLayout(2,1)); + JPanel intensityPanel = new JPanel(new GridLayout(2, 1)); intensityPanel.add(new JLabel("Display station's intensity label at zoom level (0 very close, 200 very far):")); sliderIntensityZoom = new JSlider(SwingConstants.HORIZONTAL, 0, 200, (int) (Settings.stationIntensityVisibilityZoomLevel * 100)); @@ -371,7 +371,7 @@ public void actionPerformed(ActionEvent actionEvent) { intensityPanel.add(sliderIntensityZoom); stationsPanel.add(intensityPanel); - JPanel stationSizePanel = new JPanel(new GridLayout(2,1)); + JPanel stationSizePanel = new JPanel(new GridLayout(2, 1)); stationSizePanel.add(new JLabel("Stations size multiplier (100 default, 20 tiny, 300 huge):")); sliderStationsSize = new JSlider(SwingConstants.HORIZONTAL, 20, 300, (int) (Settings.stationsSizeMul * 100)); @@ -419,7 +419,7 @@ public void save() { Settings.maxArchivedQuakes = parseInt(textFieldMaxArchived.getText(), "Max number of archived quakes", 1, Integer.MAX_VALUE); - Settings.cinemaModeZoomMultiplier= sliderZoomMul.getValue(); + Settings.cinemaModeZoomMultiplier = sliderZoomMul.getValue(); Settings.cinemaModeSwitchTime = parseInt(textFieldTime.getText(), "Cinema mode switch time", 1, 3600); Settings.cinemaModeOnStartup = chkBoxEnableOnStartup.isSelected(); Settings.cinemaModeReenable = chkBoxReEnable.isSelected(); diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/settings/HypocenterAnalysisSettingsPanel.java b/GlobalQuakeCore/src/main/java/globalquake/ui/settings/HypocenterAnalysisSettingsPanel.java index e77a11352..96c8c9a61 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/settings/HypocenterAnalysisSettingsPanel.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/settings/HypocenterAnalysisSettingsPanel.java @@ -66,23 +66,23 @@ private Component createMinStationsSetting() { """); } - public static JPanel createCoolLayout(JSlider slider, JLabel label, String defaultValue, String explanation){ + public static JPanel createCoolLayout(JSlider slider, JLabel label, String defaultValue, String explanation) { JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(BorderFactory.createRaisedBevelBorder()); JPanel topPanel = new JPanel(new BorderLayout()); - topPanel.setBorder(new EmptyBorder(5,5,5,5)); + topPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); topPanel.add(label, BorderLayout.NORTH); topPanel.add(slider, BorderLayout.CENTER); - if(defaultValue != null) { + if (defaultValue != null) { JLabel labelDefault = new JLabel("Default value: " + defaultValue); labelDefault.setBorder(new EmptyBorder(8, 2, 0, 0)); topPanel.add(labelDefault, BorderLayout.SOUTH); } - if(explanation != null) { + if (explanation != null) { JTextArea textAreaExplanation = new JTextArea(explanation); textAreaExplanation.setBorder(new EmptyBorder(5, 5, 5, 5)); textAreaExplanation.setEditable(false); @@ -95,7 +95,7 @@ public static JPanel createCoolLayout(JSlider slider, JLabel label, String defau return panel; } - public static JSlider createSettingsSlider(int min, int max, int major, int minor){ + public static JSlider createSettingsSlider(int min, int max, int major, int minor) { JSlider slider = new JSlider(); slider.setMinimum(min); slider.setMaximum(max); @@ -145,13 +145,13 @@ private Component createSettingPWave() { return createCoolLayout(sliderPWaveInaccuracy, label, "%s ms".formatted(Settings.pWaveInaccuracyThresholdDefault), """ - This value determines the threshold value when the hypocenter finding\s - algorithm considers the arrival from current point to a station correct \s - or incorrect\s - Higher values are less restrictive and will lead to more false positives. - Lower values will force the algorithm to find more accurate hypocenter \s - and will lead to more false negatives. - """); + This value determines the threshold value when the hypocenter finding\s + algorithm considers the arrival from current point to a station correct \s + or incorrect\s + Higher values are less restrictive and will lead to more false positives. + Lower values will force the algorithm to find more accurate hypocenter \s + and will lead to more false negatives. + """); } @Override diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/settings/IntensityScaleSelector.java b/GlobalQuakeCore/src/main/java/globalquake/ui/settings/IntensityScaleSelector.java index 07c8c6f97..a04576ff5 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/settings/IntensityScaleSelector.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/settings/IntensityScaleSelector.java @@ -24,7 +24,7 @@ public IntensityScaleSelector(String text, int shakingLevelScale, int shakingLev @Override public void actionPerformed(ActionEvent actionEvent) { levelComboBox.removeAllItems(); - ((IntensityScale)shakingScaleComboBox.getSelectedItem()).getLevels().forEach(levelComboBox::addItem); + ((IntensityScale) shakingScaleComboBox.getSelectedItem()).getLevels().forEach(levelComboBox::addItem); } }); diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/settings/SettingsFrame.java b/GlobalQuakeCore/src/main/java/globalquake/ui/settings/SettingsFrame.java index a3838d497..16d34d2b5 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/settings/SettingsFrame.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/settings/SettingsFrame.java @@ -19,24 +19,24 @@ public class SettingsFrame extends GQFrame { - private final List panels = new LinkedList<>(); - private final boolean isClient; - private JTabbedPane tabbedPane; - - public static void main(String[] args) throws Exception{ - TauPTravelTimeCalculator.init(); - Sounds.load(); - GlobalQuake.prepare(new File("./.GlobalQuakeData/"), null); - EventQueue.invokeLater(() -> { + private final List panels = new LinkedList<>(); + private final boolean isClient; + private JTabbedPane tabbedPane; + + public static void main(String[] args) throws Exception { + TauPTravelTimeCalculator.init(); + Sounds.load(); + GlobalQuake.prepare(new File("./.GlobalQuakeData/"), null); + EventQueue.invokeLater(() -> { try { new SettingsFrame(null, false).setVisible(true); } catch (Exception e) { - Logger.error(e); + Logger.error(e); } }); - } + } - // settings panel instance tracker + // settings panel instance tracker private static SettingsFrame openInstance = null; public SettingsFrame(Component parent, boolean isClient) { @@ -49,8 +49,8 @@ public SettingsFrame(Component parent, boolean isClient) { openInstance = this; initialize(parent); - // Add a window listener to set openInstance to null when the frame is closed - addWindowListener(new WindowAdapter() { + // Add a window listener to set openInstance to null when the frame is closed + addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { openInstance = null; @@ -58,87 +58,85 @@ public void windowClosed(WindowEvent e) { }); } - // gets the instance of SettingsFrame - public static SettingsFrame getInstance() { + // gets the instance of SettingsFrame + public static SettingsFrame getInstance() { return openInstance; } - private void initialize(Component parent) { - setTitle(!isClient ? "GlobalQuake Settings" : "GlobalQuake Settings (Client)"); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + private void initialize(Component parent) { + setTitle(!isClient ? "GlobalQuake Settings" : "GlobalQuake Settings (Client)"); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - JPanel contentPanel = new JPanel(new BorderLayout()); - setContentPane(contentPanel); + JPanel contentPanel = new JPanel(new BorderLayout()); + setContentPane(contentPanel); - tabbedPane = new JTabbedPane(JTabbedPane.TOP); - contentPanel.add(tabbedPane, BorderLayout.CENTER); + tabbedPane = new JTabbedPane(JTabbedPane.TOP); + contentPanel.add(tabbedPane, BorderLayout.CENTER); - JPanel panel_1 = new JPanel(); - contentPanel.add(panel_1, BorderLayout.SOUTH); + JPanel panel_1 = new JPanel(); + contentPanel.add(panel_1, BorderLayout.SOUTH); - JButton btnCancel = new JButton("Cancel"); - panel_1.add(btnCancel); + JButton btnCancel = new JButton("Cancel"); + panel_1.add(btnCancel); - btnCancel.addActionListener(e -> dispose()); + btnCancel.addActionListener(e -> dispose()); - JButton btnSave = new JButton("Save"); - panel_1.add(btnSave); + JButton btnSave = new JButton("Save"); + panel_1.add(btnSave); - btnSave.addActionListener(e -> { + btnSave.addActionListener(e -> { for (SettingsPanel panel1 : panels) { try { panel1.save(); - } - catch(NumberFormatException exx){ - GlobalQuake.getErrorHandler().handleWarning(new RuntimeApplicationException("Failed to parse a number: %s".formatted(exx.getMessage()), exx)); - return; - } catch(RuntimeApplicationException exxx){ - GlobalQuake.getErrorHandler().handleWarning(exxx); - return; - } - catch (Exception ex) { - GlobalQuake.getErrorHandler().handleException(ex); + } catch (NumberFormatException exx) { + GlobalQuake.getErrorHandler().handleWarning(new RuntimeApplicationException("Failed to parse a number: %s".formatted(exx.getMessage()), exx)); + return; + } catch (RuntimeApplicationException exxx) { + GlobalQuake.getErrorHandler().handleWarning(exxx); + return; + } catch (Exception ex) { + GlobalQuake.getErrorHandler().handleException(ex); return; } } Settings.save(); - dispose(); + dispose(); }); - addPanels(); - - pack(); - setResizable(false); - setLocationRelativeTo(parent); - } - - - private void addPanels() { - panels.add(new GeneralSettingsPanel(this)); - panels.add(new GraphicsSettingsPanel()); - panels.add(new AlertSettingsPanel()); - panels.add(new SoundsSettingsPanel()); - if(!isClient) { - panels.add(new PerformanceSettingsPanel()); - panels.add(new HypocenterAnalysisSettingsPanel()); - } - panels.add(new DebugSettingsPanel()); - - for (SettingsPanel panel : panels) { - JScrollPane scrollPane = new JScrollPane(panel); - scrollPane.setPreferredSize(new Dimension(700, 500)); - scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - scrollPane.getVerticalScrollBar().setUnitIncrement(10); - tabbedPane.addTab(panel.getTitle(), scrollPane); - - javax.swing.SwingUtilities.invokeLater(() -> scrollPane.getVerticalScrollBar().setValue(0)); - } - } - - public void refreshUI() { - for (SettingsPanel panel : panels) { - panel.refreshUI(); - } - } + addPanels(); + + pack(); + setResizable(false); + setLocationRelativeTo(parent); + } + + + private void addPanels() { + panels.add(new GeneralSettingsPanel(this)); + panels.add(new GraphicsSettingsPanel()); + panels.add(new AlertSettingsPanel()); + panels.add(new SoundsSettingsPanel()); + if (!isClient) { + panels.add(new PerformanceSettingsPanel()); + panels.add(new HypocenterAnalysisSettingsPanel()); + } + panels.add(new DebugSettingsPanel()); + + for (SettingsPanel panel : panels) { + JScrollPane scrollPane = new JScrollPane(panel); + scrollPane.setPreferredSize(new Dimension(700, 500)); + scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + scrollPane.getVerticalScrollBar().setUnitIncrement(10); + tabbedPane.addTab(panel.getTitle(), scrollPane); + + javax.swing.SwingUtilities.invokeLater(() -> scrollPane.getVerticalScrollBar().setValue(0)); + } + } + + public void refreshUI() { + for (SettingsPanel panel : panels) { + panel.refreshUI(); + } + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/settings/SettingsPanel.java b/GlobalQuakeCore/src/main/java/globalquake/ui/settings/SettingsPanel.java index 7d9e0af3e..d11348034 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/settings/SettingsPanel.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/settings/SettingsPanel.java @@ -5,41 +5,42 @@ import javax.swing.*; -public abstract class SettingsPanel extends JPanel{ +public abstract class SettingsPanel extends JPanel { - public abstract void save() throws NumberFormatException; - - public abstract String getTitle(); + public abstract void save() throws NumberFormatException; - public void refreshUI() {} + public abstract String getTitle(); - public double parseDouble(String str, String name, double min, double max){ - double d = Double.parseDouble(str.replace(',', '.')); - if(Double.isNaN(d) || Double.isInfinite(d)){ - throw new RuntimeApplicationException("Invalid number: %s".formatted(str)); - } + public void refreshUI() { + } - if(d < min || d > max){ - throw new RuntimeApplicationException("%s must be between %s and %s (entered %s)!".formatted(name, min, max, d)); - } + public double parseDouble(String str, String name, double min, double max) { + double d = Double.parseDouble(str.replace(',', '.')); + if (Double.isNaN(d) || Double.isInfinite(d)) { + throw new RuntimeApplicationException("Invalid number: %s".formatted(str)); + } - return d; - } + if (d < min || d > max) { + throw new RuntimeApplicationException("%s must be between %s and %s (entered %s)!".formatted(name, min, max, d)); + } - public int parseInt(String str, String name, int min, int max){ - int n = Integer.parseInt(str); + return d; + } - if(n < min || n > max){ - throw new RuntimeApplicationException("%s must be between %s and %s (entered %s)!".formatted(name, min, max, n)); - } + public int parseInt(String str, String name, int min, int max) { + int n = Integer.parseInt(str); - return n; - } + if (n < min || n > max) { + throw new RuntimeApplicationException("%s must be between %s and %s (entered %s)!".formatted(name, min, max, n)); + } - public void fill(JPanel panel, int n){ - for(int i = 0; i < n; i++){ - panel.add(new JPanel()); - } - } + return n; + } + + public void fill(JPanel panel, int n) { + for (int i = 0; i < n; i++) { + panel.add(new JPanel()); + } + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/settings/SoundsSettingsPanel.java b/GlobalQuakeCore/src/main/java/globalquake/ui/settings/SoundsSettingsPanel.java index dd0e4d83f..0189e9c9f 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/settings/SoundsSettingsPanel.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/settings/SoundsSettingsPanel.java @@ -29,7 +29,7 @@ public SoundsSettingsPanel() { private Component createIndividualSoundsPanel() { JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); - for(GQSound gqSound : Sounds.ALL_ACTUAL_SOUNDS){ + for (GQSound gqSound : Sounds.ALL_ACTUAL_SOUNDS) { var borderLayout = new BorderLayout(); borderLayout.setHgap(10); borderLayout.setVgap(4); @@ -39,7 +39,7 @@ private Component createIndividualSoundsPanel() { JPanel soundPanel = new JPanel(borderLayout); //soundPanel.setLayout(new BoxLayout(soundPanel, BoxLayout.X_AXIS)); - soundPanel.setSize(300,300); + soundPanel.setSize(300, 300); JLabel label = new JLabel(gqSound.getFilename()); label.setPreferredSize(new Dimension(160, 40)); @@ -71,7 +71,7 @@ public void actionPerformed(ActionEvent actionEvent) { try { gqSound.load(true); } catch (FatalIOException e) { - if(GlobalQuake.getErrorHandler() != null){ + if (GlobalQuake.getErrorHandler() != null) { GlobalQuake.getErrorHandler().handleWarning(new RuntimeApplicationException("Failed to load this sound!", e)); } else { Logger.error(e); @@ -80,7 +80,7 @@ public void actionPerformed(ActionEvent actionEvent) { } }); - var gl = new GridLayout(2,1); + var gl = new GridLayout(2, 1); gl.setHgap(2); gl.setVgap(4); @@ -105,7 +105,7 @@ public void actionPerformed(ActionEvent actionEvent) { } private static JSlider createSingleSoundVolumeSlider(GQSound gqSound, JLabel label) { - JSlider volumeSlider = new JSlider(SwingConstants.HORIZONTAL,0,100, (int) (gqSound.volume * 100.0)); + JSlider volumeSlider = new JSlider(SwingConstants.HORIZONTAL, 0, 100, (int) (gqSound.volume * 100.0)); volumeSlider.setMajorTickSpacing(10); volumeSlider.setMinorTickSpacing(5); volumeSlider.setPaintTicks(true); @@ -113,7 +113,7 @@ private static JSlider createSingleSoundVolumeSlider(GQSound gqSound, JLabel lab volumeSlider.addChangeListener(changeEvent -> { gqSound.volume = volumeSlider.getValue() / 100.0; - if (gqSound.equals(Sounds.countdown)){ + if (gqSound.equals(Sounds.countdown)) { Sounds.countdown2.volume = Sounds.countdown.volume; // workaround } label.setText("Volume: %d%%".formatted((int) (gqSound.volume * 100.0))); @@ -121,7 +121,7 @@ private static JSlider createSingleSoundVolumeSlider(GQSound gqSound, JLabel lab return volumeSlider; } - private Component createMasterVolumeSlider(){ + private Component createMasterVolumeSlider() { sliderMasterVolume = HypocenterAnalysisSettingsPanel.createSettingsSlider(0, 100, 10, 2); JLabel label = new JLabel(); @@ -137,7 +137,7 @@ private Component createMasterVolumeSlider(){ changeListener.stateChanged(null); - JPanel coolLayout = HypocenterAnalysisSettingsPanel.createCoolLayout(sliderMasterVolume, label, null, + JPanel coolLayout = HypocenterAnalysisSettingsPanel.createCoolLayout(sliderMasterVolume, label, null, null); JPanel fill1 = new JPanel(); @@ -148,14 +148,14 @@ private Component createMasterVolumeSlider(){ chkBoxEnableSounds.addChangeListener(changeEvent -> Settings.enableSound = chkBoxEnableSounds.isSelected()); - JButton btnSoundsFolder=new JButton("Open Sounds Folder"); + JButton btnSoundsFolder = new JButton("Open Sounds Folder"); btnSoundsFolder.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { try { Desktop.getDesktop().open(Sounds.EXPORT_DIR); } catch (IOException e) { - if(GlobalQuake.getErrorHandler() != null){ + if (GlobalQuake.getErrorHandler() != null) { GlobalQuake.getErrorHandler().handleWarning(new RuntimeApplicationException("Unable to open file explorer!", e)); } else { Logger.error(e); @@ -163,16 +163,16 @@ public void actionPerformed(ActionEvent actionEvent) { } } }); - fill1. add(btnSoundsFolder); + fill1.add(btnSoundsFolder); - JButton btnReloadSounds=new JButton("Reload Sounds"); + JButton btnReloadSounds = new JButton("Reload Sounds"); btnReloadSounds.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { try { Sounds.loadSounds(); } catch (Exception e) { - if(GlobalQuake.getErrorHandler() != null){ + if (GlobalQuake.getErrorHandler() != null) { GlobalQuake.getErrorHandler().handleWarning(new RuntimeApplicationException("Unable to reload sounds!", e)); } else { Logger.error(e); @@ -180,7 +180,7 @@ public void actionPerformed(ActionEvent actionEvent) { } } }); - fill1. add(btnReloadSounds); + fill1.add(btnReloadSounds); coolLayout.add(fill1); return coolLayout; diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/FeatureSelectableStation.java b/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/FeatureSelectableStation.java index a5477d5f9..e6bbcc0fd 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/FeatureSelectableStation.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/FeatureSelectableStation.java @@ -48,27 +48,23 @@ public void createPolygon(GlobeRenderer renderer, RenderEntity entity, InputType inputType = entity.getOriginal().getSelectedChannel() == null ? InputType.UNKNOWN : entity.getOriginal().getSelectedChannel().getInputType(); - switch (inputType){ - case UNKNOWN -> - renderer.createCircle(entity.getRenderElement(0).getPolygon(), - entity.getOriginal().getLatitude(), - entity.getOriginal().getLongitude(), - size, 0, 30); - case VELOCITY -> - renderer.createTriangle(entity.getRenderElement(0).getPolygon(), - entity.getOriginal().getLatitude(), - entity.getOriginal().getLongitude(), - size * 1.41, 0, 0); - case ACCELERATION -> - renderer.createTriangle(entity.getRenderElement(0).getPolygon(), - entity.getOriginal().getLatitude(), - entity.getOriginal().getLongitude(), - size * 1.41, 0, 180); - case DISPLACEMENT -> - renderer.createSquare(entity.getRenderElement(0).getPolygon(), - entity.getOriginal().getLatitude(), - entity.getOriginal().getLongitude(), - size * 1.41, 0); + switch (inputType) { + case UNKNOWN -> renderer.createCircle(entity.getRenderElement(0).getPolygon(), + entity.getOriginal().getLatitude(), + entity.getOriginal().getLongitude(), + size, 0, 30); + case VELOCITY -> renderer.createTriangle(entity.getRenderElement(0).getPolygon(), + entity.getOriginal().getLatitude(), + entity.getOriginal().getLongitude(), + size * 1.41, 0, 0); + case ACCELERATION -> renderer.createTriangle(entity.getRenderElement(0).getPolygon(), + entity.getOriginal().getLatitude(), + entity.getOriginal().getLongitude(), + size * 1.41, 0, 180); + case DISPLACEMENT -> renderer.createSquare(entity.getRenderElement(0).getPolygon(), + entity.getOriginal().getLatitude(), + entity.getOriginal().getLongitude(), + size * 1.41, 0); } } @@ -111,28 +107,28 @@ public void render(GlobeRenderer renderer, Graphics2D graphics, RenderEntity minDelay = entity.getOriginal().getSelectedChannel().getSeedlinkNetworks().values().stream().min(Long::compare); int x = (int) (centerPonint.x + 10); - if(minDelay.isPresent() && minDelay.get() > 5 * 60 * 1000L) { + if (minDelay.isPresent() && minDelay.get() > 5 * 60 * 1000L) { graphics.setColor(Color.red); graphics.setFont(new Font("Calibri", Font.BOLD, 14)); graphics.drawString("!", x, (int) centerPonint.y + 9); - x+=graphics.getFontMetrics().stringWidth("!"); + x += graphics.getFontMetrics().stringWidth("!"); } - if(entity.getOriginal().locationErrorSuspected()){ + if (entity.getOriginal().locationErrorSuspected()) { graphics.setColor(Color.yellow); graphics.setFont(new Font("Calibri", Font.BOLD, 14)); graphics.drawString("!", x, (int) centerPonint.y + 9); } - if(entity.getOriginal().getSelectedChannel() != null && entity.getOriginal().getSelectedChannel().getSensitivity() <= 0){ + if (entity.getOriginal().getSelectedChannel() != null && entity.getOriginal().getSelectedChannel().getSensitivity() <= 0) { graphics.setColor(Color.blue); graphics.setFont(new Font("Calibri", Font.BOLD, 14)); graphics.drawString("%.1f".formatted(entity.getOriginal().getSelectedChannel().getSensitivity()), x + 20, (int) centerPonint.y + 9); @@ -144,7 +140,7 @@ private void drawInfo(Graphics2D g, int x, int y, Station original) { g.setColor(Color.white); g.setFont(new Font("Calibri", Font.PLAIN, 12)); - String str = original.getNetwork().getNetworkCode()+" "+original.getStationCode(); + String str = original.getNetwork().getNetworkCode() + " " + original.getStationCode(); g.drawString(str, x - g.getFontMetrics().stringWidth(str) / 2, y - 11); y += 20; @@ -155,22 +151,22 @@ private void drawInfo(Graphics2D g, int x, int y, Station original) { str = original.getStationSite(); g.drawString(str, x - g.getFontMetrics().stringWidth(str) / 2, y += 13); - if(original.getSelectedChannel() != null && original.getSelectedChannel().isAvailable()) { + if (original.getSelectedChannel() != null && original.getSelectedChannel().isAvailable()) { str = "Sensitivity: %6.3E".formatted(original.getSelectedChannel().getSensitivity()); g.drawString(str, x - g.getFontMetrics().stringWidth(str) / 2, y += 13); int _y = y + 20; - for(var availableSeedlinkNetwork : original.getSelectedChannel().getSeedlinkNetworks().entrySet()) { + for (var availableSeedlinkNetwork : original.getSelectedChannel().getSeedlinkNetworks().entrySet()) { drawDelay(g, x, _y, availableSeedlinkNetwork.getValue(), availableSeedlinkNetwork.getKey().getName()); _y += 13; } } } - private static String getDelayString(long delay){ - if(delay == SeedlinkCommunicator.UNKNOWN_DELAY){ + private static String getDelayString(long delay) { + if (delay == SeedlinkCommunicator.UNKNOWN_DELAY) { return "???"; - } else if(delay <= 60 * 1000L){ + } else if (delay <= 60 * 1000L) { return "%.1fs".formatted(delay / 1000.0); } else if (delay < 60 * 60 * 1000L) { return "%d:%02d".formatted(delay / (1000 * 60), (delay / 1000) % 60); @@ -183,7 +179,7 @@ public static void drawDelay(Graphics2D g, int x, int y, long delay, String pref String fullPrefix = prefix == null ? "" : prefix + ": "; String str = fullPrefix + delayString; - int _x = x - g.getFontMetrics().stringWidth(str) / 2; + int _x = x - g.getFontMetrics().stringWidth(str) / 2; g.setColor(Color.magenta); g.drawString(fullPrefix, _x, y); _x += g.getFontMetrics().stringWidth(fullPrefix); @@ -192,11 +188,11 @@ public static void drawDelay(Graphics2D g, int x, int y, long delay, String pref } private static Color getColorDelay(long delay) { - if(delay <= 16 * 1000L){ + if (delay <= 16 * 1000L) { return Color.green; - } else if(delay <= 60 * 1000L){ + } else if (delay <= 60 * 1000L) { return Color.YELLOW; - } else if(delay <= 5 * 60 * 1000L){ + } else if (delay <= 5 * 60 * 1000L) { return Color.ORANGE; } diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/StationColor.java b/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/StationColor.java index 3295530b9..52b41728f 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/StationColor.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/StationColor.java @@ -4,11 +4,11 @@ public class StationColor { - public static final Color SELECTED = new Color(50,255,0); + public static final Color SELECTED = new Color(50, 255, 0); - public static final Color AVAILABLE = new Color(50,150,255); + public static final Color AVAILABLE = new Color(50, 150, 255); - public static final Color UNAVAILABLE = new Color(255,150,55); + public static final Color UNAVAILABLE = new Color(255, 150, 55); - public static final Color ALL = new Color(200,200,200); + public static final Color ALL = new Color(200, 200, 200); } diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/StationEditDialog.java b/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/StationEditDialog.java index dd9231b26..92f880cbe 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/StationEditDialog.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/StationEditDialog.java @@ -44,7 +44,7 @@ public void actionPerformed(ActionEvent actionEvent) { }); JPanel buttonPanel = new JPanel(); - buttonPanel.setBorder(new EmptyBorder(5,5,5,5)); + buttonPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); buttonPanel.add(doneButton); add(buttonPanel, BorderLayout.SOUTH); diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/StationSelectFrame.java b/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/StationSelectFrame.java index 5755a0e81..cb07c363b 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/StationSelectFrame.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/StationSelectFrame.java @@ -30,7 +30,7 @@ public class StationSelectFrame extends GQFrame implements ActionListener { public StationSelectFrame(Window parent, StationDatabaseManager manager) { setLayout(new BorderLayout()); this.manager = manager; - + JPanel togglePanel = new JPanel(new GridBagLayout()); JButton toggleButton = new JButton("<"); selectAll = new JButton(new SelectAllAction(manager, this)); @@ -53,7 +53,7 @@ public StationSelectFrame(Window parent, StationDatabaseManager manager) { toggleButton.setBackground(Color.GRAY); JPanel centerPanel = new JPanel(new GridBagLayout()); - stationSelectPanel = new StationSelectPanel(this, manager){ + stationSelectPanel = new StationSelectPanel(this, manager) { @Override public void paint(Graphics gr) { super.paint(gr); @@ -106,7 +106,7 @@ public void actionPerformed(ActionEvent actionEvent) { add(centerPanel, BorderLayout.CENTER); add(toolBar, BorderLayout.WEST); - add(new StationCountPanel(manager, new GridLayout(1,4)), BorderLayout.SOUTH); + add(new StationCountPanel(manager, new GridLayout(1, 4)), BorderLayout.SOUTH); pack(); setLocationRelativeTo(parent); @@ -127,7 +127,7 @@ private JToolBar createToolbar() { selectButton.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { - if(selectButton.isSelected()){ + if (selectButton.isSelected()) { setDragMode(DragMode.SELECT); } else { setDragMode(DragMode.NONE); @@ -138,14 +138,14 @@ public void actionPerformed(ActionEvent actionEvent) { deselectButton.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { - if(deselectButton.isSelected()){ + if (deselectButton.isSelected()) { setDragMode(DragMode.DESELECT); } else { setDragMode(DragMode.NONE); } } }); - + ImageIcon selectRegion = new ImageIcon(Objects.requireNonNull(getClass().getResource("/image_icons/selectRegion.png"))); Image image = selectRegion.getImage().getScaledInstance(30, 30, Image.SCALE_SMOOTH); selectButton.setIcon(new ImageIcon(image)); @@ -182,7 +182,7 @@ public void actionPerformed(ActionEvent actionEvent) { } public void setDragMode(DragMode dragMode) { - this.dragMode= dragMode; + this.dragMode = dragMode; selectButton.setSelected(this.dragMode.equals(DragMode.SELECT)); deselectButton.setSelected(this.dragMode.equals(DragMode.DESELECT)); } diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/StationSelectPanel.java b/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/StationSelectPanel.java index a4bbd2da0..7d80c6051 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/StationSelectPanel.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/StationSelectPanel.java @@ -47,7 +47,7 @@ public void mouseDragged(MouseEvent e) { dragEnd = e.getPoint(); - if(dragStart != null) { + if (dragStart != null) { Rectangle rectangle = new Rectangle(dragStart); rectangle.add(dragEnd); dragRectangle = rectangle; @@ -62,12 +62,12 @@ public void mousePressed(MouseEvent e) { return; } - if(e.getButton() == MouseEvent.BUTTON3){ + if (e.getButton() == MouseEvent.BUTTON3) { stationSelectFrame.setDragMode(DragMode.NONE); dragEnd = null; dragRectangle = null; return; - } else if(e.getButton() != MouseEvent.BUTTON1){ + } else if (e.getButton() != MouseEvent.BUTTON1) { return; } @@ -83,12 +83,12 @@ public void mouseReleased(MouseEvent e) { return; } - if(dragEnd == null || e.getButton() != MouseEvent.BUTTON1){ + if (dragEnd == null || e.getButton() != MouseEvent.BUTTON1) { return; } dragEnd = e.getPoint(); - if(dragStart != null) { + if (dragStart != null) { Rectangle rectangle = new Rectangle(dragStart); rectangle.add(dragEnd); dragRectangle = rectangle; @@ -106,26 +106,26 @@ public void mouseReleased(MouseEvent e) { @Override public void featuresClicked(ArrayList> clicked) { List clickedStations = new ArrayList<>(); - for(RenderEntity renderEntity:clicked){ - if(renderEntity.getOriginal() instanceof Station){ - clickedStations.add((Station)renderEntity.getOriginal()); + for (RenderEntity renderEntity : clicked) { + if (renderEntity.getOriginal() instanceof Station) { + clickedStations.add((Station) renderEntity.getOriginal()); } } - if(clickedStations.isEmpty()){ + if (clickedStations.isEmpty()) { return; } Station selectedStation; - if(clickedStations.size() == 1){ + if (clickedStations.size() == 1) { selectedStation = clickedStations.get(0); } else { selectedStation = (Station) JOptionPane.showInputDialog(this, "Select station:", "Station selection", JOptionPane.PLAIN_MESSAGE, null, clickedStations.toArray(), clickedStations.get(0)); } - if(selectedStation != null) + if (selectedStation != null) new StationEditDialog(stationSelectFrame, selectedStation); } @@ -140,7 +140,7 @@ private void fireDragEvent() { } stationDatabaseManager.fireUpdateEvent(); - }finally { + } finally { stationDatabaseManager.getStationDatabase().getDatabaseWriteLock().unlock(); } } @@ -149,7 +149,7 @@ private void fireDragEvent() { public void paint(Graphics gr) { super.paint(gr); Graphics2D g = (Graphics2D) gr; - if(stationSelectFrame.getDragMode() == DragMode.NONE){ + if (stationSelectFrame.getDragMode() == DragMode.NONE) { return; } @@ -159,8 +159,8 @@ public void paint(Graphics gr) { : "Drag to deselect region"; g.drawString(str, getWidth() / 2 - g.getFontMetrics().stringWidth(str) / 2, getHeight() - 8); - if(dragRectangle != null){ - g.setColor(stationSelectFrame.getDragMode() == DragMode.SELECT ? Color.green:Color.red); + if (dragRectangle != null) { + g.setColor(stationSelectFrame.getDragMode() == DragMode.SELECT ? Color.green : Color.red); g.setStroke(new BasicStroke(2f)); g.draw(dragRectangle); } @@ -174,14 +174,14 @@ public boolean interactionAllowed() { public void updateAllStations() { List stations = new ArrayList<>(); stationDatabaseManager.getStationDatabase().getDatabaseReadLock().lock(); - try{ - for(Network network:stationDatabaseManager.getStationDatabase().getNetworks()){ + try { + for (Network network : stationDatabaseManager.getStationDatabase().getNetworks()) { stations.addAll(network.getStations().stream().filter(station -> showUnavailable || station.hasAvailableChannel()).toList()); } allStationsList.clear(); allStationsList.addAll(stations); - }finally { + } finally { stationDatabaseManager.getStationDatabase().getDatabaseReadLock().unlock(); } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/action/DeselectAllAction.java b/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/action/DeselectAllAction.java index e8ddaea2e..af656d7cc 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/action/DeselectAllAction.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/action/DeselectAllAction.java @@ -17,7 +17,7 @@ public class DeselectAllAction extends AbstractAction { public DeselectAllAction(StationDatabaseManager stationDatabaseManager, Window parent) { super("Deselect All"); this.parent = parent; - this.stationDatabaseManager=stationDatabaseManager; + this.stationDatabaseManager = stationDatabaseManager; putValue(SHORT_DESCRIPTION, "Deselects All Available Stations"); @@ -39,12 +39,12 @@ public void actionPerformed(ActionEvent actionEvent) { } stationDatabaseManager.getStationDatabase().getDatabaseWriteLock().lock(); - try{ - for(Network network : stationDatabaseManager.getStationDatabase().getNetworks()){ + try { + for (Network network : stationDatabaseManager.getStationDatabase().getNetworks()) { network.getStations().forEach(station -> station.setSelectedChannel(null)); } stationDatabaseManager.fireUpdateEvent(); - }finally { + } finally { stationDatabaseManager.getStationDatabase().getDatabaseWriteLock().unlock(); } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/action/DeselectUnavailableAction.java b/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/action/DeselectUnavailableAction.java index 7b9175f33..67ac0a642 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/action/DeselectUnavailableAction.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/action/DeselectUnavailableAction.java @@ -18,8 +18,8 @@ public class DeselectUnavailableAction extends AbstractAction { public DeselectUnavailableAction(StationDatabaseManager stationDatabaseManager, Window parent) { super("Deselect Unavailable"); - this.stationDatabaseManager=stationDatabaseManager; - this.parent=parent; + this.stationDatabaseManager = stationDatabaseManager; + this.parent = parent; putValue(SHORT_DESCRIPTION, "Deselects All Unavailable Stations"); @@ -33,25 +33,25 @@ public DeselectUnavailableAction(StationDatabaseManager stationDatabaseManager, public void actionPerformed(ActionEvent actionEvent) { boolean alreadyDeselected = true; stationDatabaseManager.getStationDatabase().getDatabaseWriteLock().lock(); - try{ - for(Network network : stationDatabaseManager.getStationDatabase().getNetworks()){ - for(Station station : network.getStations()){ - if(station.getSelectedChannel() != null && !station.getSelectedChannel().isAvailable()){ + try { + for (Network network : stationDatabaseManager.getStationDatabase().getNetworks()) { + for (Station station : network.getStations()) { + if (station.getSelectedChannel() != null && !station.getSelectedChannel().isAvailable()) { alreadyDeselected = false; break; } } network.getStations().forEach(station -> { - if(station.getSelectedChannel() != null && !station.getSelectedChannel().isAvailable()) { + if (station.getSelectedChannel() != null && !station.getSelectedChannel().isAvailable()) { station.setSelectedChannel(null); } }); } - if(alreadyDeselected){ + if (alreadyDeselected) { JOptionPane.showMessageDialog(parent, "All Unavailable Stations Already Deselected"); } stationDatabaseManager.fireUpdateEvent(); - }finally { + } finally { stationDatabaseManager.getStationDatabase().getDatabaseWriteLock().unlock(); } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/action/DistanceFilterAction.java b/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/action/DistanceFilterAction.java index c220bc2ef..890d835b2 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/action/DistanceFilterAction.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/action/DistanceFilterAction.java @@ -21,8 +21,8 @@ public class DistanceFilterAction extends AbstractAction { public DistanceFilterAction(StationDatabaseManager stationDatabaseManager, Window parent) { super("Apply Distance Filter"); - this.stationDatabaseManager=stationDatabaseManager; - this.parent=parent; + this.stationDatabaseManager = stationDatabaseManager; + this.parent = parent; putValue(SHORT_DESCRIPTION, "Select Stations with Minimum Distance Between Channels"); @@ -38,18 +38,16 @@ public void actionPerformed(ActionEvent actionEvent) { double minDist; if (input != null) { // Check if user clicked OK or Cancel try { - if(Double.parseDouble(input) > 0){ + if (Double.parseDouble(input) > 0) { minDist = Double.parseDouble(input); - } - else{ + } else { throw new NumberFormatException(); } } catch (NumberFormatException e) { JOptionPane.showMessageDialog(parent, "Invalid input. Please enter a valid number.", "Error", JOptionPane.ERROR_MESSAGE); return; } - } - else{ + } else { return; } @@ -58,7 +56,7 @@ public void actionPerformed(ActionEvent actionEvent) { double finalMinDist = minDist; new Thread(() -> { - try{ + try { runAlgorithm(finalMinDist); } finally { DistanceFilterAction.this.setEnabled(true); @@ -67,14 +65,14 @@ public void actionPerformed(ActionEvent actionEvent) { } - private void runAlgorithm(double minDist){ + private void runAlgorithm(double minDist) { stationDatabaseManager.getStationDatabase().getDatabaseWriteLock().lock(); - try{ + try { List selectedAvailableChannels = new ArrayList<>(); - for(Network network : stationDatabaseManager.getStationDatabase().getNetworks()){ - for(Station station: network.getStations()){ - if(station.getSelectedChannel() != null && station.getSelectedChannel().isAvailable()){ + for (Network network : stationDatabaseManager.getStationDatabase().getNetworks()) { + for (Station station : network.getStations()) { + if (station.getSelectedChannel() != null && station.getSelectedChannel().isAvailable()) { selectedAvailableChannels.add(new FilterChannel(station)); } } @@ -83,7 +81,7 @@ private void runAlgorithm(double minDist){ selectedAvailableChannels.parallelStream().forEach(filterChannel -> filterChannel.calculateClosestChannel(new ArrayList<>(selectedAvailableChannels))); selectedAvailableChannels.sort(Comparator.comparingDouble(FilterChannel::getClosestChannel)); - while(true) { + while (true) { boolean removed = false; for (Iterator iterator = selectedAvailableChannels.iterator(); iterator.hasNext(); ) { FilterChannel filterChannel = iterator.next(); @@ -92,15 +90,15 @@ private void runAlgorithm(double minDist){ filterChannel.getStation().setSelectedChannel(null); iterator.remove(); removed = true; - for(int i = 0; i < 2; i++){ - if(!iterator.hasNext()){ + for (int i = 0; i < 2; i++) { + if (!iterator.hasNext()) { break; } iterator.next(); } } } - if(!removed){ + if (!removed) { break; } @@ -109,7 +107,7 @@ private void runAlgorithm(double minDist){ } stationDatabaseManager.fireUpdateEvent(); - }finally { + } finally { stationDatabaseManager.getStationDatabase().getDatabaseWriteLock().unlock(); } } @@ -130,14 +128,14 @@ public double getClosestChannel() { return closestChannel; } - public void calculateClosestChannel(List filterChannels){ + public void calculateClosestChannel(List filterChannels) { double closest = 99999999; - for(FilterChannel filterChannel : filterChannels){ - if(filterChannel.equals(this)){ + for (FilterChannel filterChannel : filterChannels) { + if (filterChannel.equals(this)) { continue; } double dist = GeoUtils.greatCircleDistance(station.getLatitude(), station.getLongitude(), filterChannel.getStation().getLatitude(), filterChannel.getStation().getLongitude()); - if(dist < closest){ + if (dist < closest) { closest = dist; } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/action/SelectAllAction.java b/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/action/SelectAllAction.java index 8a9063aff..90a94f765 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/action/SelectAllAction.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/stationselect/action/SelectAllAction.java @@ -17,7 +17,7 @@ public class SelectAllAction extends AbstractAction { public SelectAllAction(StationDatabaseManager stationDatabaseManager, Window parent) { super("Select All"); - this.stationDatabaseManager=stationDatabaseManager; + this.stationDatabaseManager = stationDatabaseManager; this.parent = parent; putValue(SHORT_DESCRIPTION, "Selects All Available Stations"); @@ -40,12 +40,12 @@ public void actionPerformed(ActionEvent actionEvent) { } stationDatabaseManager.getStationDatabase().getDatabaseWriteLock().lock(); - try{ - for(Network network : stationDatabaseManager.getStationDatabase().getNetworks()){ + try { + for (Network network : stationDatabaseManager.getStationDatabase().getNetworks()) { network.getStations().forEach(Station::selectBestAvailableChannel); } stationDatabaseManager.fireUpdateEvent(); - }finally { + } finally { stationDatabaseManager.getStationDatabase().getDatabaseWriteLock().unlock(); } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/table/Column.java b/GlobalQuakeCore/src/main/java/globalquake/ui/table/Column.java index 425c35da7..029306ef4 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/table/Column.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/table/Column.java @@ -9,14 +9,14 @@ public abstract class Column { private final String name; private final Function valueGetter; private final Class columnType; - private final TableCellRendererAdapter renderer; + private final TableCellRendererAdapter renderer; private Column(String name, Class columnClass, Function valueGetter, TableCellRendererAdapter renderer) { this.name = Objects.requireNonNull(name, "name cannot be null"); this.columnType = Objects.requireNonNull(columnClass, "column class cannot be null"); this.valueGetter = Objects.requireNonNull(valueGetter, "value getter cannot be null"); this.renderer = Objects.requireNonNull(renderer, "renderer cannot be null"); - } + } @SuppressWarnings("unused") public static Column editable(String name, Class columnClass, Function valueGetter, @@ -43,10 +43,10 @@ public String getName() { public Class getColumnType() { return columnType; } - + public TableCellRendererAdapter getRenderer() { - return renderer; - } + return renderer; + } private static class ReadOnly extends Column { diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/table/FilterableTableModel.java b/GlobalQuakeCore/src/main/java/globalquake/ui/table/FilterableTableModel.java index fba4cb652..666aa04f7 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/table/FilterableTableModel.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/table/FilterableTableModel.java @@ -9,36 +9,36 @@ public abstract class FilterableTableModel extends AbstractTableModel { - @Serial - private static final long serialVersionUID = 1727941556193013022L; - private final Collection data; - private final List filteredData; - - public FilterableTableModel(Collection data) { - this.data = data; - this.filteredData = new ArrayList<>(data); - applyFilter(); - } - - public synchronized final void applyFilter() { - this.filteredData.clear(); - this.filteredData.addAll(this.data.stream().filter(this::accept).toList()); - super.fireTableDataChanged(); - } - - @SuppressWarnings({"unused", "SameReturnValue"}) - public boolean accept(E entity) { - return true; - } - - public synchronized E getEntity(int rowIndex) { - return filteredData.get(rowIndex); - } - - public abstract TableCellRendererAdapter getColumnRenderer(int columnIndex); - - @Override - public synchronized int getRowCount() { - return filteredData.size(); - } + @Serial + private static final long serialVersionUID = 1727941556193013022L; + private final Collection data; + private final List filteredData; + + public FilterableTableModel(Collection data) { + this.data = data; + this.filteredData = new ArrayList<>(data); + applyFilter(); + } + + public synchronized final void applyFilter() { + this.filteredData.clear(); + this.filteredData.addAll(this.data.stream().filter(this::accept).toList()); + super.fireTableDataChanged(); + } + + @SuppressWarnings({"unused", "SameReturnValue"}) + public boolean accept(E entity) { + return true; + } + + public synchronized E getEntity(int rowIndex) { + return filteredData.get(rowIndex); + } + + public abstract TableCellRendererAdapter getColumnRenderer(int columnIndex); + + @Override + public synchronized int getRowCount() { + return filteredData.size(); + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/table/LastUpdateRenderer.java b/GlobalQuakeCore/src/main/java/globalquake/ui/table/LastUpdateRenderer.java index 5b09e4a63..c7266085a 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/table/LastUpdateRenderer.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/table/LastUpdateRenderer.java @@ -6,13 +6,13 @@ public class LastUpdateRenderer extends TableCellRendererAdapter { - @SuppressWarnings("unused") - @Override - public String getText(E entity, LocalDateTime value) { - if(value == null){ - return "Never"; - } - return Settings.formatDateTime(value); - } + @SuppressWarnings("unused") + @Override + public String getText(E entity, LocalDateTime value) { + if (value == null) { + return "Never"; + } + return Settings.formatDateTime(value); + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/table/ProgressBarRenderer.java b/GlobalQuakeCore/src/main/java/globalquake/ui/table/ProgressBarRenderer.java index 69ac1c188..306e320fb 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/table/ProgressBarRenderer.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/table/ProgressBarRenderer.java @@ -3,7 +3,7 @@ import javax.swing.*; import java.awt.*; -public class ProgressBarRenderer extends TableCellRendererAdapter{ +public class ProgressBarRenderer extends TableCellRendererAdapter { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { return (JProgressBar) value; diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/table/SeedlinkNetworksTableModel.java b/GlobalQuakeCore/src/main/java/globalquake/ui/table/SeedlinkNetworksTableModel.java index 319e500b4..e42e6382b 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/table/SeedlinkNetworksTableModel.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/table/SeedlinkNetworksTableModel.java @@ -5,7 +5,7 @@ import javax.swing.*; import java.util.List; -public class SeedlinkNetworksTableModel extends FilterableTableModel{ +public class SeedlinkNetworksTableModel extends FilterableTableModel { private final List> columns = List.of( Column.readonly("Name", String.class, SeedlinkNetwork::getName, new TableCellRendererAdapter<>()), Column.readonly("Host", String.class, SeedlinkNetwork::getHost, new TableCellRendererAdapter<>()), diff --git a/GlobalQuakeCore/src/main/java/globalquake/ui/table/StationSourcesTableModel.java b/GlobalQuakeCore/src/main/java/globalquake/ui/table/StationSourcesTableModel.java index 09216e075..44bee89e6 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/ui/table/StationSourcesTableModel.java +++ b/GlobalQuakeCore/src/main/java/globalquake/ui/table/StationSourcesTableModel.java @@ -6,7 +6,7 @@ import java.time.LocalDateTime; import java.util.List; -public class StationSourcesTableModel extends FilterableTableModel{ +public class StationSourcesTableModel extends FilterableTableModel { private final List> columns = List.of( Column.readonly("Name", String.class, StationSource::getName, new TableCellRendererAdapter<>()), Column.readonly("URL", String.class, StationSource::getUrl, new TableCellRendererAdapter<>()), diff --git a/GlobalQuakeCore/src/main/java/globalquake/utils/GeoUtils.java b/GlobalQuakeCore/src/main/java/globalquake/utils/GeoUtils.java index 1169d7e2d..92719ac63 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/utils/GeoUtils.java +++ b/GlobalQuakeCore/src/main/java/globalquake/utils/GeoUtils.java @@ -5,192 +5,191 @@ import org.apache.commons.math3.util.FastMath; public interface GeoUtils { - double EARTH_CIRCUMFERENCE = 40082; - double EARTH_RADIUS = 6379.0;// 6371.0; - - class MoveOnGlobePrecomputed{ - public double c_theta; - public double s_theta; - public double c_phi; - public double s_phi; - public double c_delta; - public double s_delta; - } - - static void precomputeMoveOnGlobe(MoveOnGlobePrecomputed result, double lat, double lon, double distance){ - double delta = distance / EARTH_RADIUS; - double theta = Math.toRadians(lat); - double phi = Math.toRadians(lon); - - // calculate sines and cosines - double c_theta = FastMath.cos(theta); - double s_theta = FastMath.sin(theta); - double c_phi = FastMath.cos(phi); - double s_phi = FastMath.sin(phi); - double c_delta = FastMath.cos(delta); - double s_delta = FastMath.sin(delta); - - result.c_theta = c_theta; - result.s_theta = s_theta; - result.c_phi = c_phi; - result.s_phi=s_phi; - result.c_delta = c_delta; - result.s_delta=s_delta; - } - - static void moveOnGlobe(MoveOnGlobePrecomputed p, Point2DGQ point2D, double angle){ - double gamma = Math.toRadians(angle); - double c_gamma = FastMath.cos(gamma); - double s_gamma = FastMath.sin(gamma); - double x = p.c_delta * p.c_theta * p.c_phi - p.s_delta * (p.s_theta * p.c_phi * c_gamma + p.s_phi * s_gamma); - double y = p.c_delta * p.c_theta * p.s_phi - p.s_delta * (p.s_theta * p.s_phi * c_gamma - p.c_phi * s_gamma); - double z = p.s_delta * p.c_theta * c_gamma + p.c_delta * p.s_theta; - - // calculate end lat long - double theta2 = FastMath.asin(z); - double phi2 = FastMath.atan2(y, x); - - point2D.x = FastMath.toDegrees(theta2); - point2D.y = FastMath.toDegrees(phi2); - } - - /** - * - * @param lat Latitude - * @param lon Longitude - * @param distance GCD - * @param angle Heading - * @return new lat, lon - */ - static double[] moveOnGlobe(double lat, double lon, double distance, double angle) { - // calculate angles - double delta = distance / EARTH_RADIUS; - double theta = Math.toRadians(lat); - double phi = Math.toRadians(lon); - double gamma = Math.toRadians(angle); - - // calculate sines and cosines - double c_theta = FastMath.cos(theta); - double s_theta = FastMath.sin(theta); - double c_phi = FastMath.cos(phi); - double s_phi = FastMath.sin(phi); - double c_delta = FastMath.cos(delta); - double s_delta = FastMath.sin(delta); - double c_gamma = FastMath.cos(gamma); - double s_gamma = FastMath.sin(gamma); - - // calculate end vector - double x = c_delta * c_theta * c_phi - s_delta * (s_theta * c_phi * c_gamma + s_phi * s_gamma); - double y = c_delta * c_theta * s_phi - s_delta * (s_theta * s_phi * c_gamma - c_phi * s_gamma); - double z = s_delta * c_theta * c_gamma + c_delta * s_theta; - - // calculate end lat long - double theta2 = FastMath.asin(z); - double phi2 = FastMath.atan2(y, x); - - return new double[] { FastMath.toDegrees(theta2), FastMath.toDegrees(phi2) }; - } - - static void main(String[] args) { - System.err.println(new MMIIntensityScale().getLevel(pgaFunctionGen2(7.0, 10))); - } - - @SuppressWarnings("unused") - static double placeOnSurface(double travelledDistance, double alt1, double alt2) { - double d = alt1 - alt2; - double angDiff = (travelledDistance * 360.0) / EARTH_CIRCUMFERENCE; - double s2 = travelledDistance * travelledDistance - d * d *FastMath.cos(Math.toRadians(angDiff)); - if (s2 < 0) { - return 0; - } - return FastMath.sqrt(s2); - } - - static double greatCircleDistance(double lat1, double lon1, double lat2, double lon2) { - // Convert latitude and longitude from degrees to radians - lat1 = Math.toRadians(lat1); - lon1 = Math.toRadians(lon1); - lat2 = Math.toRadians(lat2); - lon2 = Math.toRadians(lon2); - - // Compute differences in latitudes and longitudes - double dlat = lat2 - lat1; - double dlon = lon2 - lon1; - - // Haversine formula - double a = Math.pow(Math.sin(dlat / 2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon / 2), 2); - double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); - - return EARTH_RADIUS * c; // Angular distance in radians - } - - - static double calculateAngle(double lat1, double lon1, double lat2, double lon2) { - lat1 =Math.toRadians(lat1); - lon1 =Math.toRadians(lon1); - lat2 =Math.toRadians(lat2); - lon2 =Math.toRadians(lon2); - double dLon = (lon2 - lon1); - - double y =FastMath.sin(dLon) *FastMath.cos(lat2); - double x =FastMath.cos(lat1) *FastMath.sin(lat2) -FastMath.sin(lat1) *FastMath.cos(lat2) *FastMath.cos(dLon); - - double bearing =FastMath.atan2(y, x); - - bearing =FastMath.toDegrees(bearing); - bearing = (bearing + 360) % 360; - // bearing = 360 - bearing; - - return bearing; - } - - static double geologicalDistance(double lat1, double lon1, double alt1, double lat2, double lon2, - double alt2) { - alt1 += EARTH_RADIUS; - alt2 += EARTH_RADIUS; - double x1 =FastMath.sin(Math.toRadians(lon1)) * alt1 *FastMath.cos(Math.toRadians(lat1)); - double z1 = -Math.cos(Math.toRadians(lon1)) * alt1 *FastMath.cos(Math.toRadians(lat1)); - double y1 =FastMath.sin(Math.toRadians(lat1)) * alt1; - - double x2 =FastMath.sin(Math.toRadians(lon2)) * alt2 *FastMath.cos(Math.toRadians(lat2)); - double z2 = -FastMath.cos(Math.toRadians(lon2)) * alt2 *FastMath.cos(Math.toRadians(lat2)); - double y2 =FastMath.sin(Math.toRadians(lat2)) * alt2; - return FastMath.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2)); - } - - static double getMaxPGA(double lat, double lon, double depth, double mag){ - double distGEO = globalquake.core.regions.Regions.getOceanDistance(lat, lon, false, depth); - return GeoUtils.pgaFunction(mag, distGEO, depth); - } - - static double pgaFunction(double mag, double distKm, double depth) { - return pgaFunctionGen2( - mag + 0.4 * EarthquakeAnalysis.getDepthCorrection(depth), - distKm / (1.0 + 0.75 * EarthquakeAnalysis.getDepthCorrection(depth))); - } - - private static double pgaFunctionGen2(double mag, double distKm) { - return Math.pow(10, mag * 0.575) / (0.36 * Math.pow(distKm, 1.25 + mag / 22.0) + 10); - } - - @Deprecated - private static double pgaFunctionGen1(double mag, double distKm){ - distKm = FastMath.abs(distKm); - double a = mag + 1.5; - double b = FastMath.pow((a + 0.9) / 5.5, 7.0); - double c = FastMath.pow((distKm * (14.0 - a * 0.85)) / (FastMath.pow(a, (5.4) / (1 + a * 0.075))), 2.5); - return b / (0.09 + c); - } - - @SuppressWarnings("unused") - static double inversePgaFunctionGen1(double mag, double pga) { - double a = mag + 1.5; - return ((Math.pow((Math.pow((a + 0.9) / 5.5, 7.0)) / pga - 0.09, 1 / 2.5) - * (Math.pow(a, (5.4) / (1 + a * 0.075))))) / (14.0 - a * 0.85); - } - - static double gcdToGeo(double greatCircleDistance) { - return geologicalDistance(0, 0, 0, 0, (360 * greatCircleDistance) / EARTH_CIRCUMFERENCE, 0); - } + double EARTH_CIRCUMFERENCE = 40082; + double EARTH_RADIUS = 6379.0;// 6371.0; + + class MoveOnGlobePrecomputed { + public double c_theta; + public double s_theta; + public double c_phi; + public double s_phi; + public double c_delta; + public double s_delta; + } + + static void precomputeMoveOnGlobe(MoveOnGlobePrecomputed result, double lat, double lon, double distance) { + double delta = distance / EARTH_RADIUS; + double theta = Math.toRadians(lat); + double phi = Math.toRadians(lon); + + // calculate sines and cosines + double c_theta = FastMath.cos(theta); + double s_theta = FastMath.sin(theta); + double c_phi = FastMath.cos(phi); + double s_phi = FastMath.sin(phi); + double c_delta = FastMath.cos(delta); + double s_delta = FastMath.sin(delta); + + result.c_theta = c_theta; + result.s_theta = s_theta; + result.c_phi = c_phi; + result.s_phi = s_phi; + result.c_delta = c_delta; + result.s_delta = s_delta; + } + + static void moveOnGlobe(MoveOnGlobePrecomputed p, Point2DGQ point2D, double angle) { + double gamma = Math.toRadians(angle); + double c_gamma = FastMath.cos(gamma); + double s_gamma = FastMath.sin(gamma); + double x = p.c_delta * p.c_theta * p.c_phi - p.s_delta * (p.s_theta * p.c_phi * c_gamma + p.s_phi * s_gamma); + double y = p.c_delta * p.c_theta * p.s_phi - p.s_delta * (p.s_theta * p.s_phi * c_gamma - p.c_phi * s_gamma); + double z = p.s_delta * p.c_theta * c_gamma + p.c_delta * p.s_theta; + + // calculate end lat long + double theta2 = FastMath.asin(z); + double phi2 = FastMath.atan2(y, x); + + point2D.x = FastMath.toDegrees(theta2); + point2D.y = FastMath.toDegrees(phi2); + } + + /** + * @param lat Latitude + * @param lon Longitude + * @param distance GCD + * @param angle Heading + * @return new lat, lon + */ + static double[] moveOnGlobe(double lat, double lon, double distance, double angle) { + // calculate angles + double delta = distance / EARTH_RADIUS; + double theta = Math.toRadians(lat); + double phi = Math.toRadians(lon); + double gamma = Math.toRadians(angle); + + // calculate sines and cosines + double c_theta = FastMath.cos(theta); + double s_theta = FastMath.sin(theta); + double c_phi = FastMath.cos(phi); + double s_phi = FastMath.sin(phi); + double c_delta = FastMath.cos(delta); + double s_delta = FastMath.sin(delta); + double c_gamma = FastMath.cos(gamma); + double s_gamma = FastMath.sin(gamma); + + // calculate end vector + double x = c_delta * c_theta * c_phi - s_delta * (s_theta * c_phi * c_gamma + s_phi * s_gamma); + double y = c_delta * c_theta * s_phi - s_delta * (s_theta * s_phi * c_gamma - c_phi * s_gamma); + double z = s_delta * c_theta * c_gamma + c_delta * s_theta; + + // calculate end lat long + double theta2 = FastMath.asin(z); + double phi2 = FastMath.atan2(y, x); + + return new double[]{FastMath.toDegrees(theta2), FastMath.toDegrees(phi2)}; + } + + static void main(String[] args) { + System.err.println(new MMIIntensityScale().getLevel(pgaFunctionGen2(7.0, 10))); + } + + @SuppressWarnings("unused") + static double placeOnSurface(double travelledDistance, double alt1, double alt2) { + double d = alt1 - alt2; + double angDiff = (travelledDistance * 360.0) / EARTH_CIRCUMFERENCE; + double s2 = travelledDistance * travelledDistance - d * d * FastMath.cos(Math.toRadians(angDiff)); + if (s2 < 0) { + return 0; + } + return FastMath.sqrt(s2); + } + + static double greatCircleDistance(double lat1, double lon1, double lat2, double lon2) { + // Convert latitude and longitude from degrees to radians + lat1 = Math.toRadians(lat1); + lon1 = Math.toRadians(lon1); + lat2 = Math.toRadians(lat2); + lon2 = Math.toRadians(lon2); + + // Compute differences in latitudes and longitudes + double dlat = lat2 - lat1; + double dlon = lon2 - lon1; + + // Haversine formula + double a = Math.pow(Math.sin(dlat / 2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon / 2), 2); + double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); + + return EARTH_RADIUS * c; // Angular distance in radians + } + + + static double calculateAngle(double lat1, double lon1, double lat2, double lon2) { + lat1 = Math.toRadians(lat1); + lon1 = Math.toRadians(lon1); + lat2 = Math.toRadians(lat2); + lon2 = Math.toRadians(lon2); + double dLon = (lon2 - lon1); + + double y = FastMath.sin(dLon) * FastMath.cos(lat2); + double x = FastMath.cos(lat1) * FastMath.sin(lat2) - FastMath.sin(lat1) * FastMath.cos(lat2) * FastMath.cos(dLon); + + double bearing = FastMath.atan2(y, x); + + bearing = FastMath.toDegrees(bearing); + bearing = (bearing + 360) % 360; + // bearing = 360 - bearing; + + return bearing; + } + + static double geologicalDistance(double lat1, double lon1, double alt1, double lat2, double lon2, + double alt2) { + alt1 += EARTH_RADIUS; + alt2 += EARTH_RADIUS; + double x1 = FastMath.sin(Math.toRadians(lon1)) * alt1 * FastMath.cos(Math.toRadians(lat1)); + double z1 = -Math.cos(Math.toRadians(lon1)) * alt1 * FastMath.cos(Math.toRadians(lat1)); + double y1 = FastMath.sin(Math.toRadians(lat1)) * alt1; + + double x2 = FastMath.sin(Math.toRadians(lon2)) * alt2 * FastMath.cos(Math.toRadians(lat2)); + double z2 = -FastMath.cos(Math.toRadians(lon2)) * alt2 * FastMath.cos(Math.toRadians(lat2)); + double y2 = FastMath.sin(Math.toRadians(lat2)) * alt2; + return FastMath.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2)); + } + + static double getMaxPGA(double lat, double lon, double depth, double mag) { + double distGEO = globalquake.core.regions.Regions.getOceanDistance(lat, lon, false, depth); + return GeoUtils.pgaFunction(mag, distGEO, depth); + } + + static double pgaFunction(double mag, double distKm, double depth) { + return pgaFunctionGen2( + mag + 0.4 * EarthquakeAnalysis.getDepthCorrection(depth), + distKm / (1.0 + 0.75 * EarthquakeAnalysis.getDepthCorrection(depth))); + } + + private static double pgaFunctionGen2(double mag, double distKm) { + return Math.pow(10, mag * 0.575) / (0.36 * Math.pow(distKm, 1.25 + mag / 22.0) + 10); + } + + @Deprecated + private static double pgaFunctionGen1(double mag, double distKm) { + distKm = FastMath.abs(distKm); + double a = mag + 1.5; + double b = FastMath.pow((a + 0.9) / 5.5, 7.0); + double c = FastMath.pow((distKm * (14.0 - a * 0.85)) / (FastMath.pow(a, (5.4) / (1 + a * 0.075))), 2.5); + return b / (0.09 + c); + } + + @SuppressWarnings("unused") + static double inversePgaFunctionGen1(double mag, double pga) { + double a = mag + 1.5; + return ((Math.pow((Math.pow((a + 0.9) / 5.5, 7.0)) / pga - 0.09, 1 / 2.5) + * (Math.pow(a, (5.4) / (1 + a * 0.075))))) / (14.0 - a * 0.85); + } + + static double gcdToGeo(double greatCircleDistance) { + return geologicalDistance(0, 0, 0, 0, (360 * greatCircleDistance) / EARTH_CIRCUMFERENCE, 0); + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/utils/LookupTableIO.java b/GlobalQuakeCore/src/main/java/globalquake/utils/LookupTableIO.java index 9782c1ca7..91a4a3eac 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/utils/LookupTableIO.java +++ b/GlobalQuakeCore/src/main/java/globalquake/utils/LookupTableIO.java @@ -11,7 +11,7 @@ public class LookupTableIO { public static boolean exportLookupTableToFile() { List> lookupTables = Regions.generateLookupTablesInParallel(); HashMap lookupTable = new HashMap<>(); - for(HashMap singleLT : lookupTables) { + for (HashMap singleLT : lookupTables) { lookupTable.putAll(singleLT); } @@ -24,11 +24,11 @@ public static boolean exportLookupTableToFile(HashMap lookupTabl private static boolean performExport(HashMap lookupTable) { - try{ + try { ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream("lookupTable.dat")); output.writeObject(lookupTable); output.close(); - } catch (Exception e){ + } catch (Exception e) { System.err.println("Unable to save a lookup table! " + e); return false; } @@ -47,7 +47,7 @@ public static HashMap importLookupTableFromFile() throws IOExcep } HashMap lookupTable; - try{ + try { ObjectInput input = new ObjectInputStream(resource.openStream()); lookupTable = (HashMap) input.readObject(); } catch (IOException | ClassNotFoundException e) { diff --git a/GlobalQuakeCore/src/main/java/globalquake/utils/NamedThreadFactory.java b/GlobalQuakeCore/src/main/java/globalquake/utils/NamedThreadFactory.java index 4bff191cc..bd08660f9 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/utils/NamedThreadFactory.java +++ b/GlobalQuakeCore/src/main/java/globalquake/utils/NamedThreadFactory.java @@ -4,18 +4,18 @@ import java.util.concurrent.ThreadFactory; public class NamedThreadFactory implements ThreadFactory { - - private final String name; - public NamedThreadFactory(String name) { - this.name=name; - } + private final String name; - @Override - public Thread newThread(@Nonnull Runnable r) { - Thread t = new Thread(r); - t.setName(name); - return t; - } + public NamedThreadFactory(String name) { + this.name = name; + } + + @Override + public Thread newThread(@Nonnull Runnable r) { + Thread t = new Thread(r); + t.setName(name); + return t; + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/utils/Scale.java b/GlobalQuakeCore/src/main/java/globalquake/utils/Scale.java index 1cfad7d97..c7760addb 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/utils/Scale.java +++ b/GlobalQuakeCore/src/main/java/globalquake/utils/Scale.java @@ -11,80 +11,81 @@ public class Scale { - public static final double RATIO_THRESHOLD = 50_000.0; - public static final double EXPONENT = 0.25; + public static final double RATIO_THRESHOLD = 50_000.0; + public static final double EXPONENT = 0.25; - public static final boolean ENABLE_INTERPOLATION = false; + public static final boolean ENABLE_INTERPOLATION = false; - private static BufferedImage pgaScale; - public static void load() throws IOException, NullPointerException { - pgaScale = ImageIO.read(Objects.requireNonNull(ClassLoader.getSystemClassLoader().getResource("scales/pgaScale3.png"))); - } + private static BufferedImage pgaScale; - public static Color getColorRatio(double ratio){ - return Settings.useOldColorScheme ? getColorRatioOld(ratio) : getColorRatioNew(ratio); - } + public static void load() throws IOException, NullPointerException { + pgaScale = ImageIO.read(Objects.requireNonNull(ClassLoader.getSystemClassLoader().getResource("scales/pgaScale3.png"))); + } - public static Color getColorRatioOld(double ratio) { - int i = (int) (Math.log10(ratio) * 20.0); - return new Color(pgaScale.getRGB(0, Math.max(0, Math.min(pgaScale.getHeight() - 1, i)))); - } + public static Color getColorRatio(double ratio) { + return Settings.useOldColorScheme ? getColorRatioOld(ratio) : getColorRatioNew(ratio); + } - private static final double K = FastMath.pow(RATIO_THRESHOLD, EXPONENT); + public static Color getColorRatioOld(double ratio) { + int i = (int) (Math.log10(ratio) * 20.0); + return new Color(pgaScale.getRGB(0, Math.max(0, Math.min(pgaScale.getHeight() - 1, i)))); + } - public static Color getColorRatioNew(double ratio) { - if(ratio < 1){ - return new Color(pgaScale.getRGB(0, 0)); - } + private static final double K = FastMath.pow(RATIO_THRESHOLD, EXPONENT); - double pct = Math.pow(ratio - 1.0, EXPONENT) / K; + public static Color getColorRatioNew(double ratio) { + if (ratio < 1) { + return new Color(pgaScale.getRGB(0, 0)); + } - int i1 = (int)(pct * (pgaScale.getHeight() - 1)); - int i2 = i1 + 1; + double pct = Math.pow(ratio - 1.0, EXPONENT) / K; - if(i1 < 0){ - return new Color(pgaScale.getRGB(0, 0)); - } else if (i1 >= pgaScale.getHeight() - 1){ - return new Color(pgaScale.getRGB(0, pgaScale.getHeight() - 1)); - } + int i1 = (int) (pct * (pgaScale.getHeight() - 1)); + int i2 = i1 + 1; - if(!ENABLE_INTERPOLATION){ - return new Color(pgaScale.getRGB(0, i1)); - } + if (i1 < 0) { + return new Color(pgaScale.getRGB(0, 0)); + } else if (i1 >= pgaScale.getHeight() - 1) { + return new Color(pgaScale.getRGB(0, pgaScale.getHeight() - 1)); + } - double weight = (pct * (pgaScale.getHeight() - 1)) - i1; + if (!ENABLE_INTERPOLATION) { + return new Color(pgaScale.getRGB(0, i1)); + } - Color color1 = new Color(pgaScale.getRGB(0, i1)); - Color color2 = new Color(pgaScale.getRGB(0, i2)); + double weight = (pct * (pgaScale.getHeight() - 1)) - i1; - return interpolateColors(color1, color2, weight); - } + Color color1 = new Color(pgaScale.getRGB(0, i1)); + Color color2 = new Color(pgaScale.getRGB(0, i2)); - public static Color interpolateColors(Color color1, Color color2, double weight) { - // Make sure weight is within the range [0, 1] - weight = Math.max(0, Math.min(1, weight)); + return interpolateColors(color1, color2, weight); + } - // Extract RGB components of the two colors - int r1 = color1.getRed(); - int g1 = color1.getGreen(); - int b1 = color1.getBlue(); + public static Color interpolateColors(Color color1, Color color2, double weight) { + // Make sure weight is within the range [0, 1] + weight = Math.max(0, Math.min(1, weight)); - int r2 = color2.getRed(); - int g2 = color2.getGreen(); - int b2 = color2.getBlue(); + // Extract RGB components of the two colors + int r1 = color1.getRed(); + int g1 = color1.getGreen(); + int b1 = color1.getBlue(); - // Interpolate RGB components - int rInterpolated = (int) (r1 * (1 - weight) + r2 * weight); - int gInterpolated = (int) (g1 * (1 - weight) + g2 * weight); - int bInterpolated = (int) (b1 * (1 - weight) + b2 * weight); + int r2 = color2.getRed(); + int g2 = color2.getGreen(); + int b2 = color2.getBlue(); - // Create the interpolated color - return new Color(rInterpolated, gInterpolated, bInterpolated); - } + // Interpolate RGB components + int rInterpolated = (int) (r1 * (1 - weight) + r2 * weight); + int gInterpolated = (int) (g1 * (1 - weight) + g2 * weight); + int bInterpolated = (int) (b1 * (1 - weight) + b2 * weight); - public static Color getColorEasily(double ratio) { - int i = (int) ((pgaScale.getHeight() - 1) * ratio); - return new Color(pgaScale.getRGB(0, Math.max(0, Math.min(pgaScale.getHeight() - 1, i)))); - } + // Create the interpolated color + return new Color(rInterpolated, gInterpolated, bInterpolated); + } + + public static Color getColorEasily(double ratio) { + int i = (int) ((pgaScale.getHeight() - 1) * ratio); + return new Color(pgaScale.getRGB(0, Math.max(0, Math.min(pgaScale.getHeight() - 1, i)))); + } } diff --git a/GlobalQuakeCore/src/main/java/globalquake/utils/monitorable/Monitorable.java b/GlobalQuakeCore/src/main/java/globalquake/utils/monitorable/Monitorable.java index 9e582a4db..1b161df3d 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/utils/monitorable/Monitorable.java +++ b/GlobalQuakeCore/src/main/java/globalquake/utils/monitorable/Monitorable.java @@ -6,11 +6,11 @@ public interface Monitorable { AtomicInteger monitor = new AtomicInteger(0); - default int getMonitorState(){ + default int getMonitorState() { return monitor.get(); } - default void noteChange(){ + default void noteChange() { monitor.incrementAndGet(); } diff --git a/GlobalQuakeCore/src/main/java/globalquake/utils/monitorable/MonitorableConcurrentLinkedQueue.java b/GlobalQuakeCore/src/main/java/globalquake/utils/monitorable/MonitorableConcurrentLinkedQueue.java index 0df109a55..bf800e728 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/utils/monitorable/MonitorableConcurrentLinkedQueue.java +++ b/GlobalQuakeCore/src/main/java/globalquake/utils/monitorable/MonitorableConcurrentLinkedQueue.java @@ -10,7 +10,7 @@ public MonitorableConcurrentLinkedQueue(Collection tmpList) { super(tmpList); } - public MonitorableConcurrentLinkedQueue(){ + public MonitorableConcurrentLinkedQueue() { super(); } diff --git a/GlobalQuakeCore/src/main/java/globalquake/utils/monitorable/MonitorableCopyOnWriteArrayList.java b/GlobalQuakeCore/src/main/java/globalquake/utils/monitorable/MonitorableCopyOnWriteArrayList.java index d8faf7b78..581c09da9 100644 --- a/GlobalQuakeCore/src/main/java/globalquake/utils/monitorable/MonitorableCopyOnWriteArrayList.java +++ b/GlobalQuakeCore/src/main/java/globalquake/utils/monitorable/MonitorableCopyOnWriteArrayList.java @@ -11,7 +11,7 @@ public MonitorableCopyOnWriteArrayList(List tmpList) { super(tmpList); } - public MonitorableCopyOnWriteArrayList(){ + public MonitorableCopyOnWriteArrayList() { super(); } diff --git a/GlobalQuakeCore/src/test/java/globalquake/core/database/StationDatabaseManagerTest.java b/GlobalQuakeCore/src/test/java/globalquake/core/database/StationDatabaseManagerTest.java index c2871f748..b3fb8a241 100644 --- a/GlobalQuakeCore/src/test/java/globalquake/core/database/StationDatabaseManagerTest.java +++ b/GlobalQuakeCore/src/test/java/globalquake/core/database/StationDatabaseManagerTest.java @@ -12,7 +12,7 @@ public class StationDatabaseManagerTest { @Test - public void testConstructor(){ + public void testConstructor() { StationDatabase stationDatabase = new StationDatabase(); StationDatabaseManager databaseManager = new StationDatabaseManager(stationDatabase); @@ -20,7 +20,7 @@ public void testConstructor(){ } @Test - public void testAcceptChannel(){ + public void testAcceptChannel() { Network dummyNetwork = new Network("coolNetwork", ""); Station dummyStation = new Station(dummyNetwork, "coolStation", "", 0, 0, 0); Channel dummyChannel = new Channel("coolChannel", "00", 50, 0, 0, 0, null, -1, InputType.UNKNOWN); @@ -36,7 +36,7 @@ public void testAcceptChannel(){ } @Test - public void testAcceptAnotherChannel(){ + public void testAcceptAnotherChannel() { Network dummyNetwork = new Network("coolNetwork", ""); Station dummyStation = new Station(dummyNetwork, "coolStation", "", 0, 0, 0); Channel dummyChannel = new Channel("coolChannel", "00", 50, 0, 0, 0, null, -1, InputType.UNKNOWN); @@ -64,7 +64,7 @@ public void testAcceptAnotherChannel(){ } @Test - public void testRemoveStationSource(){ + public void testRemoveStationSource() { StationSource stationSource1 = new StationSource("1", ""); StationSource stationSource2 = new StationSource("2", ""); Network dummyNetwork = new Network("coolNetwork", ""); @@ -112,7 +112,7 @@ public void testRemoveStationSource(){ } @Test - public void testBasicallyEverything(){ + public void testBasicallyEverything() { SeedlinkNetwork dummySeedlinkNetwork = new SeedlinkNetwork("dummy", "", 5); SeedlinkNetwork dummySeedlinkNetwork2 = new SeedlinkNetwork("dummy2", "", 5); StationSource stationSource1 = new StationSource("1", ""); @@ -188,7 +188,7 @@ public void testBasicallyEverything(){ } @Test - public void testChannelUpdate(){ + public void testChannelUpdate() { Network dummyNetwork = new Network("coolNetwork", ""); Station dummyStation = new Station(dummyNetwork, "coolStation", "", 0, 0, 0); Channel dummyChannel = new Channel("coolChannel", "00", 50, 0, 0, 0, null, -1, InputType.UNKNOWN); @@ -211,7 +211,7 @@ public void testChannelUpdate(){ } @Test - public void testAcceptNetworks(){ + public void testAcceptNetworks() { Network dummyNetwork = new Network("coolNetwork", ""); Station dummyStation = new Station(dummyNetwork, "coolStation", "", 0, 0, 0); Channel dummyChannel = new Channel("coolChannel", "00", 50, 0, 0, 0, null, -1, InputType.UNKNOWN); @@ -226,7 +226,7 @@ public void testAcceptNetworks(){ } @Test - public void testChannelDeselectWhenRemoveAllSeedlinks(){ + public void testChannelDeselectWhenRemoveAllSeedlinks() { SeedlinkNetwork seedlinkNetwork = new SeedlinkNetwork("dummy", "D", 5); Network dummyNetwork = new Network("coolNetwork", ""); Station dummyStation = new Station(dummyNetwork, "coolStation", "", 0, 0, 0); diff --git a/GlobalQuakeCore/src/test/java/globalquake/core/earthquake/EarthquakeAnalysisTest.java b/GlobalQuakeCore/src/test/java/globalquake/core/earthquake/EarthquakeAnalysisTest.java index d2384f0e5..46f8c1447 100644 --- a/GlobalQuakeCore/src/test/java/globalquake/core/earthquake/EarthquakeAnalysisTest.java +++ b/GlobalQuakeCore/src/test/java/globalquake/core/earthquake/EarthquakeAnalysisTest.java @@ -13,41 +13,41 @@ public class EarthquakeAnalysisTest { @Test - public void testMagnitudeSelectionEmptyList(){ + public void testMagnitudeSelectionEmptyList() { List mags = new ArrayList<>(); assertEquals(EarthquakeAnalysis.selectMagnitude(mags), EarthquakeAnalysis.NO_MAGNITUDE, 0.1); } @Test - public void testMagnitudeSelectionSingleVal(){ + public void testMagnitudeSelectionSingleVal() { List mags = new ArrayList<>(); - mags.add(new MagnitudeReading(4,1, 55555, InputType.VELOCITY)); + mags.add(new MagnitudeReading(4, 1, 55555, InputType.VELOCITY)); assertEquals(EarthquakeAnalysis.selectMagnitude(mags), 4.0, 0.1); } @Test - public void testMagnitudeSelectionSimple(){ + public void testMagnitudeSelectionSimple() { List mags = new ArrayList<>(); - mags.add(new MagnitudeReading(4,1, 55555, InputType.VELOCITY)); - mags.add(new MagnitudeReading(4,10, 55555, InputType.VELOCITY)); - mags.add(new MagnitudeReading(4,100, 55555, InputType.VELOCITY)); + mags.add(new MagnitudeReading(4, 1, 55555, InputType.VELOCITY)); + mags.add(new MagnitudeReading(4, 10, 55555, InputType.VELOCITY)); + mags.add(new MagnitudeReading(4, 100, 55555, InputType.VELOCITY)); assertEquals(EarthquakeAnalysis.selectMagnitude(mags), 4.0, 0.1); } @Test - public void testMagnitudeSelectionSort(){ + public void testMagnitudeSelectionSort() { List mags = new ArrayList<>(); - mags.add(new MagnitudeReading(1,1, 55555, InputType.VELOCITY)); - mags.add(new MagnitudeReading(2,10, 55555, InputType.VELOCITY)); - mags.add(new MagnitudeReading(3,100, 55555, InputType.VELOCITY)); - mags.add(new MagnitudeReading(4,100, 55555, InputType.VELOCITY)); - mags.add(new MagnitudeReading(5,100, 55555, InputType.VELOCITY)); + mags.add(new MagnitudeReading(1, 1, 55555, InputType.VELOCITY)); + mags.add(new MagnitudeReading(2, 10, 55555, InputType.VELOCITY)); + mags.add(new MagnitudeReading(3, 100, 55555, InputType.VELOCITY)); + mags.add(new MagnitudeReading(4, 100, 55555, InputType.VELOCITY)); + mags.add(new MagnitudeReading(5, 100, 55555, InputType.VELOCITY)); Collections.shuffle(mags); @@ -55,18 +55,18 @@ public void testMagnitudeSelectionSort(){ } @Test - public void testMagnitudeSelectionDistant(){ + public void testMagnitudeSelectionDistant() { List mags = new ArrayList<>(); - mags.add(new MagnitudeReading(4,1, 55555, InputType.VELOCITY)); - mags.add(new MagnitudeReading(4,10, 55555, InputType.VELOCITY)); - mags.add(new MagnitudeReading(4,100, 55555, InputType.VELOCITY)); - mags.add(new MagnitudeReading(9,10_000, 55555, InputType.VELOCITY)); - mags.add(new MagnitudeReading(9,10_000, 55555, InputType.VELOCITY)); - mags.add(new MagnitudeReading(9,10_000, 55555, InputType.VELOCITY)); - mags.add(new MagnitudeReading(9,10_000, 55555, InputType.VELOCITY)); - mags.add(new MagnitudeReading(9,10_000, 55555, InputType.VELOCITY)); - mags.add(new MagnitudeReading(9,10_000, 55555, InputType.VELOCITY)); + mags.add(new MagnitudeReading(4, 1, 55555, InputType.VELOCITY)); + mags.add(new MagnitudeReading(4, 10, 55555, InputType.VELOCITY)); + mags.add(new MagnitudeReading(4, 100, 55555, InputType.VELOCITY)); + mags.add(new MagnitudeReading(9, 10_000, 55555, InputType.VELOCITY)); + mags.add(new MagnitudeReading(9, 10_000, 55555, InputType.VELOCITY)); + mags.add(new MagnitudeReading(9, 10_000, 55555, InputType.VELOCITY)); + mags.add(new MagnitudeReading(9, 10_000, 55555, InputType.VELOCITY)); + mags.add(new MagnitudeReading(9, 10_000, 55555, InputType.VELOCITY)); + mags.add(new MagnitudeReading(9, 10_000, 55555, InputType.VELOCITY)); Collections.shuffle(mags); @@ -74,18 +74,18 @@ public void testMagnitudeSelectionDistant(){ } @Test - public void testMagnitudeSelectionMany(){ + public void testMagnitudeSelectionMany() { List mags = new ArrayList<>(); - for(int i = 0; i < 100; i++) { + for (int i = 0; i < 100; i++) { mags.add(new MagnitudeReading(4, 1, 55555, InputType.VELOCITY)); } - for(int i = 0; i < 100; i++) { + for (int i = 0; i < 100; i++) { mags.add(new MagnitudeReading(6, 3000, 55555, InputType.VELOCITY)); } - for(int i = 0; i < 100; i++) { + for (int i = 0; i < 100; i++) { mags.add(new MagnitudeReading(8, 10000, 55555, InputType.VELOCITY)); } diff --git a/GlobalQuakeCore/src/test/java/globalquake/core/geo/taup/DifferenceTest.java b/GlobalQuakeCore/src/test/java/globalquake/core/geo/taup/DifferenceTest.java index 0283034dd..638a7191e 100644 --- a/GlobalQuakeCore/src/test/java/globalquake/core/geo/taup/DifferenceTest.java +++ b/GlobalQuakeCore/src/test/java/globalquake/core/geo/taup/DifferenceTest.java @@ -11,7 +11,7 @@ public static void main(String[] args) throws Exception { double ang = TauPTravelTimeCalculator.toAngle(8372.6); for (double depth = 0; depth < 50; depth += 0.5) { - System.out.printf("%.1fkm: %.3fs%n",depth, TauPTravelTimeCalculator.getPWaveTravelTime(depth, ang) - TravelTimeTableOld.getPWaveTravelTime(depth, ang)); + System.out.printf("%.1fkm: %.3fs%n", depth, TauPTravelTimeCalculator.getPWaveTravelTime(depth, ang) - TravelTimeTableOld.getPWaveTravelTime(depth, ang)); } } diff --git a/GlobalQuakeCore/src/test/java/globalquake/core/geo/taup/TauPTravelTimeCalculatorTest.java b/GlobalQuakeCore/src/test/java/globalquake/core/geo/taup/TauPTravelTimeCalculatorTest.java index bbe5a201e..d2878e274 100644 --- a/GlobalQuakeCore/src/test/java/globalquake/core/geo/taup/TauPTravelTimeCalculatorTest.java +++ b/GlobalQuakeCore/src/test/java/globalquake/core/geo/taup/TauPTravelTimeCalculatorTest.java @@ -11,8 +11,8 @@ public class TauPTravelTimeCalculatorTest { public void testTravelTimeZeroDistance() throws FatalApplicationException { TauPTravelTimeCalculator.init(); - assertEquals(0, Math.abs(TauPTravelTimeCalculator.getPWaveTravelTime(0, 0)) ,1e-6); - assertEquals(0, Math.abs(TauPTravelTimeCalculator.getSWaveTravelTime(0, 0)) , 1e-6); + assertEquals(0, Math.abs(TauPTravelTimeCalculator.getPWaveTravelTime(0, 0)), 1e-6); + assertEquals(0, Math.abs(TauPTravelTimeCalculator.getSWaveTravelTime(0, 0)), 1e-6); } @Test @@ -37,7 +37,7 @@ public void sanityTestTravelTime0KM() throws FatalApplicationException { public void sanityTestTravelTimeVarious() throws FatalApplicationException { TauPTravelTimeCalculator.init(); - for(double depth = 0; depth < 600; depth += 1) { + for (double depth = 0; depth < 600; depth += 1) { for (double ang = 10; ang <= 100; ang += 1) { assertEquals("%s˚ %skm".formatted(ang, depth), TravelTimeTableOld.getPWaveTravelTime(depth, ang), TauPTravelTimeCalculator.getPWaveTravelTime(depth, ang), 2.0); assertEquals("%s˚ %skm".formatted(ang, depth), TravelTimeTableOld.getSWaveTravelTime(depth, ang), TauPTravelTimeCalculator.getSWaveTravelTime(depth, ang), 2.0); @@ -49,20 +49,20 @@ public void sanityTestTravelTimeVarious() throws FatalApplicationException { public void sanityTestTravelAngle() throws FatalApplicationException { TauPTravelTimeCalculator.init(); - for(double depth = 0; depth < 600; depth += 1) { + for (double depth = 0; depth < 600; depth += 1) { for (double ang = 0; ang < 150; ang += 1) { assertEquals("%s˚ %skm".formatted(ang, depth), ang, TauPTravelTimeCalculator.getPWaveTravelAngle(depth, TauPTravelTimeCalculator.getPWaveTravelTime(depth, ang)), - 1e-4); + 1e-4); } } } @Test - public void testNoCrash() throws Exception{ + public void testNoCrash() throws Exception { TauPTravelTimeCalculator.init(); - for(double depth = -20; depth <= 1000; depth += 0.04){ - for(double ang = -20; ang <= 200; ang += 0.04){ + for (double depth = -20; depth <= 1000; depth += 0.04) { + for (double ang = -20; ang <= 200; ang += 0.04) { TauPTravelTimeCalculator.getPWaveTravelTimeFast(depth, ang); TauPTravelTimeCalculator.getPWaveTravelTime(depth, ang); } @@ -70,17 +70,17 @@ public void testNoCrash() throws Exception{ } @Test - public void testBigAngle() throws Exception{ + public void testBigAngle() throws Exception { TauPTravelTimeCalculator.init(); assertEquals(TauPTravelTimeCalculator.NO_ARRIVAL, TauPTravelTimeCalculator.getPWaveTravelAngle(0, 40 * 60), 1e-6); assertEquals(TauPTravelTimeCalculator.NO_ARRIVAL, TauPTravelTimeCalculator.getPWaveTravelAngle(0, -40 * 60), 1e-6); - assertEquals(TauPTravelTimeCalculator.NO_ARRIVAL,TauPTravelTimeCalculator.getPKIKPWaveTravelAngle(0, 2 * 60), 1e-6); + assertEquals(TauPTravelTimeCalculator.NO_ARRIVAL, TauPTravelTimeCalculator.getPKIKPWaveTravelAngle(0, 2 * 60), 1e-6); assertEquals(TauPTravelTimeCalculator.NO_ARRIVAL, TauPTravelTimeCalculator.getPKPWaveTravelAngle(0, 2 * 60), 1e-6); } @Test - public void testPKP() throws Exception{ + public void testPKP() throws Exception { TauPTravelTimeCalculator.init(); assertEquals(153.35, TauPTravelTimeCalculator.getPKPWaveTravelAngle(0, 1200.0), 0.5); @@ -96,11 +96,11 @@ public void testPKP() throws Exception{ assertEquals(153, TauPTravelTimeCalculator.getPKPWaveTravelAngle(0, 1199.21), 0.5); assertEquals(154, TauPTravelTimeCalculator.getPKPWaveTravelAngle(0, 1201.45), 0.5); assertEquals(155, TauPTravelTimeCalculator.getPKPWaveTravelAngle(0, 1203.61), 0.5); - assertEquals(156, TauPTravelTimeCalculator.getPKPWaveTravelAngle(0, 1222.92), 0.5); + assertEquals(156, TauPTravelTimeCalculator.getPKPWaveTravelAngle(0, 1222.92), 0.5); } @Test - public void testPKIKP() throws Exception{ + public void testPKIKP() throws Exception { TauPTravelTimeCalculator.init(); assertEquals(1212.09, TauPTravelTimeCalculator.getPKIKPWaveTravelTime(0, 180.0), 0.5); @@ -115,7 +115,7 @@ public void testPKIKP() throws Exception{ assertEquals(40, TauPTravelTimeCalculator.getPKIKPWaveTravelAngle(0, 1012.15), 0.5); assertEquals(80, TauPTravelTimeCalculator.getPKIKPWaveTravelAngle(0, 1061.23), 0.5); assertEquals(150, TauPTravelTimeCalculator.getPKIKPWaveTravelAngle(0, 1186.73), 0.5); - assertEquals(179.9, TauPTravelTimeCalculator.getPKIKPWaveTravelAngle(0, 1212.09), 0.5); + assertEquals(179.9, TauPTravelTimeCalculator.getPKIKPWaveTravelAngle(0, 1212.09), 0.5); } } \ No newline at end of file diff --git a/GlobalQuakeCore/src/test/java/globalquake/core/geo/taup/TravelTimeTableOld.java b/GlobalQuakeCore/src/test/java/globalquake/core/geo/taup/TravelTimeTableOld.java index 732cccfde..26ad96fcd 100644 --- a/GlobalQuakeCore/src/test/java/globalquake/core/geo/taup/TravelTimeTableOld.java +++ b/GlobalQuakeCore/src/test/java/globalquake/core/geo/taup/TravelTimeTableOld.java @@ -7,900 +7,899 @@ @SuppressWarnings("unused") public class TravelTimeTableOld { - public static final double[] DEPTHS = { 0, 15, 35, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, - 700 }; - public static final double[] DEPTHS_PKP = { 0, 35, 50, 100, 200, 300, 500, 700 }; - - private static final int PKP_START = 113; - - public static final ArrayList PTravelTimeTable = new ArrayList<>(); - public static final ArrayList STravelTimeTable = new ArrayList<>(); - public static final ArrayList PKPTravelTimeTable = new ArrayList<>(); - - static { - fillTable(); - } - - private static void fillTable() { - PTravelTimeTable.add(new double[] { 0.0, 2.59, 5.76, 7.62, 13.84, 20.03, 26.12, 32.11, 37.97, 43.7, 49.32, - 54.67, 59.89, 65.02, 70.07, 75.02, 79.7 }); - PTravelTimeTable.add(new double[] { 19.17, 19.01, 17.51, 17.7, 20.39, 24.73, 29.72, 34.99, 40.34, 45.71, 51.05, - 56.18, 61.23, 66.21, 71.14, 76.0, 80.58 }); - PTravelTimeTable.add(new double[] { 35.03, 33.23, 31.27, 31.32, 32.54, 35.08, 38.47, 42.42, 46.73, 51.26, 55.91, - 60.47, 65.03, 69.62, 74.22, 78.78999999999999, 83.13 }); - PTravelTimeTable.add(new double[] { 48.78, 46.98, 45.02, 45.02, 45.71, 47.32, 49.59, 52.43, 55.71, 59.31, 63.16, - 66.97, 70.91, 74.95, 79.07, 83.24, 87.18 }); - PTravelTimeTable.add(new double[] { 62.53, 60.73, 58.77, 58.74, 59.14, 60.2, 61.73, 63.75, 66.17, 68.95, 72.02, - 75.09, 78.35, 81.78999999999999, 85.37, 89.06, 92.55 }); - PTravelTimeTable.add(new double[] { 76.27, 74.47, 72.51, 72.45, 72.67, 73.36, 74.35, 75.74, 77.48, 79.56, 81.95, - 84.31, 86.91, 89.76, 92.78999999999999, 95.97999999999999, 98.97 }); - PTravelTimeTable.add(new double[] { 90.01, 88.21000000000001, 86.25, 86.17, 86.24, 86.64, 87.2, 88.08, 89.26, - 90.76, 92.56, 94.25, 96.25, 98.53999999999999, 101.05, 103.74000000000001, 106.22999999999999 }); - PTravelTimeTable.add(new double[] { 103.75, 101.94, 99.97999999999999, 99.88, 99.83, 99.97999999999999, 100.17, - 100.62, 101.32, 102.32, 103.61, 104.66, 106.12, 107.89, 109.92, 112.15, 114.12 }); - PTravelTimeTable.add(new double[] { 117.47, 115.67, 113.7, 113.58, 113.42, 113.33, 113.18, 113.24000000000001, - 113.52000000000001, 114.08, 114.92, 115.35, 116.33, 117.64, 119.22999999999999, 121.02, 122.49 }); - PTravelTimeTable.add(new double[] { 131.19, 129.38, 127.41, 127.27, 127.02, 126.66, 126.2, 125.89, 125.79, - 125.96, 126.4, 126.17, 126.74, 127.66, 128.84, 130.24, 131.18 }); - PTravelTimeTable.add(new double[] { 144.9, 143.09, 141.12, 140.96, 140.62, 139.93, 139.17000000000002, 138.51, - 138.07, 137.88, 137.52, 137.05, 137.28, 137.84, 138.66, 139.7, 140.09 }); - PTravelTimeTable.add(new double[] { 158.59, 156.78, 154.81, 154.63, 154.21, 153.12, 152.05, 151.06, 150.3, - 149.8, 148.59, 147.93, 147.87, 148.12, 148.61, 149.32999999999998, 149.11 }); - PTravelTimeTable.add(new double[] { 172.27, 170.46, 168.48, 168.29, 167.59, 166.19, 164.8, 163.51, 162.47, - 161.55, 159.62, 158.79, 158.47, 158.44, 158.64, 158.56, 158.17000000000002 }); - PTravelTimeTable.add(new double[] { 185.94, 184.13, 182.14, 181.93, 180.8, 179.1, 177.41, 175.85, 174.55, 172.6, - 170.61, 169.61, 169.06, 168.77, 168.71, 167.78, 167.26 }); - PTravelTimeTable.add(new double[] { 199.59, 197.78, 195.79, 195.56, 193.83, 191.81, 189.85, 188.06, 185.98, - 183.6, 181.54, 180.37, 179.61, 179.09, 178.78, 176.97, 176.34 }); - PTravelTimeTable.add(new double[] { 213.23, 211.41, 209.32, 208.75, 206.63, 204.32, 202.13, 199.74, 196.99, - 194.54, 192.39, 191.06, 190.11, 189.37, 188.06, 186.15, 185.4 }); - PTravelTimeTable - .add(new double[] { 226.37, 224.46, 222.31, 221.62, 219.17000000000002, 216.64, 213.82999999999998, - 210.73, 207.93, 205.41, 203.17000000000002, 201.68, 200.53, 199.44, 197.24, 195.29, 194.44 }); - PTravelTimeTable.add(new double[] { 239.13, 237.17000000000002, 234.96, 234.17000000000002, 231.49, 228.19, - 224.81, 221.67000000000002, 218.79, 216.19, 213.85, 212.21, 210.88, 208.62, 206.39, 204.41, 203.45 }); - PTravelTimeTable.add(new double[] { 251.57, 249.59, 247.33, 246.46, 242.77, 239.15, 235.72, 232.52, 229.57, - 226.88, 224.43, 222.63, 220.26, 217.77, 215.51, 213.48, 212.42000000000002 }); - PTravelTimeTable.add(new double[] { 263.16, 261.04, 258.57, 257.44, 253.71, 250.04, 246.55, 243.28, 240.24, - 237.45, 234.9, 232.15, 229.41, 226.89, 224.59, 222.52, 221.35 }); - PTravelTimeTable.add(new double[] { 274.1, 271.97, 269.49, 268.35, 264.56, 260.83, 257.28, 253.93, 250.81, - 247.86, 244.33, 241.29, 238.53, 235.97, 233.63, 231.5, 230.23 }); - PTravelTimeTable.add(new double[] { 284.95, 282.82, 280.32, 279.15999999999997, 275.32, 271.52, 267.89, 264.46, - 260.76, 257.01, 253.47, 250.4, 247.6, 245.01, 242.62, 240.43, 239.09 }); - PTravelTimeTable.add(new double[] { 295.71, 293.56, 291.05, 289.87, 285.96, 282.09000000000003, - 278.09000000000003, 273.89, 269.9, 266.12, 262.56, 259.46, 256.63, 253.99, 251.54, 249.31, 247.93 }); - PTravelTimeTable.add(new double[] { 306.34, 304.18, 301.65, 300.46, 296.18, 291.62, 287.22, 283.0, 279.0, 275.2, - 271.61, 268.48, 265.6, 262.91, 260.43, 258.16, 256.73 }); - PTravelTimeTable.add(new double[] { 316.31, 314.04, 311.33, 309.94, 305.31, 300.74, 296.32, 292.08, 288.05, - 284.23, 280.61, 277.43, 274.51, 271.79, 269.28, 266.99, 265.51 }); - PTravelTimeTable.add(new double[] { 325.43, 323.15, 320.44, 319.04, 314.4, 309.81, 305.37, 301.11, 297.05, - 293.2, 289.53, 286.33, 283.38, 280.64, 278.1, 275.78, 274.25 }); - PTravelTimeTable.add(new double[] { 334.5, 332.23, 329.51, 328.11, 323.45, 318.83, 314.37, 310.08, 305.99, - 302.1, 298.42, 295.19, 292.22, 289.45, 286.89, 284.54, 282.94 }); - PTravelTimeTable.add(new double[] { 343.54, 341.25, 338.53, 337.12, 332.44, 327.79, 323.3, 318.99, 314.88, - 310.97, 307.27, 304.02, 301.03, 298.24, 295.65, 293.25, 291.58 }); - PTravelTimeTable.add(new double[] { 352.5, 350.22, 347.49, 346.07, 341.35, 336.69, 332.19, 327.85, 323.73, - 319.81, 316.09, 312.82, 309.81, 306.99, 304.36, 301.91, 300.17 }); - PTravelTimeTable.add(new double[] { 361.41, 359.12, 356.38, 354.96, 350.23, 345.56, 341.04, 336.69, 332.55, - 328.62, 324.88, 321.59, 318.55, 315.69, 313.01, 310.52, 308.71 }); - PTravelTimeTable.add(new double[] { 370.27, 367.98, 365.24, 363.82, 359.08, 354.39, 349.86, 345.5, - 341.34000000000003, 337.39, 333.63, 330.31, 327.23, 324.33, 321.61, 319.07, 317.2 }); - PTravelTimeTable.add(new double[] { 379.11, 376.81, 374.07, 372.64, 367.89, 363.19, 358.64, 354.27, - 350.09000000000003, 346.11, 342.33, 338.97, 335.85, 332.90999999999997, 330.15, 327.57, 325.63 }); - PTravelTimeTable.add(new double[] { 387.91, 385.62, 382.87, 381.44, 376.67, 371.96, 367.39, 362.99, 358.79, - 354.78, 350.97, 347.58, 344.42, 341.44, 338.64, 336.01, 334.01 }); - PTravelTimeTable.add(new double[] { 396.68, 394.38, 391.63, 390.19, 385.41, 380.67, 376.08, 371.66, 367.43, - 363.4, 359.55, 356.13, 352.93, 349.90999999999997, 347.06, 344.39, 342.32 }); - PTravelTimeTable.add(new double[] { 405.4, 403.09000000000003, 400.34000000000003, 398.89, 394.09000000000003, - 389.33, 384.71, 380.27, 376.01, 371.95, 368.07, 364.61, 361.38, 358.32, 355.43, 352.71, 350.58 }); - PTravelTimeTable.add(new double[] { 414.06, 411.75, 408.99, 407.54, 402.71, 397.93, 393.29, 388.82, 384.53, - 380.44, 376.54, 373.04, 369.77, 366.67, 363.73, 360.96, 358.78 }); - PTravelTimeTable.add(new double[] { 422.66, 420.34, 417.58, 416.12, 411.27, 406.46, 401.8, 397.3, 392.99, - 388.87, 384.94, 381.41, 378.1, 374.96, 371.98, 369.16, 366.92 }); - PTravelTimeTable.add(new double[] { 431.19, 428.88, 426.1, 424.64, 419.76, 414.94, 410.25, 405.73, 401.39, - 397.24, 393.27, 389.71, 386.36, 383.18, 380.16, 377.3, 375.0 }); - PTravelTimeTable.add(new double[] { 439.67, 437.35, 434.57, 433.09, 428.2, 423.35, 418.64, 414.09000000000003, - 409.72, 405.54, 401.54, 397.94, 394.56, 391.34, 388.27, 385.37, 383.02 }); - PTravelTimeTable.add(new double[] { 448.08, 445.75, 442.97, 441.49, 436.57, 431.69, 426.96, 422.38, 417.99, - 413.78, 409.75, 406.11, 402.69, 399.43, 396.33, 393.38, 390.97 }); - PTravelTimeTable.add(new double[] { 456.42, 454.09000000000003, 451.3, 449.81, 444.87, 439.97, 435.21, 430.6, - 426.19, 421.95, 417.88, 414.22, 410.76, 407.46, 404.31, 401.32, 398.86 }); - PTravelTimeTable.add(new double[] { 464.7, 462.36, 459.56, 458.07, 453.1, 448.18, 443.39, 438.76, 434.32, - 430.05, 425.96, 422.25, 418.76, 415.42, 412.23, 409.2, 406.69 }); - PTravelTimeTable.add(new double[] { 472.9, 470.56, 467.76, 466.26, 461.27, 456.32, 451.51, 446.85, 442.38, - 438.08, 433.96, 430.22, 426.69, 423.32, 420.09, 417.01, 414.45 }); - PTravelTimeTable.add(new double[] { 481.04, 478.7, 475.88, 474.38, 469.36, 464.39, 459.56, 454.87, 450.37, - 446.05, 441.89, 438.12, 434.56, 431.14, 427.88, 424.76, 422.14 }); - PTravelTimeTable.add(new double[] { 489.11, 486.76, 483.94, 482.43, 477.39, 472.39, 467.53, 462.83, 458.3, - 453.94, 449.76, 445.96, 442.36, 438.9, 435.6, 432.44, 429.77 }); - PTravelTimeTable.add(new double[] { 497.1, 494.75, 491.93, 490.4, 485.34, 480.32, 475.44, 470.71, 466.15, - 461.77, 457.55, 453.72, 450.08, 446.59, 443.25, 440.05, 437.34 }); - PTravelTimeTable.add(new double[] { 505.03, 502.67, 499.84, 498.31, 493.23, 488.18, 483.27, 478.52, 473.93, - 469.52, 465.28, 461.40999999999997, 457.74, 454.22, 450.84, 447.6, 444.84 }); - PTravelTimeTable.add(new double[] { 512.88, 510.52, 507.68, 506.14, 501.04, 495.97, 491.04, 486.26, 481.65, - 477.21, 472.94, 469.04, 465.33, 461.77, 458.35, 455.08, 452.27 }); - PTravelTimeTable.add(new double[] { 520.66, 518.29, 515.45, 513.91, 508.78, 503.69, 498.73, 493.92, 489.29, - 484.82, 480.52, 476.59000000000003, 472.85, 469.26, 465.8, 462.49, 459.65 }); - PTravelTimeTable.add(new double[] { 528.37, 526.0, 523.15, 521.6, 516.44, 511.33, 506.35, 501.52, 496.86, - 492.37, 488.04, 484.08, 480.31, 476.68, 473.19, 469.84000000000003, 466.95 }); - PTravelTimeTable.add(new double[] { 536.0, 533.63, 530.77, 529.21, 524.04, 518.91, 513.9, 509.04, 504.36, - 499.84, 495.48, 491.49, 487.69, 484.03, 480.51, 477.12, 474.19 }); - PTravelTimeTable.add(new double[] { 543.56, 541.18, 538.32, 536.76, 531.56, 526.41, 521.38, 516.5, 511.79, - 507.24, 502.86, 498.84, 495.01, 491.31, 487.76, 484.33, 481.36 }); - PTravelTimeTable.add(new double[] { 551.05, 548.67, 545.8, 544.23, 539.01, 533.83, 528.78, 523.88, 519.15, - 514.58, 510.17, 506.12, 502.25, 498.53, 494.93, 491.47, 488.46 }); - PTravelTimeTable.add(new double[] { 558.47, 556.08, 553.2, 551.63, 546.39, 541.19, 536.12, 531.19, 526.44, - 521.84, 517.41, 513.32, 509.43, 505.67, 502.05, 498.55, 495.5 }); - PTravelTimeTable.add(new double[] { 565.81, 563.42, 560.54, 558.96, 553.7, 548.48, 543.38, 538.43, 533.65, - 529.03, 524.57, 520.46, 516.54, 512.75, 509.09, 505.56, 502.47 }); - PTravelTimeTable.add(new double[] { 573.08, 570.69, 567.8, 566.21, 560.93, 555.69, 550.58, 545.6, 540.8, 536.15, - 531.66, 527.53, 523.57, 519.75, 516.06, 512.5, 509.37 }); - PTravelTimeTable.add(new double[] { 580.28, 577.88, 574.99, 573.39, 568.09, 562.83, 557.69, 552.7, 547.87, - 543.2, 538.69, 534.52, 530.54, 526.69, 522.97, 519.37, 516.21 }); - PTravelTimeTable.add(new double[] { 587.4, 585.0, 582.1, 580.5, 575.18, 569.9, 564.74, 559.72, 554.87, 550.18, - 545.64, 541.45, 537.44, 533.56, 529.81, 526.18, 522.98 }); - PTravelTimeTable.add(new double[] { 594.46, 592.05, 589.14, 587.54, 582.2, 576.9, 571.72, 566.68, 561.8, 557.09, - 552.53, 548.31, 544.27, 540.36, 536.57, 532.92, 529.68 }); - PTravelTimeTable.add(new double[] { 601.43, 599.02, 596.11, 594.5, 589.14, 583.82, 578.62, 573.56, 568.66, - 563.92, 559.34, 555.09, 551.02, 547.09, 543.27, 539.59, 536.31 }); - PTravelTimeTable.add(new double[] { 608.34, 605.93, 603.01, 601.39, 596.01, 590.67, 585.45, 580.37, 575.45, - 570.69, 566.08, 561.81, 557.71, 553.75, 549.91, 546.19, 542.88 }); - PTravelTimeTable.add(new double[] { 615.17, 612.75, 609.83, 608.21, 602.81, 597.45, 592.21, 587.11, 582.17, - 577.38, 572.75, 568.45, 564.33, 560.34, 556.47, 552.72, 549.38 }); - PTravelTimeTable.add(new double[] { 621.93, 619.51, 616.58, 614.95, 609.54, 604.16, 598.9, 593.77, 588.81, - 584.01, 579.35, 575.03, 570.88, 566.86, 562.97, 559.19, 555.82 }); - PTravelTimeTable.add(new double[] { 628.62, 626.19, 623.26, 621.63, 616.19, 610.79, 605.51, 600.37, 595.39, - 590.56, 585.88, 581.54, 577.37, 573.32, 569.4, 565.59, 562.18 }); - PTravelTimeTable.add(new double[] { 635.23, 632.8, 629.86, 628.23, 622.77, 617.36, 612.06, 606.9, 601.89, - 597.05, 592.35, 587.98, 583.78, 579.71, 575.76, 571.92, 568.48 }); - PTravelTimeTable.add(new double[] { 641.78, 639.34, 636.4, 634.76, 629.29, 623.85, 618.53, 613.35, 608.33, - 603.46, 598.74, 594.35, 590.12, 586.03, 582.05, 578.19, 574.72 }); - PTravelTimeTable.add(new double[] { 648.25, 645.81, 642.86, 641.21, 635.72, 630.27, 624.94, 619.74, 614.69, - 609.8, 605.06, 600.64, 596.4, 592.27, 588.27, 584.38, 580.88 }); - PTravelTimeTable.add(new double[] { 654.65, 652.21, 649.25, 647.6, 642.09, 636.62, 631.27, 626.05, 620.99, - 616.08, 611.31, 606.87, 602.6, 598.45, 594.42, 590.51, 586.98 }); - PTravelTimeTable.add(new double[] { 660.97, 658.53, 655.57, 653.91, 648.39, 642.9, 637.53, 632.29, 627.21, - 622.28, 617.49, 613.03, 608.74, 604.56, 600.51, 596.57, 593.01 }); - PTravelTimeTable.add(new double[] { 667.23, 664.78, 661.82, 660.15, 654.61, 649.11, 643.72, 638.46, 633.36, - 628.41, 623.6, 619.12, 614.8, 610.61, 606.52, 602.56, 598.97 }); - PTravelTimeTable.add(new double[] { 673.41, 670.96, 667.99, 666.32, 660.76, 655.24, 649.83, 644.56, 639.44, - 634.47, 629.65, 625.14, 620.8, 616.58, 612.47, 608.48, 604.86 }); - PTravelTimeTable.add(new double[] { 679.51, 677.06, 674.09, 672.41, 666.84, 661.3, 655.88, 650.59, 645.45, - 640.46, 635.61, 631.09, 626.72, 622.48, 618.35, 614.33, 610.68 }); - PTravelTimeTable.add(new double[] { 685.55, 683.09, 680.12, 678.44, 672.85, 667.29, 661.85, 656.54, 651.39, - 646.38, 641.51, 636.96, 632.58, 628.31, 624.15, 620.11, 616.43 }); - PTravelTimeTable.add(new double[] { 691.51, 689.05, 686.07, 684.39, 678.78, 673.21, 667.75, 662.43, 657.25, - 652.22, 647.34, 642.77, 638.36, 634.07, 629.89, 625.82, 622.12 }); - PTravelTimeTable.add(new double[] { 697.4, 694.94, 691.95, 690.26, 684.64, 679.05, 673.58, 668.24, 663.04, - 658.0, 653.09, 648.5, 644.07, 639.75, 635.55, 631.46, 627.73 }); - PTravelTimeTable.add(new double[] { 703.22, 700.75, 697.76, 696.06, 690.43, 684.82, 679.33, 673.97, 668.76, - 663.7, 658.77, 654.16, 649.71, 645.37, 641.15, 637.03, 633.28 }); - PTravelTimeTable.add(new double[] { 708.96, 706.49, 703.49, 701.79, 696.14, 690.52, 685.01, 679.64, 674.41, - 669.33, 664.38, 659.75, 655.28, 650.92, 646.67, 642.54, 638.76 }); - PTravelTimeTable.add(new double[] { 714.62, 712.15, 709.15, 707.45, 701.78, 696.14, 690.62, 685.23, 679.98, - 674.88, 669.92, 665.27, 660.78, 656.4, 652.13, 647.97, 644.17 }); - PTravelTimeTable.add(new double[] { 720.22, 717.74, 714.74, 713.03, 707.35, 701.7, 696.16, 690.75, 685.49, - 680.37, 675.39, 670.72, 666.21, 661.81, 657.52, 653.33, 649.5 }); - PTravelTimeTable.add(new double[] { 725.74, 723.26, 720.25, 718.54, 712.84, 707.18, 701.62, 696.2, 690.92, - 685.79, 680.79, 676.1, 671.57, 667.14, 662.83, 658.62, 654.77 }); - PTravelTimeTable.add(new double[] { 731.19, 728.71, 725.69, 723.98, 718.26, 712.58, 707.02, 701.57, 696.28, - 691.13, 686.11, 681.4, 676.85, 672.4, 668.07, 663.84, 659.96 }); - PTravelTimeTable.add(new double[] { 736.56, 734.07, 731.05, 729.34, 723.61, 717.91, 712.33, 706.87, 701.56, - 696.39, 691.36, 686.63, 682.06, 677.59, 673.24, 668.98, 665.08 }); - PTravelTimeTable.add(new double[] { 741.85, 739.37, 736.34, 734.62, 728.88, 723.17, 717.57, 712.1, 706.77, - 701.58, 696.53, 691.78, 687.19, 682.71, 678.33, 674.05, 670.12 }); - PTravelTimeTable.add(new double[] { 747.07, 744.58, 741.56, 739.83, 734.07, 728.35, 722.73, 717.25, 711.9, - 706.7, 701.63, 696.86, 692.25, 687.74, 683.34, 679.05, 675.1 }); - PTravelTimeTable.add(new double[] { 752.22, 749.72, 746.69, 744.96, 739.19, 733.45, 727.82, 722.32, 716.96, - 711.74, 706.65, 701.86, 697.23, 692.71, 688.29, 683.97, 680.0 }); - PTravelTimeTable.add(new double[] { 757.28, 754.78, 751.75, 750.01, 744.23, 738.47, 732.83, 727.31, 721.93, - 716.7, 711.6, 706.79, 702.14, 697.6, 693.16, 688.82, 684.81 }); - PTravelTimeTable.add(new double[] { 762.26, 759.77, 756.72, 754.98, 749.19, 743.42, 737.76, 732.23, 726.84, - 721.59, 716.47, 711.64, 706.97, 702.39, 697.92, 693.56, 689.53 }); - PTravelTimeTable.add(new double[] { 767.18, 764.68, 761.63, 759.89, 754.08, 748.29, 742.62, 737.06, 731.65, - 726.37, 721.23, 716.39, 711.69, 707.11, 702.63, 698.25, 694.22 }); - PTravelTimeTable.add(new double[] { 771.99, 769.49, 766.43, 764.68, 758.85, 753.05, 747.36, 741.79, 736.37, - 731.09, 725.93, 721.08, 716.38, 711.79, 707.3, 702.92, 698.88 }); - PTravelTimeTable.add(new double[] { 776.71, 774.21, 771.15, 769.4, 763.56, 757.76, 752.06, 746.48, 741.05, - 735.76, 730.61, 725.75, 721.04, 716.44, 711.95, 707.56, 703.51 }); - PTravelTimeTable.add(new double[] { 781.4, 778.89, 775.83, 774.08, 768.24, 762.43, 756.72, 751.15, 745.71, - 740.41, 735.25, 730.39, 725.68, 721.08, 716.58, 712.19, 708.13 }); - PTravelTimeTable.add(new double[] { 786.05, 783.55, 780.49, 778.73, 772.89, 767.07, 761.37, 755.78, 750.35, - 745.05, 739.88, 735.01, 730.3, 725.69, 721.19, 716.8, 712.74 }); - PTravelTimeTable.add(new double[] { 790.69, 788.18, 785.12, 783.37, 777.52, 771.7, 765.99, 760.4, 754.96, - 749.66, 744.49, 739.62, 734.9, 730.3, 725.79, 721.39, 717.33 }); - PTravelTimeTable.add(new double[] { 795.31, 792.8, 789.74, 787.98, 782.13, 776.31, 770.6, 765.01, 759.57, - 754.26, 749.09, 744.22, 739.49, 734.88, 730.37, 725.96, 721.89 }); - PTravelTimeTable.add(new double[] { 799.91, 797.4, 794.34, 792.58, 786.73, 780.91, 775.19, 769.6, 764.15, - 758.84, 753.67, 748.79, 744.06, 739.44, 734.93, 730.51, 726.44 }); - PTravelTimeTable.add(new double[] { 804.5, 801.99, 798.93, 797.17, 791.31, 785.48, 779.76, 774.17, 768.72, - 763.4, 758.22, 753.34, 748.6, 743.98, 739.46, 735.04, 730.95 }); - PTravelTimeTable.add(new double[] { 809.06, 806.55, 803.49, 801.73, 795.87, 790.04, 784.31, 778.71, 773.26, - 767.94, 762.75, 757.86, 753.12, 748.49, 743.96, 739.53, 735.44 }); - PTravelTimeTable.add(new double[] { 813.6, 811.09, 808.02, 806.26, 800.4, 794.56, 788.83, 783.23, 777.77, - 772.44, 767.25, 762.35, 757.61, 752.97, 748.43, 744.0, 739.9 }); - PTravelTimeTable.add(new double[] { 818.11, 815.6, 812.53, 810.77, 804.9, 799.06, 793.33, 787.72, 782.25, - 776.92, 771.72, 766.82, 762.07, 757.42, 752.88, 748.44, 744.34 }); - PTravelTimeTable.add(new double[] { 822.59, 820.08, 817.01, 815.25, 809.37, 803.53, 797.79, 792.17, 786.7, - 781.37, 776.17, 771.26, 766.51, 761.87, 757.33, 752.89, 748.79 }); - PTravelTimeTable.add(new double[] { 827.04, 824.53, 821.46, 819.7, 813.82, 807.97, 802.23, 796.62, 791.15, - 785.81, 780.61, 775.71, 770.96, 766.31, 761.77, 757.33, 753.23 }); - PTravelTimeTable.add(new double[] { 831.49, 828.97, 825.91, 824.14, 818.26, 812.42, 806.68, 801.07, 795.59, - 790.26, 785.06, 780.15, 775.4, 770.76, 766.22, 761.78, 757.68 }); - PTravelTimeTable.add(new double[] { 835.93, 833.42, 830.35, 828.59, 822.71, 816.86, 811.13, 805.51, 800.04, - 794.71, 789.51, 784.6, 779.85, 775.2, 770.66, 766.23, 762.13 }); - PTravelTimeTable.add(new double[] { 840.38, 837.86, 834.8, 833.03, 827.16, 821.31, 815.57, 809.96, 804.48, - 799.15, 793.95, 789.05, 784.29, 779.65, 775.11, 770.67, 766.57 }); - PTravelTimeTable.add(new double[] { 844.83, 842.31, 839.24, 837.48, 831.6, 825.76, 820.02, 814.4, 808.93, 803.6, - 798.4, 793.49, 788.74, 784.09, 779.55, 775.12, 771.02 }); - PTravelTimeTable.add(new double[] { 849.27, 846.76, 843.69, 841.92, 836.05, 830.2, 824.46, 818.85, 813.38, - 808.04, 802.84, 797.94, 793.18, 788.54, 784.0, 779.56, 775.46 }); - PTravelTimeTable.add(new double[] { 853.72, 851.2, 848.14, 846.37, 840.49, 834.65, 828.91, 823.29, 817.82, - 812.49, 807.29, 802.38, 797.63, 792.99, 788.45, 784.01, 779.91 }); - PTravelTimeTable.add(new double[] { 858.16, 855.65, 852.58, 850.82, 844.94, 839.09, 833.35, 827.74, 822.27, - 816.93, 811.73, 806.83, 802.08, 797.43, 792.89, 788.45, 784.35 }); - PTravelTimeTable.add(new double[] { 862.61, 860.09, 857.03, 855.26, 849.38, 843.54, 837.8, 832.18, 826.71, - 821.38, 816.18, 811.27, 806.52, 801.88, 797.34, 792.9, 788.8 }); - PTravelTimeTable.add(new double[] { 867.05, 864.54, 861.47, 859.71, 853.83, 847.98, 842.24, 836.63, 831.16, - 825.83, 820.63, 815.72, 810.97, 806.32, 801.78, 797.35, 793.25 }); - PTravelTimeTable.add(new double[] { 871.5, 868.98, 865.92, 864.15, 858.28, 852.43, 846.69, 841.08, 835.6, - 830.27, 825.07, 820.17, 815.41, 810.77, 806.23, 801.79, 797.69 }); - PTravelTimeTable.add(new double[] { 875.95, 873.43, 870.36, 868.6, 862.72, 856.87, 851.14, 845.52, 840.05, - 834.72, 829.52, 824.61, 819.86, 815.21, 810.67, 806.24, 802.14 }); - PTravelTimeTable.add(new double[] { 880.39, 877.88, 874.81, 873.04, 867.17, 861.32, 855.58, 849.97, 844.5, - 839.16, 833.96, 829.06, 824.3, 819.66, 815.12, 810.68, 806.58 }); - PTravelTimeTable.add(new double[] { 884.84, 882.32, 879.25, 877.49, 871.61, 865.77, 860.03, 854.41, 848.94, - 843.61, 838.41, 833.5, 828.75, 824.11, 819.57, 815.13, 811.03 }); - PTravelTimeTable.add(new double[] { 889.28, 886.77, 883.7, 881.94, 876.06, 870.21, 864.47, 858.86, 853.39, - 848.05, 842.85, 837.95, 833.2, 828.55, 824.01, 819.57, 815.47 }); - PTravelTimeTable.add(new double[] { 893.73, 891.21, 888.15, 886.38, 880.5, 874.66, 868.92, 863.3, 857.83, 852.5, - 847.3, 842.39, 837.64, 833.0, 828.46, 824.02, 819.92 }); - PTravelTimeTable.add(new double[] { 898.17, 895.66, 892.59, 890.83, 884.95, 879.1, 873.36, 867.75, 862.28, - 856.94, 851.75, 846.84, 842.09, 837.44, 832.9, 828.47, 824.36 }); - PTravelTimeTable.add(new double[] { 902.62, 900.1, 897.04, 895.27, 889.4, 883.55, 877.81, 872.2, 866.72, 861.39, - 856.19, 851.29, 846.53, 841.89, 837.35, 832.91, 828.81 }); - PTravelTimeTable.add(new double[] { 907.06, 904.55, 901.48, 899.72, 893.84, 887.99, 882.26, 876.64, 871.17, - 865.84, 860.64, 855.73, 850.98, 846.33, 841.79, 837.36, 833.26 }); - PTravelTimeTable.add(new double[] { 911.51, 908.99, 905.93, 904.16, 898.29, 892.44, 886.7, 881.09, 875.62, - 870.28, 865.08, 860.18, 855.42, 850.78, 846.24, 841.8, 837.7 }); - PTravelTimeTable.add(new double[] { 915.96, 913.44, 910.37, 908.61, 902.73, 896.89, 891.15, 885.53, 880.06, - 874.73, 869.53, 864.62, 859.87, 855.22, 850.68, 846.25, 842.15 }); - PTravelTimeTable.add(new double[] { 920.4, 917.89, 914.82, 913.05, 907.18, 901.33, 895.59, 889.98, 884.51, - 879.17, 873.97, 869.07, 864.32, 859.67, 855.13, 850.69, 846.59 }); - PTravelTimeTable.add(new double[] { 924.85, 922.33, 919.27, 917.5, 911.62, 905.78, 900.04, 894.42, 888.95, - 883.62, 878.42, 873.51, 868.76, 864.12, 859.58, 855.14, 851.04 }); - PTravelTimeTable.add(new double[] { 929.29, 926.78, 923.71, 921.95, 916.07, 910.22, 904.48, 898.87, 893.4, - 888.06, 882.86, 877.96, 873.21, 868.56, 864.02, 859.59, 855.48 }); - PTravelTimeTable.add(new double[] { 933.74, 931.22, 928.16, 926.39, 920.52, 914.67, 908.93, 903.32, 897.84, - 892.51, 887.31, 882.41, 877.65, 873.01, 868.47, 864.03, 859.93 }); - PTravelTimeTable.add(new double[] { 938.18, 935.67, 932.6, 930.84, 924.96, 919.11, 913.38, 907.76, 902.29, - 896.96, 891.76, 886.85, 882.1, 877.45, 872.91, 868.48, 864.38 }); - - STravelTimeTable.add(new double[] { 0.0, 4.34, 9.68, 13.02, 24.16, 35.27, 46.35, 57.34, 68.13, 78.72, 89.12, - 98.99000000000001, 108.57, 117.96000000000001, 127.17, 136.2, 144.64 }); - STravelTimeTable.add(new double[] { 32.14, 31.98, 30.38, 30.74, 35.74, 43.61, 52.78, 62.52, 72.42, 82.37, - 92.27000000000001, 101.74000000000001, 111.0, 120.13, 129.12, 137.97, 146.25 }); - STravelTimeTable.add(new double[] { 60.75, 57.98, 55.06, 55.14, 57.38, 62.05, 68.43, 75.89, 83.96000000000001, - 92.41, 101.11, 109.53999999999999, 117.94, 126.35, 134.74, 143.07, 150.88 }); - STravelTimeTable.add(new double[] { 85.43, 82.66, 79.73, 79.72, 80.94, 83.92, 88.39, 93.95, 100.21000000000001, - 107.03, 114.28999999999999, 121.4, 128.65, 136.07999999999998, 143.6, 151.17000000000002, 158.28 }); - STravelTimeTable.add(new double[] { 110.1, 107.33, 104.4, 104.33, 104.99000000000001, 107.0, 110.24000000000001, - 114.4, 119.19, 124.57, 130.46, 136.21, 142.24, 148.56, 155.1, 161.8, 168.05 }); - STravelTimeTable.add(new double[] { 134.76, 131.99, 129.06, 128.93, 129.22, 130.59, 132.98, 136.12, 139.74, - 143.91, 148.59, 153.06, 157.89, 163.12, 168.65, 174.42000000000002, 179.76 }); - STravelTimeTable.add(new double[] { 159.41, 156.63, 153.7, 153.52, 153.53, 154.43, 156.2, 158.54, 161.21, - 164.36, 168.01, 171.27, 174.99, 179.18, 183.74, 188.6, 192.98 }); - STravelTimeTable.add(new double[] { 184.04, 181.26, 178.32, 178.1, 177.87, 178.4, 179.69, 181.38, 183.24, - 185.52, 188.26, 190.37, 193.06, 196.3, 199.96, 203.96, 207.36 }); - STravelTimeTable.add(new double[] { 208.65, 205.87, 202.92000000000002, 202.66, 202.21, 202.44, 203.34, 204.45, - 205.6, 207.12, 209.06, 210.0, 211.78, 214.16, 216.98, 220.17000000000002, 222.57999999999998 }); - STravelTimeTable.add(new double[] { 233.24, 230.45, 227.5, 227.19, 226.56, 226.52, 227.07999999999998, - 227.67000000000002, 228.15, 228.97, 230.2, 229.89, 230.9, 232.5, 234.56, 237.01, 238.37 }); - STravelTimeTable.add(new double[] { 257.8, 255.01, 252.05, 251.7, 250.88, 250.61, 250.89, 250.93, 250.79, - 250.97, 250.84, 249.89, 250.23, 251.14, 252.52, 254.28, 254.5 }); - STravelTimeTable.add(new double[] { 282.33, 279.53, 276.56, 276.17, 275.19, 274.71, 274.72, 274.15999999999997, - 273.43, 273.02, 271.23, 269.88, 269.65, 269.96, 270.71, 271.52, 270.78 }); - STravelTimeTable.add(new double[] { 306.83, 304.02, 301.04, 300.61, 299.47, 298.79, 298.57, 297.3, 295.99, - 295.05, 291.53, 289.82, 289.09000000000003, 288.84000000000003, 289.03, 288.19, 287.11 }); - STravelTimeTable.add(new double[] { 331.29, 328.47, 325.48, 325.01, 323.72, 322.86, 322.36, 320.27, 318.45, - 315.58, 311.72, 309.67, 308.47, 307.73, 307.39, 304.79, 303.4 }); - STravelTimeTable.add(new double[] { 355.7, 352.89, 349.88, 349.37, 347.93, 346.9, 345.65999999999997, 343.04, - 340.3, 335.79, 331.77, 329.38, 327.76, 326.56, 325.01, 321.32, 319.64 }); - STravelTimeTable.add(new double[] { 380.08, 377.25, 374.24, 373.69, 372.11, 370.91, 368.66, 365.58, 360.52, - 355.87, 351.65999999999997, 348.94, 346.90999999999997, 345.29, 341.55, 337.75, 335.81 }); - STravelTimeTable.add(new double[] { 404.40999999999997, 401.57, 398.55, 397.96, 396.25, 394.82, 391.36, 385.83, - 380.59, 375.77, 371.36, 368.31, 365.91, 362.32, 357.99, 354.06, 351.89 }); - STravelTimeTable.add(new double[] { 428.69, 425.85, 422.81, 422.18, 420.34, 417.65999999999997, 411.68, 405.87, - 400.48, 395.47, 390.84, 387.48, 383.6, 378.75, 374.3, 370.26, 367.81 }); - STravelTimeTable.add(new double[] { 452.92, 450.07, 447.02, 446.36, 444.01, 437.81, 431.68, 425.73, 420.15, - 414.95, 410.09000000000003, 405.33, 400.0, 395.05, 390.5, 386.32, 383.62 }); - STravelTimeTable.add(new double[] { 477.1, 474.24, 471.17, 470.47, 464.07, 457.75, 451.47, 445.35, 439.59, - 434.18, 427.64, 421.7, 416.28, 411.24, 406.56, 402.18, 399.4 }); - STravelTimeTable.add(new double[] { 499.77, 496.38, 492.44, 490.47, 483.94, 477.46, 471.02, 464.72, 458.06, - 450.85, 443.96, 437.94, 432.43, 427.26, 422.4, 417.98, 415.15 }); - STravelTimeTable.add(new double[] { 519.66, 516.24, 512.27, 510.25, 503.57, 496.92, 489.91, 481.99, 474.39, - 467.11, 460.15, 454.05, 448.39, 443.08, 438.19, 433.74, 430.88 }); - STravelTimeTable.add(new double[] { 539.3, 535.85, 531.83, 529.77, 522.56, 514.36, 506.22, 498.25, 490.59, - 483.24, 476.18, 469.93, 464.2, 458.87, 453.95, 449.48, 446.58 }); - STravelTimeTable.add(new double[] { 557.88, 554.15, 549.7, 547.19, 538.86, 530.6, 522.41, 514.37, 506.62, - 499.15, 492.0, 485.73, 479.97, 474.62, 469.69, 465.19, 462.24 }); - STravelTimeTable.add(new double[] { 574.14, 570.4, 565.93, 563.4, 555.02, 546.7, 538.41, 530.26, 522.44, 514.95, - 507.78, 501.49, 495.72, 490.35, 485.4, 480.88, 477.87 }); - STravelTimeTable.add(new double[] { 590.26, 586.5, 582.01, 579.46, 570.97, 562.56, 554.22, 546.06, 538.22, - 530.71, 523.54, 517.23, 511.44, 506.05, 501.08, 496.52, 493.44 }); - STravelTimeTable.add(new double[] { 606.14, 602.37, 597.85, 595.29, 586.78, 578.35, 570.0, 561.82, 553.97, - 546.46, 539.27, 532.94, 527.13, 521.72, 516.71, 512.11, 508.96 }); - STravelTimeTable.add(new double[] { 621.93, 618.16, 613.64, 611.07, 602.55, 594.11, 585.75, 577.56, 569.7, - 562.17, 554.97, 548.62, 542.79, 537.35, 532.29, 527.64, 524.41 }); - STravelTimeTable.add(new double[] { 637.69, 633.92, 629.4, 626.82, 618.29, 609.84, 601.47, 593.27, 585.4, - 577.85, 570.63, 564.26, 558.4, 552.91, 547.81, 543.11, 539.79 }); - STravelTimeTable.add(new double[] { 653.43, 649.65, 645.13, 642.55, 634.01, 625.55, 617.17, 608.95, 601.06, - 593.5, 586.25, 579.85, 573.95, 568.42, 563.27, 558.5, 555.1 }); - STravelTimeTable.add(new double[] { 669.14, 665.36, 660.83, 658.25, 649.7, 641.22, 632.82, 624.59, 616.68, - 609.09, 601.81, 595.37, 589.43, 583.85, 578.65, 573.82, 570.33 }); - STravelTimeTable.add(new double[] { 684.81, 681.03, 676.5, 673.91, 665.34, 656.85, 648.43, 640.18, 632.24, - 624.61, 617.3, 610.83, 604.84, 599.21, 593.95, 589.07, 585.49 }); - STravelTimeTable.add(new double[] { 700.45, 696.66, 692.12, 689.53, 680.94, 672.42, 663.98, 655.7, 647.73, - 640.07, 632.72, 626.21, 620.17, 614.5, 609.18, 604.24, 600.58 }); - STravelTimeTable.add(new double[] { 716.02, 712.23, 707.69, 705.09, 696.47, 687.93, 679.46, 671.14, 663.14, - 655.45, 648.07, 641.51, 635.43, 629.7, 624.33, 619.33, 615.58 }); - STravelTimeTable.add(new double[] { 731.53, 727.73, 723.18, 720.58, 711.93, 703.36, 694.86, 686.52, 678.48, - 670.76, 663.34, 656.73, 650.6, 644.83, 639.4, 634.33, 630.5 }); - STravelTimeTable.add(new double[] { 746.97, 743.16, 738.6, 735.99, 727.32, 718.72, 710.18, 701.81, 693.74, - 685.98, 678.52, 671.88, 665.7, 659.87, 654.38, 649.25, 645.33 }); - STravelTimeTable.add(new double[] { 762.32, 758.51, 753.95, 751.32, 742.62, 733.99, 725.43, 717.02, 708.92, - 701.12, 693.63, 686.93, 680.7, 674.82, 669.28, 664.08, 660.08 }); - STravelTimeTable.add(new double[] { 777.6, 773.79, 769.21, 766.58, 757.85, 749.19, 740.59, 732.15, 724.01, - 716.18, 708.64, 701.9, 695.62, 689.68, 684.09, 678.83, 674.74 }); - STravelTimeTable.add(new double[] { 792.8, 788.98, 784.39, 781.75, 772.99, 764.3, 755.67, 747.19, 739.02, - 731.14, 723.57, 716.78, 710.45, 704.46, 698.8, 693.48, 689.31 }); - STravelTimeTable.add(new double[] { 807.91, 804.08, 799.48, 796.83, 788.04, 779.32, 770.65, 762.14, 753.93, - 746.02, 738.4, 731.57, 725.19, 719.14, 713.42, 708.04, 703.79 }); - STravelTimeTable.add(new double[] { 822.93, 819.09, 814.49, 811.83, 803.0, 794.24, 785.55, 777.0, 768.75, 760.8, - 753.14, 746.26, 739.83, 733.73, 727.95, 722.51, 718.18 }); - STravelTimeTable.add(new double[] { 837.86, 834.01, 829.4, 826.73, 817.87, 809.08, 800.35, 791.77, 783.48, - 775.49, 767.79, 760.86, 754.38, 748.22, 742.39, 736.88, 732.47 }); - STravelTimeTable.add(new double[] { 852.69, 848.84, 844.21, 841.53, 832.64, 823.82, 815.05, 806.44, 798.11, - 790.08, 782.34, 775.36, 768.83, 762.62, 756.73, 751.15, 746.66 }); - STravelTimeTable.add(new double[] { 867.42, 863.57, 858.93, 856.24, 847.32, 838.46, 829.66, 821.01, 812.65, - 804.57, 796.79, 789.77, 783.18, 776.92, 770.97, 765.33, 760.76 }); - STravelTimeTable.add(new double[] { 882.06, 878.2, 873.56, 870.86, 861.9, 853.0, 844.17, 835.48, 827.08, 818.97, - 811.14, 804.07, 797.43, 791.11, 785.1, 779.41, 774.76 }); - STravelTimeTable.add(new double[] { 896.6, 892.73, 888.08, 885.37, 876.38, 867.45, 858.58, 849.85, 841.41, - 833.26, 825.39, 818.27, 811.58, 805.21, 799.14, 793.38, 788.66 }); - STravelTimeTable.add(new double[] { 911.04, 907.16, 902.5, 899.78, 890.75, 881.79, 872.88, 864.12, 855.64, - 847.45, 839.54, 832.37, 825.63, 819.2, 813.08, 807.26, 802.46 }); - STravelTimeTable.add(new double[] { 925.37, 921.49, 916.81, 914.08, 905.02, 896.02, 887.08, 878.28, 869.77, - 861.53, 853.58, 846.37, 839.58, 833.09, 826.91, 821.03, 816.16 }); - STravelTimeTable.add(new double[] { 939.6, 935.71, 931.02, 928.28, 919.19, 910.15, 901.18, 892.34, 883.79, - 875.51, 867.52, 860.26, 853.42, 846.88, 840.64, 834.7, 829.76 }); - STravelTimeTable.add(new double[] { 953.72, 949.82, 945.13, 942.38, 933.25, 924.18, 915.17, 906.29, 897.7, - 889.39, 881.35, 874.04, 867.15, 860.56, 854.27, 848.27, 843.27 }); - STravelTimeTable.add(new double[] { 967.73, 963.83, 959.12, 956.36, 947.2, 938.09, 929.05, 920.14, 911.51, - 903.15, 895.07, 887.72, 880.78, 874.14, 867.8, 861.75, 856.67 }); - STravelTimeTable.add(new double[] { 981.64, 977.73, 973.01, 970.24, 961.04, 951.9, 942.82, 933.87, 925.2, - 916.81, 908.69, 901.3, 894.31, 887.62, 881.23, 875.12, 869.98 }); - STravelTimeTable.add(new double[] { 995.43, 991.52, 986.79, 984.01, 974.77, 965.6, 956.48, 947.5, 938.8, 930.37, - 922.21, 914.77, 907.74, 901.0, 894.55, 888.39, 883.18 }); - STravelTimeTable.add(new double[] { 1009.12, 1005.19, 1000.45, 997.66, 988.4, 979.19, 970.04, 961.03, 952.29, - 943.82, 935.63, 928.14, 921.06, 914.28, 907.77, 901.56, 896.28 }); - STravelTimeTable.add(new double[] { 1022.7, 1018.77, 1014.02, 1011.22, 1001.92, 992.68, 983.5, 974.45, 965.68, - 957.17, 948.93, 941.41, 934.28, 927.44, 920.89, 914.62, 909.27 }); - STravelTimeTable.add(new double[] { 1036.17, 1032.23, 1027.47, 1024.67, 1015.34, 1006.07, 996.85, 987.77, - 978.96, 970.41, 962.13, 954.56, 947.39, 940.5, 933.9, 927.57, 922.17 }); - STravelTimeTable.add(new double[] { 1049.54, 1045.59, 1040.82, 1038.0, 1028.65, 1019.34, 1010.09, 1000.97, - 992.12, 983.54, 975.23, 967.61, 960.39, 953.46, 946.8, 940.42, 934.96 }); - STravelTimeTable.add(new double[] { 1062.79, 1058.84, 1054.06, 1051.23, 1041.84, 1032.5, 1023.22, 1014.07, - 1005.18, 996.56, 988.21, 980.55, 973.29, 966.31, 959.6, 953.17, 947.64 }); - STravelTimeTable.add(new double[] { 1075.94, 1071.98, 1067.19, 1064.35, 1054.93, 1045.56, 1036.24, 1027.05, - 1018.13, 1009.48, 1001.08, 993.39, 986.08, 979.05, 972.3, 965.81, 960.22 }); - STravelTimeTable.add(new double[] { 1088.97, 1085.0, 1080.2, 1077.35, 1067.9, 1058.5, 1049.15, 1039.93, 1030.97, - 1022.28, 1013.85, 1006.11, 998.76, 991.68, 984.88, 978.35, 972.69 }); - STravelTimeTable.add(new double[] { 1101.89, 1097.91, 1093.11, 1090.25, 1080.76, 1071.33, 1061.95, 1052.69, - 1043.71, 1034.98, 1026.51, 1018.73, 1011.33, 1004.21, 997.36, 990.77, 985.06 }); - STravelTimeTable.add(new double[] { 1114.7, 1110.72, 1105.9, 1103.03, 1093.52, 1084.05, 1074.64, 1065.35, - 1056.33, 1047.57, 1039.06, 1031.24, 1023.8, 1016.63, 1009.73, 1003.09, 997.33 }); - STravelTimeTable.add(new double[] { 1127.39, 1123.41, 1118.58, 1115.71, 1106.16, 1096.66, 1087.21, 1077.89, - 1068.84, 1060.04, 1051.5, 1043.63, 1036.15, 1028.94, 1021.99, 1015.31, 1009.48 }); - STravelTimeTable.add(new double[] { 1139.98, 1135.99, 1131.15, 1128.26, 1118.68, 1109.16, 1099.68, 1090.33, - 1081.24, 1072.4, 1063.82, 1055.92, 1048.39, 1041.14, 1034.15, 1027.41, 1021.53 }); - STravelTimeTable.add(new double[] { 1152.45, 1148.45, 1143.6, 1140.71, 1131.1, 1121.54, 1112.03, 1102.65, - 1093.52, 1084.66, 1076.04, 1068.1, 1060.53, 1053.23, 1046.19, 1039.41, 1033.48 }); - STravelTimeTable.add(new double[] { 1164.8, 1160.8, 1155.94, 1153.04, 1143.4, 1133.81, 1124.27, 1114.86, 1105.7, - 1096.8, 1088.15, 1080.17, 1072.56, 1065.22, 1058.13, 1051.3, 1045.31 }); - STravelTimeTable.add(new double[] { 1177.05, 1173.04, 1168.17, 1165.26, 1155.59, 1145.97, 1136.4, 1126.95, - 1117.77, 1108.83, 1100.14, 1092.12, 1084.47, 1077.09, 1069.96, 1063.09, 1057.04 }); - STravelTimeTable.add(new double[] { 1189.18, 1185.16, 1180.28, 1177.36, 1167.67, 1158.02, 1148.42, 1138.94, - 1129.72, 1120.75, 1112.03, 1103.97, 1096.28, 1088.85, 1081.68, 1074.76, 1068.66 }); - STravelTimeTable.add(new double[] { 1201.19, 1197.17, 1192.29, 1189.36, 1179.63, 1169.95, 1160.32, 1150.81, - 1141.56, 1132.56, 1123.8, 1115.71, 1107.98, 1100.51, 1093.29, 1086.33, 1080.18 }); - STravelTimeTable.add(new double[] { 1213.09, 1209.07, 1204.17, 1201.23, 1191.48, 1181.77, 1172.11, 1162.57, - 1153.29, 1144.25, 1135.46, 1127.33, 1119.56, 1112.05, 1104.79, 1097.78, 1091.58 }); - STravelTimeTable.add(new double[] { 1224.88, 1220.85, 1215.94, 1213.0, 1203.21, 1193.48, 1183.79, 1174.22, - 1164.9, 1155.84, 1147.01, 1138.84, 1131.03, 1123.48, 1116.18, 1109.12, 1102.86 }); - STravelTimeTable.add(new double[] { 1236.55, 1232.51, 1227.6, 1224.65, 1214.83, 1205.07, 1195.35, 1185.75, - 1176.4, 1167.3, 1158.44, 1150.24, 1142.39, 1134.79, 1127.45, 1120.35, 1114.04 }); - STravelTimeTable.add(new double[] { 1248.11, 1244.06, 1239.14, 1236.18, 1226.34, 1216.54, 1206.8, 1197.17, - 1187.79, 1178.65, 1169.76, 1161.52, 1153.63, 1145.99, 1138.61, 1131.46, 1125.11 }); - STravelTimeTable.add(new double[] { 1259.55, 1255.49, 1250.57, 1247.59, 1237.73, 1227.9, 1218.12, 1208.46, - 1199.05, 1189.89, 1180.96, 1172.68, 1164.76, 1157.08, 1149.65, 1142.46, 1136.06 }); - STravelTimeTable.add(new double[] { 1270.87, 1266.81, 1261.87, 1258.89, 1248.99, 1239.14, 1229.33, 1219.64, - 1210.2, 1201.01, 1192.05, 1183.73, 1175.77, 1168.06, 1160.59, 1153.35, 1146.9 }); - STravelTimeTable.add(new double[] { 1282.07, 1278.0, 1273.05, 1270.07, 1260.14, 1250.26, 1240.42, 1230.71, - 1221.24, 1212.01, 1203.02, 1194.67, 1186.67, 1178.92, 1171.4, 1164.13, 1157.63 }); - STravelTimeTable.add(new double[] { 1293.15, 1289.08, 1284.12, 1281.12, 1271.17, 1261.27, 1251.4, 1241.66, - 1232.16, 1222.9, 1213.87, 1205.49, 1197.45, 1189.66, 1182.11, 1174.79, 1168.25 }); - STravelTimeTable.add(new double[] { 1304.11, 1300.03, 1295.07, 1292.07, 1282.09, 1272.15, 1262.26, 1252.49, - 1242.96, 1233.67, 1224.61, 1216.19, 1208.11, 1200.29, 1192.7, 1185.34, 1178.75 }); - STravelTimeTable.add(new double[] { 1314.95, 1310.87, 1305.9, 1302.89, 1292.88, 1282.92, 1273.0, 1263.2, - 1253.64, 1244.32, 1235.23, 1226.78, 1218.67, 1210.8, 1203.17, 1195.78, 1189.14 }); - STravelTimeTable.add(new double[] { 1325.68, 1321.59, 1316.61, 1313.59, 1303.55, 1293.57, 1283.62, 1273.79, - 1264.2, 1254.85, 1245.74, 1237.25, 1229.1, 1221.2, 1213.53, 1206.09, 1199.41 }); - STravelTimeTable.add(new double[] { 1336.28, 1332.19, 1327.2, 1324.17, 1314.11, 1304.1, 1294.12, 1284.27, - 1274.65, 1265.27, 1256.12, 1247.6, 1239.42, 1231.48, 1223.77, 1216.29, 1209.56 }); - STravelTimeTable.add(new double[] { 1346.77, 1342.67, 1337.67, 1334.63, 1324.55, 1314.51, 1304.51, 1294.62, - 1284.98, 1275.57, 1266.39, 1257.83, 1249.61, 1241.63, 1233.88, 1226.37, 1219.59 }); - STravelTimeTable.add(new double[] { 1357.13, 1353.02, 1348.02, 1344.97, 1334.86, 1324.79, 1314.76, 1304.85, - 1295.18, 1285.74, 1276.52, 1267.93, 1259.68, 1251.67, 1243.88, 1236.32, 1229.5 }); - STravelTimeTable.add(new double[] { 1367.36, 1363.25, 1358.23, 1355.19, 1345.05, 1334.95, 1324.9, 1314.96, - 1305.25, 1295.78, 1286.54, 1277.92, 1269.63, 1261.58, 1253.76, 1246.16, 1239.3 }); - STravelTimeTable.add(new double[] { 1377.47, 1373.35, 1368.33, 1365.27, 1355.11, 1344.99, 1334.91, 1324.94, - 1315.21, 1305.71, 1296.44, 1287.78, 1279.46, 1271.37, 1263.52, 1255.88, 1248.97 }); - STravelTimeTable.add(new double[] { 1387.45, 1383.33, 1378.3, 1375.23, 1365.05, 1354.9, 1344.79, 1334.8, - 1325.04, 1315.51, 1306.21, 1297.52, 1289.16, 1281.04, 1273.15, 1265.47, 1258.52 }); - STravelTimeTable.add(new double[] { 1397.31, 1393.18, 1388.14, 1385.07, 1374.86, 1364.69, 1354.55, 1344.53, - 1334.74, 1325.19, 1315.86, 1307.13, 1298.74, 1290.59, 1282.65, 1274.94, 1267.94 }); - STravelTimeTable.add(new double[] { 1407.04, 1402.91, 1397.86, 1394.78, 1384.54, 1374.34, 1364.18, 1354.14, - 1344.32, 1334.74, 1325.37, 1316.62, 1308.19, 1300.0, 1292.03, 1284.28, 1277.24 }); - STravelTimeTable.add(new double[] { 1416.64, 1412.5, 1407.45, 1404.36, 1394.1, 1383.87, 1373.69, 1363.61, - 1353.77, 1344.15, 1334.76, 1325.97, 1317.52, 1309.29, 1301.28, 1293.49, 1286.41 }); - STravelTimeTable.add(new double[] { 1426.11, 1421.97, 1416.9, 1413.81, 1403.52, 1393.27, 1383.05, 1372.95, - 1363.08, 1353.44, 1344.02, 1335.2, 1326.71, 1318.44, 1310.4, 1302.57, 1295.45 }); - STravelTimeTable.add(new double[] { 1435.44, 1431.29, 1426.22, 1423.12, 1412.8, 1402.53, 1392.29, 1382.16, - 1372.26, 1362.59, 1353.14, 1344.29, 1335.77, 1327.47, 1319.39, 1311.53, 1304.36 }); - STravelTimeTable.add(new double[] { 1444.64, 1440.49, 1435.41, 1432.3, 1421.96, 1411.66, 1401.39, 1391.24, - 1381.31, 1371.62, 1362.14, 1353.25, 1344.7, 1336.37, 1328.25, 1320.35, 1313.16 }); - STravelTimeTable.add(new double[] { 1453.71, 1449.55, 1444.46, 1441.34, 1430.98, 1420.65, 1410.36, 1400.18, - 1390.23, 1380.51, 1371.0, 1362.09, 1353.5, 1345.14, 1337.01, 1329.09, 1321.88 }); - STravelTimeTable.add(new double[] { 1462.63, 1458.47, 1453.37, 1450.25, 1439.86, 1429.51, 1419.2, 1409.0, - 1399.02, 1389.28, 1379.75, 1370.83, 1362.23, 1353.86, 1345.71, 1337.78, 1330.56 }); - STravelTimeTable.add(new double[] { 1471.43, 1467.26, 1462.16, 1459.03, 1448.63, 1438.27, 1427.94, 1417.73, - 1407.74, 1397.99, 1388.46, 1379.52, 1370.91, 1362.53, 1354.37, 1346.42, 1339.18 }); - STravelTimeTable.add(new double[] { 1480.16, 1475.98, 1470.88, 1467.75, 1457.34, 1446.97, 1436.63, 1426.41, - 1416.42, 1406.65, 1397.11, 1388.16, 1379.54, 1371.14, 1362.96, 1355.0, 1347.73 }); - STravelTimeTable.add(new double[] { 1488.83, 1484.66, 1479.55, 1476.42, 1466.0, 1455.62, 1445.27, 1435.04, - 1425.04, 1415.26, 1405.7, 1396.73, 1388.09, 1379.68, 1371.48, 1363.49, 1356.2 }); - STravelTimeTable.add(new double[] { 1497.46, 1493.28, 1488.17, 1485.03, 1474.6, 1464.2, 1453.85, 1443.6, - 1433.58, 1423.79, 1414.21, 1405.23, 1396.57, 1388.14, 1379.92, 1371.91, 1364.6 }); - STravelTimeTable.add(new double[] { 1506.0, 1501.82, 1496.71, 1493.57, 1483.12, 1472.71, 1462.34, 1452.08, - 1442.05, 1432.24, 1422.65, 1413.65, 1404.97, 1396.51, 1388.28, 1380.26, 1372.94 }); - STravelTimeTable.add(new double[] { 1514.47, 1510.29, 1505.17, 1502.02, 1491.56, 1481.14, 1470.76, 1460.48, - 1450.43, 1440.61, 1431.01, 1422.0, 1413.31, 1404.86, 1396.62, 1388.6, 1381.28 }); - STravelTimeTable.add(new double[] { 1522.86, 1518.67, 1513.55, 1510.4, 1499.93, 1489.5, 1479.1, 1468.82, - 1458.77, 1448.95, 1439.35, 1430.34, 1421.65, 1413.2, 1404.96, 1396.94, 1389.62 }); - STravelTimeTable.add(new double[] { 1531.2, 1527.01, 1521.89, 1518.74, 1508.27, 1497.84, 1487.45, 1477.16, - 1467.11, 1457.29, 1447.69, 1438.68, 1429.99, 1421.54, 1413.3, 1405.28, 1397.96 }); - STravelTimeTable.add(new double[] { 1539.54, 1535.35, 1530.23, 1527.08, 1516.61, 1506.18, 1495.79, 1485.51, - 1475.45, 1465.63, 1456.03, 1447.02, 1438.33, 1429.88, 1421.64, 1413.62, 1406.3 }); - STravelTimeTable.add(new double[] { 1547.88, 1543.69, 1538.57, 1535.42, 1524.95, 1514.52, 1504.13, 1493.85, - 1483.8, 1473.97, 1464.37, 1455.36, 1446.67, 1438.22, 1429.98, 1421.96, 1414.64 }); - STravelTimeTable.add(new double[] { 1556.22, 1552.03, 1546.91, 1543.76, 1533.29, 1522.86, 1512.47, 1502.19, - 1492.14, 1482.31, 1472.71, 1463.7, 1455.01, 1446.56, 1438.32, 1430.31, 1422.98 }); - STravelTimeTable.add(new double[] { 1564.56, 1560.37, 1555.25, 1552.1, 1541.63, 1531.2, 1520.81, 1510.53, - 1500.48, 1490.65, 1481.05, 1472.04, 1463.36, 1454.9, 1446.66, 1438.65, 1431.32 }); - STravelTimeTable.add(new double[] { 1572.9, 1568.71, 1563.59, 1560.44, 1549.97, 1539.54, 1529.15, 1518.87, - 1508.82, 1498.99, 1489.39, 1480.38, 1471.7, 1463.24, 1455.0, 1446.99, 1439.66 }); - STravelTimeTable.add(new double[] { 1581.24, 1577.05, 1571.93, 1568.78, 1558.31, 1547.88, 1537.49, 1527.21, - 1517.16, 1507.33, 1497.73, 1488.72, 1480.04, 1471.58, 1463.35, 1455.33, 1448.01 }); - STravelTimeTable.add(new double[] { 1589.58, 1585.39, 1580.27, 1577.12, 1566.65, 1556.22, 1545.83, 1535.55, - 1525.5, 1515.67, 1506.07, 1497.06, 1488.38, 1479.92, 1471.69, 1463.67, 1456.35 }); - STravelTimeTable.add(new double[] { 1597.92, 1593.74, 1588.61, 1585.46, 1574.99, 1564.56, 1554.17, 1543.89, - 1533.84, 1524.02, 1514.41, 1505.4, 1496.72, 1488.26, 1480.03, 1472.01, 1464.69 }); - STravelTimeTable.add(new double[] { 1606.26, 1602.08, 1596.95, 1593.8, 1583.33, 1572.9, 1562.51, 1552.23, - 1542.18, 1532.36, 1522.75, 1513.74, 1505.06, 1496.6, 1488.37, 1480.35, 1473.03 }); - STravelTimeTable.add(new double[] { 1614.6, 1610.42, 1605.29, 1602.14, 1591.67, 1581.24, 1570.85, 1560.57, - 1550.52, 1540.7, 1531.09, 1522.08, 1513.4, 1504.94, 1496.71, 1488.69, 1481.37 }); - STravelTimeTable.add(new double[] { 1622.94, 1618.76, 1613.63, 1610.48, 1600.01, 1589.58, 1579.19, 1568.91, - 1558.86, 1549.04, 1539.43, 1530.42, 1521.74, 1513.28, 1505.05, 1497.03, 1489.71 }); - STravelTimeTable.add(new double[] { 1631.28, 1627.1, 1621.97, 1618.82, 1608.35, 1597.92, 1587.53, 1577.25, - 1567.2, 1557.38, 1547.77, 1538.76, 1530.08, 1521.62, 1513.39, 1505.37, 1498.05 }); - STravelTimeTable.add(new double[] { 1639.62, 1635.44, 1630.31, 1627.16, 1616.69, 1606.26, 1595.87, 1585.59, - 1575.54, 1565.72, 1556.11, 1547.1, 1538.42, 1529.96, 1521.73, 1513.71, 1506.39 }); - STravelTimeTable.add(new double[] { 1647.97, 1643.78, 1638.65, 1635.51, 1625.03, 1614.61, 1604.21, 1593.93, - 1583.88, 1574.06, 1564.46, 1555.45, 1546.76, 1538.31, 1530.07, 1522.05, 1514.73 }); - STravelTimeTable.add(new double[] { 1656.31, 1652.12, 1647.0, 1643.85, 1633.38, 1622.95, 1612.55, 1602.27, - 1592.22, 1582.4, 1572.8, 1563.79, 1555.1, 1546.65, 1538.41, 1530.39, 1523.07 }); - STravelTimeTable.add(new double[] { 1664.65, 1660.46, 1655.34, 1652.19, 1641.72, 1631.29, 1620.89, 1610.61, - 1600.56, 1590.74, 1581.14, 1572.13, 1563.44, 1554.99, 1546.75, 1538.73, 1531.41 }); - STravelTimeTable.add(new double[] { 1672.99, 1668.8, 1663.68, 1660.53, 1650.06, 1639.63, 1629.24, 1618.95, - 1608.9, 1599.08, 1589.48, 1580.47, 1571.78, 1563.33, 1555.09, 1547.07, 1539.75 }); - STravelTimeTable.add(new double[] { 1681.33, 1677.14, 1672.02, 1668.87, 1658.4, 1647.97, 1637.58, 1627.3, - 1617.25, 1607.42, 1597.82, 1588.81, 1580.12, 1571.67, 1563.43, 1555.41, 1548.09 }); - STravelTimeTable.add(new double[] { 1689.67, 1685.48, 1680.36, 1677.21, 1666.74, 1656.31, 1645.92, 1635.64, - 1625.59, 1615.76, 1606.16, 1597.15, 1588.46, 1580.01, 1571.77, 1563.75, 1556.43 }); - STravelTimeTable.add(new double[] { 1698.01, 1693.82, 1688.7, 1685.55, 1675.08, 1664.65, 1654.26, 1643.98, - 1633.93, 1624.1, 1614.5, 1605.49, 1596.8, 1588.35, 1580.11, 1572.1, 1564.77 }); - STravelTimeTable.add(new double[] { 1706.35, 1702.16, 1697.04, 1693.89, 1683.42, 1672.99, 1662.6, 1652.32, - 1642.27, 1632.44, 1622.84, 1613.83, 1605.15, 1596.69, 1588.45, 1580.44, 1573.11 }); - STravelTimeTable.add(new double[] { 1714.69, 1710.5, 1705.38, 1702.23, 1691.76, 1681.33, 1670.94, 1660.66, - 1650.61, 1640.78, 1631.18, 1622.17, 1613.49, 1605.03, 1596.8, 1588.78, 1581.45 }); - STravelTimeTable.add(new double[] { 1723.03, 1718.84, 1713.72, 1710.57, 1700.1, 1689.67, 1679.28, 1669.0, - 1658.95, 1649.12, 1639.52, 1630.51, 1621.83, 1613.37, 1605.14, 1597.12, 1589.8 }); - STravelTimeTable.add(new double[] { 1731.37, 1727.18, 1722.06, 1718.91, 1708.44, 1698.01, 1687.62, 1677.34, - 1667.29, 1657.46, 1647.86, 1638.85, 1630.17, 1621.71, 1613.48, 1605.46, 1598.14 }); - - PKPTravelTimeTable.add(new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }); - PKPTravelTimeTable.add(new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }); - PKPTravelTimeTable.add(new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 1085.33, 1063.71, 1044.28 }); - PKPTravelTimeTable.add(new double[] { 1124.84, 1119.11, 1117.27, 1111.11, 1098.95, 1087.25, 1065.64, 1046.21 }); - PKPTravelTimeTable.add(new double[] { 1126.76, 1121.04, 1119.19, 1113.04, 1100.88, 1089.17, 1067.56, 1048.13 }); - PKPTravelTimeTable.add(new double[] { 1128.68, 1122.96, 1121.11, 1114.96, 1102.8, 1091.1, 1069.49, 1050.05 }); - PKPTravelTimeTable.add(new double[] { 1130.61, 1124.88, 1123.04, 1116.88, 1104.72, 1093.02, 1071.41, 1051.98 }); - PKPTravelTimeTable.add(new double[] { 1132.53, 1126.81, 1124.96, 1118.81, 1106.65, 1094.94, 1073.33, 1053.9 }); - PKPTravelTimeTable.add(new double[] { 1134.45, 1128.73, 1126.88, 1120.73, 1108.57, 1096.86, 1075.25, 1055.82 }); - PKPTravelTimeTable.add(new double[] { 1136.37, 1130.65, 1128.8, 1122.65, 1110.49, 1098.79, 1077.17, 1057.74 }); - PKPTravelTimeTable.add(new double[] { 1138.29, 1132.57, 1130.72, 1124.57, 1112.41, 1100.7, 1079.09, 1059.66 }); - PKPTravelTimeTable.add(new double[] { 1140.21, 1134.49, 1132.64, 1126.49, 1114.33, 1102.62, 1081.01, 1061.57 }); - PKPTravelTimeTable.add(new double[] { 1142.13, 1136.4, 1134.56, 1128.4, 1116.24, 1104.54, 1082.92, 1063.49 }); - PKPTravelTimeTable.add(new double[] { 1144.04, 1138.32, 1136.47, 1130.32, 1118.15, 1106.45, 1084.83, 1065.4 }); - PKPTravelTimeTable.add(new double[] { 1145.95, 1140.23, 1138.38, 1132.23, 1120.06, 1108.36, 1086.74, 1067.3 }); - PKPTravelTimeTable.add(new double[] { 1147.86, 1142.14, 1140.29, 1134.13, 1121.97, 1110.27, 1088.65, 1069.21 }); - PKPTravelTimeTable.add(new double[] { 1149.76, 1144.04, 1142.19, 1136.04, 1123.88, 1112.17, 1090.55, 1071.11 }); - PKPTravelTimeTable.add(new double[] { 1151.67, 1145.94, 1144.09, 1137.94, 1125.78, 1114.07, 1092.45, 1073.0 }); - PKPTravelTimeTable.add(new double[] { 1153.56, 1147.84, 1145.99, 1139.83, 1127.67, 1115.96, 1094.34, 1074.9 }); - PKPTravelTimeTable.add(new double[] { 1155.45, 1149.73, 1147.88, 1141.72, 1129.56, 1117.85, 1096.23, 1076.78 }); - PKPTravelTimeTable.add(new double[] { 1157.34, 1151.61, 1149.77, 1143.61, 1131.45, 1119.74, 1098.11, 1078.66 }); - PKPTravelTimeTable.add(new double[] { 1159.22, 1153.49, 1151.65, 1145.49, 1133.32, 1121.61, 1099.98, 1080.53 }); - PKPTravelTimeTable.add(new double[] { 1161.09, 1155.37, 1153.52, 1147.36, 1135.19, 1123.48, 1101.85, 1082.4 }); - PKPTravelTimeTable.add(new double[] { 1162.96, 1157.23, 1155.38, 1149.22, 1137.06, 1125.34, 1103.71, 1084.25 }); - PKPTravelTimeTable.add(new double[] { 1164.81, 1159.08, 1157.24, 1151.08, 1138.91, 1127.19, 1105.56, 1086.09 }); - PKPTravelTimeTable.add(new double[] { 1166.66, 1160.93, 1159.08, 1152.92, 1140.75, 1129.04, 1107.4, 1087.93 }); - PKPTravelTimeTable.add(new double[] { 1168.49, 1162.76, 1160.91, 1154.76, 1142.58, 1130.87, 1109.22, 1089.75 }); - PKPTravelTimeTable.add(new double[] { 1170.31, 1164.59, 1162.74, 1156.58, 1144.4, 1132.68, 1111.04, 1091.56 }); - PKPTravelTimeTable.add(new double[] { 1172.12, 1166.39, 1164.54, 1158.38, 1146.21, 1134.49, 1112.83, 1093.35 }); - PKPTravelTimeTable.add(new double[] { 1173.92, 1168.19, 1166.34, 1160.18, 1148.0, 1136.27, 1114.62, 1095.13 }); - PKPTravelTimeTable.add(new double[] { 1175.69, 1169.96, 1168.11, 1161.95, 1149.77, 1138.04, 1116.38, 1096.88 }); - PKPTravelTimeTable.add(new double[] { 1177.45, 1171.72, 1169.87, 1163.71, 1151.52, 1139.79, 1118.13, 1098.62 }); - PKPTravelTimeTable.add(new double[] { 1179.19, 1173.46, 1171.61, 1165.44, 1153.26, 1141.52, 1119.85, 1100.34 }); - PKPTravelTimeTable.add(new double[] { 1180.9, 1175.17, 1173.32, 1167.15, 1154.96, 1143.23, 1121.55, 1102.02 }); - PKPTravelTimeTable.add(new double[] { 1182.59, 1176.86, 1175.01, 1168.84, 1156.65, 1144.91, 1123.22, 1103.69 }); - PKPTravelTimeTable.add(new double[] { 1184.25, 1178.52, 1176.67, 1170.5, 1158.3, 1146.56, 1124.86, 1105.32 }); - PKPTravelTimeTable.add(new double[] { 1185.88, 1180.15, 1178.3, 1172.12, 1159.93, 1148.18, 1126.47, 1106.92 }); - PKPTravelTimeTable.add(new double[] { 1187.48, 1181.74, 1179.89, 1173.72, 1161.51, 1149.76, 1128.05, 1108.48 }); - PKPTravelTimeTable.add(new double[] { 1189.04, 1183.3, 1181.45, 1175.27, 1163.06, 1151.31, 1129.58, 1110.0 }); - PKPTravelTimeTable.add(new double[] { 1190.55, 1184.82, 1182.96, 1176.78, 1164.57, 1152.81, 1131.07, 1111.49 }); - PKPTravelTimeTable.add(new double[] { 1192.03, 1186.29, 1184.44, 1178.26, 1166.04, 1154.28, 1132.53, 1112.93 }); - PKPTravelTimeTable.add(new double[] { 1193.47, 1187.73, 1185.87, 1179.69, 1167.47, 1155.7, 1133.94, 1114.33 }); - PKPTravelTimeTable.add(new double[] { 1194.86, 1189.12, 1187.26, 1181.08, 1168.85, 1157.08, 1135.31, 1115.69 }); - PKPTravelTimeTable.add(new double[] { 1196.2, 1190.46, 1188.61, 1182.42, 1170.19, 1158.42, 1136.63, 1117.0 }); - PKPTravelTimeTable.add(new double[] { 1197.5, 1191.76, 1189.9, 1183.72, 1171.48, 1159.7, 1137.91, 1118.26 }); - PKPTravelTimeTable.add(new double[] { 1198.75, 1193.01, 1191.15, 1184.96, 1172.73, 1160.94, 1139.14, 1119.48 }); - PKPTravelTimeTable.add(new double[] { 1199.96, 1194.21, 1192.35, 1186.16, 1173.92, 1162.13, 1140.32, 1120.64 }); - PKPTravelTimeTable.add(new double[] { 1201.11, 1195.36, 1193.5, 1187.31, 1175.06, 1163.27, 1141.45, 1121.76 }); - PKPTravelTimeTable.add(new double[] { 1202.2, 1196.46, 1194.6, 1188.4, 1176.15, 1164.35, 1142.52, 1122.83 }); - PKPTravelTimeTable.add(new double[] { 1203.25, 1197.5, 1195.64, 1189.44, 1177.19, 1165.39, 1143.55, 1123.84 }); - PKPTravelTimeTable.add(new double[] { 1204.24, 1198.49, 1196.63, 1190.43, 1178.18, 1166.37, 1144.52, 1124.81 }); - PKPTravelTimeTable.add(new double[] { 1205.18, 1199.43, 1197.57, 1191.37, 1179.11, 1167.3, 1145.44, 1125.72 }); - PKPTravelTimeTable.add(new double[] { 1206.06, 1200.31, 1198.45, 1192.25, 1179.99, 1168.17, 1146.31, 1126.57 }); - PKPTravelTimeTable.add(new double[] { 1206.89, 1201.14, 1199.28, 1193.07, 1180.81, 1168.99, 1147.12, 1127.37 }); - PKPTravelTimeTable.add(new double[] { 1207.66, 1201.91, 1200.05, 1193.84, 1181.58, 1169.75, 1147.88, 1128.12 }); - PKPTravelTimeTable.add(new double[] { 1208.38, 1202.63, 1200.77, 1194.56, 1182.29, 1170.46, 1148.58, 1128.82 }); - PKPTravelTimeTable.add(new double[] { 1209.04, 1203.29, 1201.43, 1195.22, 1182.94, 1171.12, 1149.22, 1129.46 }); - PKPTravelTimeTable.add(new double[] { 1209.64, 1203.89, 1202.03, 1195.82, 1183.54, 1171.71, 1149.81, 1130.04 }); - PKPTravelTimeTable.add(new double[] { 1210.19, 1204.44, 1202.57, 1196.36, 1184.08, 1172.25, 1150.35, 1130.57 }); - PKPTravelTimeTable.add(new double[] { 1210.68, 1204.93, 1203.06, 1196.85, 1184.57, 1172.74, 1150.83, 1131.04 }); - PKPTravelTimeTable.add(new double[] { 1211.11, 1205.36, 1203.49, 1197.28, 1185.0, 1173.16, 1151.25, 1131.46 }); - PKPTravelTimeTable.add(new double[] { 1211.49, 1205.73, 1203.87, 1197.65, 1185.37, 1173.53, 1151.62, 1131.83 }); - PKPTravelTimeTable.add(new double[] { 1211.81, 1206.05, 1204.19, 1197.97, 1185.69, 1173.85, 1151.93, 1132.13 }); - PKPTravelTimeTable.add(new double[] { 1212.07, 1206.31, 1204.44, 1198.23, 1185.94, 1174.1, 1152.18, 1132.38 }); - PKPTravelTimeTable.add(new double[] { 1212.27, 1206.51, 1204.65, 1198.43, 1186.14, 1174.3, 1152.38, 1132.58 }); - PKPTravelTimeTable.add(new double[] { 1212.41, 1206.66, 1204.79, 1198.58, 1186.29, 1174.45, 1152.52, 1132.72 }); - PKPTravelTimeTable.add(new double[] { 1212.5, 1206.74, 1204.88, 1198.66, 1186.37, 1174.53, 1152.61, 1132.8 }); - PKPTravelTimeTable.add(new double[] { 1212.53, 1206.77, 1204.91, 1198.69, 1186.4, 1174.56, 1152.64, 1132.83 }); - - dataCheck(); - } - - private static void dataCheck() { - int errors = 0; - for (int i = 0; i < PTravelTimeTable.size() - 1; i++) { - for (int j = 0; j < DEPTHS.length; j++) { - if (PTravelTimeTable.get(i + 1)[j] < PTravelTimeTable.get(i)[j]) { - errors++; - } - } - } - for (int i = 0; i < STravelTimeTable.size() - 1; i++) { - for (int j = 0; j < DEPTHS.length; j++) { - if (STravelTimeTable.get(i + 1)[j] < STravelTimeTable.get(i)[j]) { - errors++; - } - } - } - - Logger.debug("[TravelTimeTable] found " + errors + " errors."); - } - - @SuppressWarnings("unused") - public static double getPKPWaveTravelTime(double depth, double angle) { - double val = _getPKPWaveTravelTime(depth, angle); - if (val == 0) { - return Double.POSITIVE_INFINITY; - } else { - return val; - } - } - - private static double _getPKPWaveTravelTime(double depth, double angle) { - depth = Math.max(0, Math.min(DEPTHS_PKP[DEPTHS_PKP.length - 1], depth)); - int d = 0; - double q = 0; - for (int i = 0; i < DEPTHS_PKP.length - 1; i++) { - if (DEPTHS_PKP[i + 1] >= depth) { - d = i; - double max = DEPTHS_PKP[i + 1]; - double min = DEPTHS_PKP[i]; - q = (depth - min) / (max - min); - break; - } - } - - if (angle <= PKP_START) { - return Double.POSITIVE_INFINITY; - } else if (angle - PKP_START >= PKPTravelTimeTable.size() - 1) { - return PKPTravelTimeTable.get(PKPTravelTimeTable.size() - 1)[d] * (1 - q) - + PKPTravelTimeTable.get(PKPTravelTimeTable.size() - 1)[d + 1] * (q); - } - - int low = (int) (angle - PKP_START); - int high = low + 1; - - double valHigh = PKPTravelTimeTable.get(high)[d] * (1 - q) + PKPTravelTimeTable.get(high)[d + 1] * (q); - double valLow = PKPTravelTimeTable.get(low)[d] * (1 - q) + PKPTravelTimeTable.get(low)[d + 1] * (q); - - if (PKPTravelTimeTable.get(high)[d] <= 0 || PKPTravelTimeTable.get(high)[d + 1] <= 0 - || PKPTravelTimeTable.get(low)[d] <= 0 || PKPTravelTimeTable.get(low)[d + 1] <= 0) { - return Double.POSITIVE_INFINITY; - } - - double r = angle % 1.0; - return (1 - r) * valLow + r * valHigh; - } - - /** - * - * @param depth depth in km - * @param angle angle - * @return P wave travel time in seconds - */ - public static double getPWaveTravelTime(double depth, double angle) { - depth = Math.max(0, Math.min(DEPTHS[DEPTHS.length - 1], depth)); - int d = 0; - double q = 0; - for (int i = 0; i < DEPTHS.length - 1; i++) { - if (DEPTHS[i + 1] >= depth) { - d = i; - double max = DEPTHS[i + 1]; - double min = DEPTHS[i]; - q = (depth - min) / (max - min); - break; - } - } - - if (angle <= 0) { - return PTravelTimeTable.get(0)[d] * (1 - q) + PTravelTimeTable.get(0)[d + 1] * (q); - } else if (angle >= PTravelTimeTable.size() - 1) { - return PTravelTimeTable.get(PTravelTimeTable.size() - 1)[d] * (1 - q) - + PTravelTimeTable.get(PTravelTimeTable.size() - 1)[d + 1] * (q); - } - - int low = (int) (angle); - int high = low + 1; - - double valHigh = PTravelTimeTable.get(high)[d] * (1 - q) + PTravelTimeTable.get(high)[d + 1] * (q); - double valLow = PTravelTimeTable.get(low)[d] * (1 - q) + PTravelTimeTable.get(low)[d + 1] * (q); - - double r = angle % 1.0; - return (1 - r) * valLow + r * valHigh; - } - - public static double getSWaveTravelTime(double depth, double angle) { - depth = Math.max(0, Math.min(DEPTHS[DEPTHS.length - 1], depth)); - int d = 0; - double q = 0; - for (int i = 0; i < DEPTHS.length - 1; i++) { - if (DEPTHS[i + 1] >= depth) { - d = i; - double max = DEPTHS[i + 1]; - double min = DEPTHS[i]; - q = (depth - min) / (max - min); - break; - } - } - if (angle <= 0) { - return STravelTimeTable.get(0)[d] * (1 - q) + STravelTimeTable.get(0)[d + 1] * (q); - } else if (angle >= STravelTimeTable.size() - 1) { - return STravelTimeTable.get(STravelTimeTable.size() - 1)[d] * (1 - q) - + STravelTimeTable.get(STravelTimeTable.size() - 1)[d + 1] * (q); - } - int low = (int) (angle); - int high = low + 1; - - double valHigh = STravelTimeTable.get(high)[d] * (1 - q) + STravelTimeTable.get(high)[d + 1] * (q); - double valLow = STravelTimeTable.get(low)[d] * (1 - q) + STravelTimeTable.get(low)[d + 1] * (q); - - double r = angle % 1.0; - return (1 - r) * valLow + r * valHigh; - } - - /** - * -1 WHEN IT HASN'T OCCURRED YET +INFINITY WHEN IT ALREADY PASSED THE EARTH - **/ - - @SuppressWarnings("unused") - public static double getPKPWaveTravelAngle(double depth, double ageSec) { - depth = Math.max(0, Math.min(DEPTHS_PKP[DEPTHS_PKP.length - 1], depth)); - int d = 0; - double q = 0; - for (int i = 0; i < DEPTHS_PKP.length - 1; i++) { - if (DEPTHS_PKP[i + 1] >= depth) { - d = i; - double max = DEPTHS_PKP[i + 1]; - double min = DEPTHS_PKP[i]; - q = (depth - min) / (max - min); - break; - } - } - - // System.out.println("lower: " + DEPTHS[d] + ", upper: " + DEPTHS[d + 1] + ", " - // + q); - - // System.out.println("val0=" + val0+", "+d+", "+q); - // its still underground - - double valN = PKPTravelTimeTable.get(PKPTravelTimeTable.size() - 1)[d] * (1 - q) - + PKPTravelTimeTable.get(PKPTravelTimeTable.size() - 1)[d + 1] * (q); - // System.out.println("valN=" + valN); - // exceeded 125° - if (ageSec > valN) { - return Double.POSITIVE_INFINITY; - } - - int lo = 0; - int hi = PKPTravelTimeTable.size() - 1; - - while (lo <= hi) { - int mid = (hi + lo) / 2; - double val = PKPTravelTimeTable.get(mid)[d] * (1 - q) + PKPTravelTimeTable.get(mid)[d + 1] * (q); - if (ageSec < val) { - hi = mid - 1; - } else if (ageSec >= val) { - lo = mid + 1; - } - } - - double valLo = PKPTravelTimeTable.get(lo)[d] * (1 - q) + PKPTravelTimeTable.get(lo)[d + 1] * (q); - double valHi = PKPTravelTimeTable.get(hi)[d] * (1 - q) + PKPTravelTimeTable.get(hi)[d + 1] * (q); - if (PKPTravelTimeTable.get(hi)[d] <= 0 || PKPTravelTimeTable.get(hi)[d + 1] <= 0 - || PKPTravelTimeTable.get(lo)[d] <= 0 || PKPTravelTimeTable.get(lo)[d + 1] <= 0) { - return Double.POSITIVE_INFINITY; - } - double r = (ageSec - valHi) / (valLo - valHi); + public static final double[] DEPTHS = {0, 15, 35, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, + 700}; + public static final double[] DEPTHS_PKP = {0, 35, 50, 100, 200, 300, 500, 700}; + + private static final int PKP_START = 113; + + public static final ArrayList PTravelTimeTable = new ArrayList<>(); + public static final ArrayList STravelTimeTable = new ArrayList<>(); + public static final ArrayList PKPTravelTimeTable = new ArrayList<>(); + + static { + fillTable(); + } + + private static void fillTable() { + PTravelTimeTable.add(new double[]{0.0, 2.59, 5.76, 7.62, 13.84, 20.03, 26.12, 32.11, 37.97, 43.7, 49.32, + 54.67, 59.89, 65.02, 70.07, 75.02, 79.7}); + PTravelTimeTable.add(new double[]{19.17, 19.01, 17.51, 17.7, 20.39, 24.73, 29.72, 34.99, 40.34, 45.71, 51.05, + 56.18, 61.23, 66.21, 71.14, 76.0, 80.58}); + PTravelTimeTable.add(new double[]{35.03, 33.23, 31.27, 31.32, 32.54, 35.08, 38.47, 42.42, 46.73, 51.26, 55.91, + 60.47, 65.03, 69.62, 74.22, 78.78999999999999, 83.13}); + PTravelTimeTable.add(new double[]{48.78, 46.98, 45.02, 45.02, 45.71, 47.32, 49.59, 52.43, 55.71, 59.31, 63.16, + 66.97, 70.91, 74.95, 79.07, 83.24, 87.18}); + PTravelTimeTable.add(new double[]{62.53, 60.73, 58.77, 58.74, 59.14, 60.2, 61.73, 63.75, 66.17, 68.95, 72.02, + 75.09, 78.35, 81.78999999999999, 85.37, 89.06, 92.55}); + PTravelTimeTable.add(new double[]{76.27, 74.47, 72.51, 72.45, 72.67, 73.36, 74.35, 75.74, 77.48, 79.56, 81.95, + 84.31, 86.91, 89.76, 92.78999999999999, 95.97999999999999, 98.97}); + PTravelTimeTable.add(new double[]{90.01, 88.21000000000001, 86.25, 86.17, 86.24, 86.64, 87.2, 88.08, 89.26, + 90.76, 92.56, 94.25, 96.25, 98.53999999999999, 101.05, 103.74000000000001, 106.22999999999999}); + PTravelTimeTable.add(new double[]{103.75, 101.94, 99.97999999999999, 99.88, 99.83, 99.97999999999999, 100.17, + 100.62, 101.32, 102.32, 103.61, 104.66, 106.12, 107.89, 109.92, 112.15, 114.12}); + PTravelTimeTable.add(new double[]{117.47, 115.67, 113.7, 113.58, 113.42, 113.33, 113.18, 113.24000000000001, + 113.52000000000001, 114.08, 114.92, 115.35, 116.33, 117.64, 119.22999999999999, 121.02, 122.49}); + PTravelTimeTable.add(new double[]{131.19, 129.38, 127.41, 127.27, 127.02, 126.66, 126.2, 125.89, 125.79, + 125.96, 126.4, 126.17, 126.74, 127.66, 128.84, 130.24, 131.18}); + PTravelTimeTable.add(new double[]{144.9, 143.09, 141.12, 140.96, 140.62, 139.93, 139.17000000000002, 138.51, + 138.07, 137.88, 137.52, 137.05, 137.28, 137.84, 138.66, 139.7, 140.09}); + PTravelTimeTable.add(new double[]{158.59, 156.78, 154.81, 154.63, 154.21, 153.12, 152.05, 151.06, 150.3, + 149.8, 148.59, 147.93, 147.87, 148.12, 148.61, 149.32999999999998, 149.11}); + PTravelTimeTable.add(new double[]{172.27, 170.46, 168.48, 168.29, 167.59, 166.19, 164.8, 163.51, 162.47, + 161.55, 159.62, 158.79, 158.47, 158.44, 158.64, 158.56, 158.17000000000002}); + PTravelTimeTable.add(new double[]{185.94, 184.13, 182.14, 181.93, 180.8, 179.1, 177.41, 175.85, 174.55, 172.6, + 170.61, 169.61, 169.06, 168.77, 168.71, 167.78, 167.26}); + PTravelTimeTable.add(new double[]{199.59, 197.78, 195.79, 195.56, 193.83, 191.81, 189.85, 188.06, 185.98, + 183.6, 181.54, 180.37, 179.61, 179.09, 178.78, 176.97, 176.34}); + PTravelTimeTable.add(new double[]{213.23, 211.41, 209.32, 208.75, 206.63, 204.32, 202.13, 199.74, 196.99, + 194.54, 192.39, 191.06, 190.11, 189.37, 188.06, 186.15, 185.4}); + PTravelTimeTable + .add(new double[]{226.37, 224.46, 222.31, 221.62, 219.17000000000002, 216.64, 213.82999999999998, + 210.73, 207.93, 205.41, 203.17000000000002, 201.68, 200.53, 199.44, 197.24, 195.29, 194.44}); + PTravelTimeTable.add(new double[]{239.13, 237.17000000000002, 234.96, 234.17000000000002, 231.49, 228.19, + 224.81, 221.67000000000002, 218.79, 216.19, 213.85, 212.21, 210.88, 208.62, 206.39, 204.41, 203.45}); + PTravelTimeTable.add(new double[]{251.57, 249.59, 247.33, 246.46, 242.77, 239.15, 235.72, 232.52, 229.57, + 226.88, 224.43, 222.63, 220.26, 217.77, 215.51, 213.48, 212.42000000000002}); + PTravelTimeTable.add(new double[]{263.16, 261.04, 258.57, 257.44, 253.71, 250.04, 246.55, 243.28, 240.24, + 237.45, 234.9, 232.15, 229.41, 226.89, 224.59, 222.52, 221.35}); + PTravelTimeTable.add(new double[]{274.1, 271.97, 269.49, 268.35, 264.56, 260.83, 257.28, 253.93, 250.81, + 247.86, 244.33, 241.29, 238.53, 235.97, 233.63, 231.5, 230.23}); + PTravelTimeTable.add(new double[]{284.95, 282.82, 280.32, 279.15999999999997, 275.32, 271.52, 267.89, 264.46, + 260.76, 257.01, 253.47, 250.4, 247.6, 245.01, 242.62, 240.43, 239.09}); + PTravelTimeTable.add(new double[]{295.71, 293.56, 291.05, 289.87, 285.96, 282.09000000000003, + 278.09000000000003, 273.89, 269.9, 266.12, 262.56, 259.46, 256.63, 253.99, 251.54, 249.31, 247.93}); + PTravelTimeTable.add(new double[]{306.34, 304.18, 301.65, 300.46, 296.18, 291.62, 287.22, 283.0, 279.0, 275.2, + 271.61, 268.48, 265.6, 262.91, 260.43, 258.16, 256.73}); + PTravelTimeTable.add(new double[]{316.31, 314.04, 311.33, 309.94, 305.31, 300.74, 296.32, 292.08, 288.05, + 284.23, 280.61, 277.43, 274.51, 271.79, 269.28, 266.99, 265.51}); + PTravelTimeTable.add(new double[]{325.43, 323.15, 320.44, 319.04, 314.4, 309.81, 305.37, 301.11, 297.05, + 293.2, 289.53, 286.33, 283.38, 280.64, 278.1, 275.78, 274.25}); + PTravelTimeTable.add(new double[]{334.5, 332.23, 329.51, 328.11, 323.45, 318.83, 314.37, 310.08, 305.99, + 302.1, 298.42, 295.19, 292.22, 289.45, 286.89, 284.54, 282.94}); + PTravelTimeTable.add(new double[]{343.54, 341.25, 338.53, 337.12, 332.44, 327.79, 323.3, 318.99, 314.88, + 310.97, 307.27, 304.02, 301.03, 298.24, 295.65, 293.25, 291.58}); + PTravelTimeTable.add(new double[]{352.5, 350.22, 347.49, 346.07, 341.35, 336.69, 332.19, 327.85, 323.73, + 319.81, 316.09, 312.82, 309.81, 306.99, 304.36, 301.91, 300.17}); + PTravelTimeTable.add(new double[]{361.41, 359.12, 356.38, 354.96, 350.23, 345.56, 341.04, 336.69, 332.55, + 328.62, 324.88, 321.59, 318.55, 315.69, 313.01, 310.52, 308.71}); + PTravelTimeTable.add(new double[]{370.27, 367.98, 365.24, 363.82, 359.08, 354.39, 349.86, 345.5, + 341.34000000000003, 337.39, 333.63, 330.31, 327.23, 324.33, 321.61, 319.07, 317.2}); + PTravelTimeTable.add(new double[]{379.11, 376.81, 374.07, 372.64, 367.89, 363.19, 358.64, 354.27, + 350.09000000000003, 346.11, 342.33, 338.97, 335.85, 332.90999999999997, 330.15, 327.57, 325.63}); + PTravelTimeTable.add(new double[]{387.91, 385.62, 382.87, 381.44, 376.67, 371.96, 367.39, 362.99, 358.79, + 354.78, 350.97, 347.58, 344.42, 341.44, 338.64, 336.01, 334.01}); + PTravelTimeTable.add(new double[]{396.68, 394.38, 391.63, 390.19, 385.41, 380.67, 376.08, 371.66, 367.43, + 363.4, 359.55, 356.13, 352.93, 349.90999999999997, 347.06, 344.39, 342.32}); + PTravelTimeTable.add(new double[]{405.4, 403.09000000000003, 400.34000000000003, 398.89, 394.09000000000003, + 389.33, 384.71, 380.27, 376.01, 371.95, 368.07, 364.61, 361.38, 358.32, 355.43, 352.71, 350.58}); + PTravelTimeTable.add(new double[]{414.06, 411.75, 408.99, 407.54, 402.71, 397.93, 393.29, 388.82, 384.53, + 380.44, 376.54, 373.04, 369.77, 366.67, 363.73, 360.96, 358.78}); + PTravelTimeTable.add(new double[]{422.66, 420.34, 417.58, 416.12, 411.27, 406.46, 401.8, 397.3, 392.99, + 388.87, 384.94, 381.41, 378.1, 374.96, 371.98, 369.16, 366.92}); + PTravelTimeTable.add(new double[]{431.19, 428.88, 426.1, 424.64, 419.76, 414.94, 410.25, 405.73, 401.39, + 397.24, 393.27, 389.71, 386.36, 383.18, 380.16, 377.3, 375.0}); + PTravelTimeTable.add(new double[]{439.67, 437.35, 434.57, 433.09, 428.2, 423.35, 418.64, 414.09000000000003, + 409.72, 405.54, 401.54, 397.94, 394.56, 391.34, 388.27, 385.37, 383.02}); + PTravelTimeTable.add(new double[]{448.08, 445.75, 442.97, 441.49, 436.57, 431.69, 426.96, 422.38, 417.99, + 413.78, 409.75, 406.11, 402.69, 399.43, 396.33, 393.38, 390.97}); + PTravelTimeTable.add(new double[]{456.42, 454.09000000000003, 451.3, 449.81, 444.87, 439.97, 435.21, 430.6, + 426.19, 421.95, 417.88, 414.22, 410.76, 407.46, 404.31, 401.32, 398.86}); + PTravelTimeTable.add(new double[]{464.7, 462.36, 459.56, 458.07, 453.1, 448.18, 443.39, 438.76, 434.32, + 430.05, 425.96, 422.25, 418.76, 415.42, 412.23, 409.2, 406.69}); + PTravelTimeTable.add(new double[]{472.9, 470.56, 467.76, 466.26, 461.27, 456.32, 451.51, 446.85, 442.38, + 438.08, 433.96, 430.22, 426.69, 423.32, 420.09, 417.01, 414.45}); + PTravelTimeTable.add(new double[]{481.04, 478.7, 475.88, 474.38, 469.36, 464.39, 459.56, 454.87, 450.37, + 446.05, 441.89, 438.12, 434.56, 431.14, 427.88, 424.76, 422.14}); + PTravelTimeTable.add(new double[]{489.11, 486.76, 483.94, 482.43, 477.39, 472.39, 467.53, 462.83, 458.3, + 453.94, 449.76, 445.96, 442.36, 438.9, 435.6, 432.44, 429.77}); + PTravelTimeTable.add(new double[]{497.1, 494.75, 491.93, 490.4, 485.34, 480.32, 475.44, 470.71, 466.15, + 461.77, 457.55, 453.72, 450.08, 446.59, 443.25, 440.05, 437.34}); + PTravelTimeTable.add(new double[]{505.03, 502.67, 499.84, 498.31, 493.23, 488.18, 483.27, 478.52, 473.93, + 469.52, 465.28, 461.40999999999997, 457.74, 454.22, 450.84, 447.6, 444.84}); + PTravelTimeTable.add(new double[]{512.88, 510.52, 507.68, 506.14, 501.04, 495.97, 491.04, 486.26, 481.65, + 477.21, 472.94, 469.04, 465.33, 461.77, 458.35, 455.08, 452.27}); + PTravelTimeTable.add(new double[]{520.66, 518.29, 515.45, 513.91, 508.78, 503.69, 498.73, 493.92, 489.29, + 484.82, 480.52, 476.59000000000003, 472.85, 469.26, 465.8, 462.49, 459.65}); + PTravelTimeTable.add(new double[]{528.37, 526.0, 523.15, 521.6, 516.44, 511.33, 506.35, 501.52, 496.86, + 492.37, 488.04, 484.08, 480.31, 476.68, 473.19, 469.84000000000003, 466.95}); + PTravelTimeTable.add(new double[]{536.0, 533.63, 530.77, 529.21, 524.04, 518.91, 513.9, 509.04, 504.36, + 499.84, 495.48, 491.49, 487.69, 484.03, 480.51, 477.12, 474.19}); + PTravelTimeTable.add(new double[]{543.56, 541.18, 538.32, 536.76, 531.56, 526.41, 521.38, 516.5, 511.79, + 507.24, 502.86, 498.84, 495.01, 491.31, 487.76, 484.33, 481.36}); + PTravelTimeTable.add(new double[]{551.05, 548.67, 545.8, 544.23, 539.01, 533.83, 528.78, 523.88, 519.15, + 514.58, 510.17, 506.12, 502.25, 498.53, 494.93, 491.47, 488.46}); + PTravelTimeTable.add(new double[]{558.47, 556.08, 553.2, 551.63, 546.39, 541.19, 536.12, 531.19, 526.44, + 521.84, 517.41, 513.32, 509.43, 505.67, 502.05, 498.55, 495.5}); + PTravelTimeTable.add(new double[]{565.81, 563.42, 560.54, 558.96, 553.7, 548.48, 543.38, 538.43, 533.65, + 529.03, 524.57, 520.46, 516.54, 512.75, 509.09, 505.56, 502.47}); + PTravelTimeTable.add(new double[]{573.08, 570.69, 567.8, 566.21, 560.93, 555.69, 550.58, 545.6, 540.8, 536.15, + 531.66, 527.53, 523.57, 519.75, 516.06, 512.5, 509.37}); + PTravelTimeTable.add(new double[]{580.28, 577.88, 574.99, 573.39, 568.09, 562.83, 557.69, 552.7, 547.87, + 543.2, 538.69, 534.52, 530.54, 526.69, 522.97, 519.37, 516.21}); + PTravelTimeTable.add(new double[]{587.4, 585.0, 582.1, 580.5, 575.18, 569.9, 564.74, 559.72, 554.87, 550.18, + 545.64, 541.45, 537.44, 533.56, 529.81, 526.18, 522.98}); + PTravelTimeTable.add(new double[]{594.46, 592.05, 589.14, 587.54, 582.2, 576.9, 571.72, 566.68, 561.8, 557.09, + 552.53, 548.31, 544.27, 540.36, 536.57, 532.92, 529.68}); + PTravelTimeTable.add(new double[]{601.43, 599.02, 596.11, 594.5, 589.14, 583.82, 578.62, 573.56, 568.66, + 563.92, 559.34, 555.09, 551.02, 547.09, 543.27, 539.59, 536.31}); + PTravelTimeTable.add(new double[]{608.34, 605.93, 603.01, 601.39, 596.01, 590.67, 585.45, 580.37, 575.45, + 570.69, 566.08, 561.81, 557.71, 553.75, 549.91, 546.19, 542.88}); + PTravelTimeTable.add(new double[]{615.17, 612.75, 609.83, 608.21, 602.81, 597.45, 592.21, 587.11, 582.17, + 577.38, 572.75, 568.45, 564.33, 560.34, 556.47, 552.72, 549.38}); + PTravelTimeTable.add(new double[]{621.93, 619.51, 616.58, 614.95, 609.54, 604.16, 598.9, 593.77, 588.81, + 584.01, 579.35, 575.03, 570.88, 566.86, 562.97, 559.19, 555.82}); + PTravelTimeTable.add(new double[]{628.62, 626.19, 623.26, 621.63, 616.19, 610.79, 605.51, 600.37, 595.39, + 590.56, 585.88, 581.54, 577.37, 573.32, 569.4, 565.59, 562.18}); + PTravelTimeTable.add(new double[]{635.23, 632.8, 629.86, 628.23, 622.77, 617.36, 612.06, 606.9, 601.89, + 597.05, 592.35, 587.98, 583.78, 579.71, 575.76, 571.92, 568.48}); + PTravelTimeTable.add(new double[]{641.78, 639.34, 636.4, 634.76, 629.29, 623.85, 618.53, 613.35, 608.33, + 603.46, 598.74, 594.35, 590.12, 586.03, 582.05, 578.19, 574.72}); + PTravelTimeTable.add(new double[]{648.25, 645.81, 642.86, 641.21, 635.72, 630.27, 624.94, 619.74, 614.69, + 609.8, 605.06, 600.64, 596.4, 592.27, 588.27, 584.38, 580.88}); + PTravelTimeTable.add(new double[]{654.65, 652.21, 649.25, 647.6, 642.09, 636.62, 631.27, 626.05, 620.99, + 616.08, 611.31, 606.87, 602.6, 598.45, 594.42, 590.51, 586.98}); + PTravelTimeTable.add(new double[]{660.97, 658.53, 655.57, 653.91, 648.39, 642.9, 637.53, 632.29, 627.21, + 622.28, 617.49, 613.03, 608.74, 604.56, 600.51, 596.57, 593.01}); + PTravelTimeTable.add(new double[]{667.23, 664.78, 661.82, 660.15, 654.61, 649.11, 643.72, 638.46, 633.36, + 628.41, 623.6, 619.12, 614.8, 610.61, 606.52, 602.56, 598.97}); + PTravelTimeTable.add(new double[]{673.41, 670.96, 667.99, 666.32, 660.76, 655.24, 649.83, 644.56, 639.44, + 634.47, 629.65, 625.14, 620.8, 616.58, 612.47, 608.48, 604.86}); + PTravelTimeTable.add(new double[]{679.51, 677.06, 674.09, 672.41, 666.84, 661.3, 655.88, 650.59, 645.45, + 640.46, 635.61, 631.09, 626.72, 622.48, 618.35, 614.33, 610.68}); + PTravelTimeTable.add(new double[]{685.55, 683.09, 680.12, 678.44, 672.85, 667.29, 661.85, 656.54, 651.39, + 646.38, 641.51, 636.96, 632.58, 628.31, 624.15, 620.11, 616.43}); + PTravelTimeTable.add(new double[]{691.51, 689.05, 686.07, 684.39, 678.78, 673.21, 667.75, 662.43, 657.25, + 652.22, 647.34, 642.77, 638.36, 634.07, 629.89, 625.82, 622.12}); + PTravelTimeTable.add(new double[]{697.4, 694.94, 691.95, 690.26, 684.64, 679.05, 673.58, 668.24, 663.04, + 658.0, 653.09, 648.5, 644.07, 639.75, 635.55, 631.46, 627.73}); + PTravelTimeTable.add(new double[]{703.22, 700.75, 697.76, 696.06, 690.43, 684.82, 679.33, 673.97, 668.76, + 663.7, 658.77, 654.16, 649.71, 645.37, 641.15, 637.03, 633.28}); + PTravelTimeTable.add(new double[]{708.96, 706.49, 703.49, 701.79, 696.14, 690.52, 685.01, 679.64, 674.41, + 669.33, 664.38, 659.75, 655.28, 650.92, 646.67, 642.54, 638.76}); + PTravelTimeTable.add(new double[]{714.62, 712.15, 709.15, 707.45, 701.78, 696.14, 690.62, 685.23, 679.98, + 674.88, 669.92, 665.27, 660.78, 656.4, 652.13, 647.97, 644.17}); + PTravelTimeTable.add(new double[]{720.22, 717.74, 714.74, 713.03, 707.35, 701.7, 696.16, 690.75, 685.49, + 680.37, 675.39, 670.72, 666.21, 661.81, 657.52, 653.33, 649.5}); + PTravelTimeTable.add(new double[]{725.74, 723.26, 720.25, 718.54, 712.84, 707.18, 701.62, 696.2, 690.92, + 685.79, 680.79, 676.1, 671.57, 667.14, 662.83, 658.62, 654.77}); + PTravelTimeTable.add(new double[]{731.19, 728.71, 725.69, 723.98, 718.26, 712.58, 707.02, 701.57, 696.28, + 691.13, 686.11, 681.4, 676.85, 672.4, 668.07, 663.84, 659.96}); + PTravelTimeTable.add(new double[]{736.56, 734.07, 731.05, 729.34, 723.61, 717.91, 712.33, 706.87, 701.56, + 696.39, 691.36, 686.63, 682.06, 677.59, 673.24, 668.98, 665.08}); + PTravelTimeTable.add(new double[]{741.85, 739.37, 736.34, 734.62, 728.88, 723.17, 717.57, 712.1, 706.77, + 701.58, 696.53, 691.78, 687.19, 682.71, 678.33, 674.05, 670.12}); + PTravelTimeTable.add(new double[]{747.07, 744.58, 741.56, 739.83, 734.07, 728.35, 722.73, 717.25, 711.9, + 706.7, 701.63, 696.86, 692.25, 687.74, 683.34, 679.05, 675.1}); + PTravelTimeTable.add(new double[]{752.22, 749.72, 746.69, 744.96, 739.19, 733.45, 727.82, 722.32, 716.96, + 711.74, 706.65, 701.86, 697.23, 692.71, 688.29, 683.97, 680.0}); + PTravelTimeTable.add(new double[]{757.28, 754.78, 751.75, 750.01, 744.23, 738.47, 732.83, 727.31, 721.93, + 716.7, 711.6, 706.79, 702.14, 697.6, 693.16, 688.82, 684.81}); + PTravelTimeTable.add(new double[]{762.26, 759.77, 756.72, 754.98, 749.19, 743.42, 737.76, 732.23, 726.84, + 721.59, 716.47, 711.64, 706.97, 702.39, 697.92, 693.56, 689.53}); + PTravelTimeTable.add(new double[]{767.18, 764.68, 761.63, 759.89, 754.08, 748.29, 742.62, 737.06, 731.65, + 726.37, 721.23, 716.39, 711.69, 707.11, 702.63, 698.25, 694.22}); + PTravelTimeTable.add(new double[]{771.99, 769.49, 766.43, 764.68, 758.85, 753.05, 747.36, 741.79, 736.37, + 731.09, 725.93, 721.08, 716.38, 711.79, 707.3, 702.92, 698.88}); + PTravelTimeTable.add(new double[]{776.71, 774.21, 771.15, 769.4, 763.56, 757.76, 752.06, 746.48, 741.05, + 735.76, 730.61, 725.75, 721.04, 716.44, 711.95, 707.56, 703.51}); + PTravelTimeTable.add(new double[]{781.4, 778.89, 775.83, 774.08, 768.24, 762.43, 756.72, 751.15, 745.71, + 740.41, 735.25, 730.39, 725.68, 721.08, 716.58, 712.19, 708.13}); + PTravelTimeTable.add(new double[]{786.05, 783.55, 780.49, 778.73, 772.89, 767.07, 761.37, 755.78, 750.35, + 745.05, 739.88, 735.01, 730.3, 725.69, 721.19, 716.8, 712.74}); + PTravelTimeTable.add(new double[]{790.69, 788.18, 785.12, 783.37, 777.52, 771.7, 765.99, 760.4, 754.96, + 749.66, 744.49, 739.62, 734.9, 730.3, 725.79, 721.39, 717.33}); + PTravelTimeTable.add(new double[]{795.31, 792.8, 789.74, 787.98, 782.13, 776.31, 770.6, 765.01, 759.57, + 754.26, 749.09, 744.22, 739.49, 734.88, 730.37, 725.96, 721.89}); + PTravelTimeTable.add(new double[]{799.91, 797.4, 794.34, 792.58, 786.73, 780.91, 775.19, 769.6, 764.15, + 758.84, 753.67, 748.79, 744.06, 739.44, 734.93, 730.51, 726.44}); + PTravelTimeTable.add(new double[]{804.5, 801.99, 798.93, 797.17, 791.31, 785.48, 779.76, 774.17, 768.72, + 763.4, 758.22, 753.34, 748.6, 743.98, 739.46, 735.04, 730.95}); + PTravelTimeTable.add(new double[]{809.06, 806.55, 803.49, 801.73, 795.87, 790.04, 784.31, 778.71, 773.26, + 767.94, 762.75, 757.86, 753.12, 748.49, 743.96, 739.53, 735.44}); + PTravelTimeTable.add(new double[]{813.6, 811.09, 808.02, 806.26, 800.4, 794.56, 788.83, 783.23, 777.77, + 772.44, 767.25, 762.35, 757.61, 752.97, 748.43, 744.0, 739.9}); + PTravelTimeTable.add(new double[]{818.11, 815.6, 812.53, 810.77, 804.9, 799.06, 793.33, 787.72, 782.25, + 776.92, 771.72, 766.82, 762.07, 757.42, 752.88, 748.44, 744.34}); + PTravelTimeTable.add(new double[]{822.59, 820.08, 817.01, 815.25, 809.37, 803.53, 797.79, 792.17, 786.7, + 781.37, 776.17, 771.26, 766.51, 761.87, 757.33, 752.89, 748.79}); + PTravelTimeTable.add(new double[]{827.04, 824.53, 821.46, 819.7, 813.82, 807.97, 802.23, 796.62, 791.15, + 785.81, 780.61, 775.71, 770.96, 766.31, 761.77, 757.33, 753.23}); + PTravelTimeTable.add(new double[]{831.49, 828.97, 825.91, 824.14, 818.26, 812.42, 806.68, 801.07, 795.59, + 790.26, 785.06, 780.15, 775.4, 770.76, 766.22, 761.78, 757.68}); + PTravelTimeTable.add(new double[]{835.93, 833.42, 830.35, 828.59, 822.71, 816.86, 811.13, 805.51, 800.04, + 794.71, 789.51, 784.6, 779.85, 775.2, 770.66, 766.23, 762.13}); + PTravelTimeTable.add(new double[]{840.38, 837.86, 834.8, 833.03, 827.16, 821.31, 815.57, 809.96, 804.48, + 799.15, 793.95, 789.05, 784.29, 779.65, 775.11, 770.67, 766.57}); + PTravelTimeTable.add(new double[]{844.83, 842.31, 839.24, 837.48, 831.6, 825.76, 820.02, 814.4, 808.93, 803.6, + 798.4, 793.49, 788.74, 784.09, 779.55, 775.12, 771.02}); + PTravelTimeTable.add(new double[]{849.27, 846.76, 843.69, 841.92, 836.05, 830.2, 824.46, 818.85, 813.38, + 808.04, 802.84, 797.94, 793.18, 788.54, 784.0, 779.56, 775.46}); + PTravelTimeTable.add(new double[]{853.72, 851.2, 848.14, 846.37, 840.49, 834.65, 828.91, 823.29, 817.82, + 812.49, 807.29, 802.38, 797.63, 792.99, 788.45, 784.01, 779.91}); + PTravelTimeTable.add(new double[]{858.16, 855.65, 852.58, 850.82, 844.94, 839.09, 833.35, 827.74, 822.27, + 816.93, 811.73, 806.83, 802.08, 797.43, 792.89, 788.45, 784.35}); + PTravelTimeTable.add(new double[]{862.61, 860.09, 857.03, 855.26, 849.38, 843.54, 837.8, 832.18, 826.71, + 821.38, 816.18, 811.27, 806.52, 801.88, 797.34, 792.9, 788.8}); + PTravelTimeTable.add(new double[]{867.05, 864.54, 861.47, 859.71, 853.83, 847.98, 842.24, 836.63, 831.16, + 825.83, 820.63, 815.72, 810.97, 806.32, 801.78, 797.35, 793.25}); + PTravelTimeTable.add(new double[]{871.5, 868.98, 865.92, 864.15, 858.28, 852.43, 846.69, 841.08, 835.6, + 830.27, 825.07, 820.17, 815.41, 810.77, 806.23, 801.79, 797.69}); + PTravelTimeTable.add(new double[]{875.95, 873.43, 870.36, 868.6, 862.72, 856.87, 851.14, 845.52, 840.05, + 834.72, 829.52, 824.61, 819.86, 815.21, 810.67, 806.24, 802.14}); + PTravelTimeTable.add(new double[]{880.39, 877.88, 874.81, 873.04, 867.17, 861.32, 855.58, 849.97, 844.5, + 839.16, 833.96, 829.06, 824.3, 819.66, 815.12, 810.68, 806.58}); + PTravelTimeTable.add(new double[]{884.84, 882.32, 879.25, 877.49, 871.61, 865.77, 860.03, 854.41, 848.94, + 843.61, 838.41, 833.5, 828.75, 824.11, 819.57, 815.13, 811.03}); + PTravelTimeTable.add(new double[]{889.28, 886.77, 883.7, 881.94, 876.06, 870.21, 864.47, 858.86, 853.39, + 848.05, 842.85, 837.95, 833.2, 828.55, 824.01, 819.57, 815.47}); + PTravelTimeTable.add(new double[]{893.73, 891.21, 888.15, 886.38, 880.5, 874.66, 868.92, 863.3, 857.83, 852.5, + 847.3, 842.39, 837.64, 833.0, 828.46, 824.02, 819.92}); + PTravelTimeTable.add(new double[]{898.17, 895.66, 892.59, 890.83, 884.95, 879.1, 873.36, 867.75, 862.28, + 856.94, 851.75, 846.84, 842.09, 837.44, 832.9, 828.47, 824.36}); + PTravelTimeTable.add(new double[]{902.62, 900.1, 897.04, 895.27, 889.4, 883.55, 877.81, 872.2, 866.72, 861.39, + 856.19, 851.29, 846.53, 841.89, 837.35, 832.91, 828.81}); + PTravelTimeTable.add(new double[]{907.06, 904.55, 901.48, 899.72, 893.84, 887.99, 882.26, 876.64, 871.17, + 865.84, 860.64, 855.73, 850.98, 846.33, 841.79, 837.36, 833.26}); + PTravelTimeTable.add(new double[]{911.51, 908.99, 905.93, 904.16, 898.29, 892.44, 886.7, 881.09, 875.62, + 870.28, 865.08, 860.18, 855.42, 850.78, 846.24, 841.8, 837.7}); + PTravelTimeTable.add(new double[]{915.96, 913.44, 910.37, 908.61, 902.73, 896.89, 891.15, 885.53, 880.06, + 874.73, 869.53, 864.62, 859.87, 855.22, 850.68, 846.25, 842.15}); + PTravelTimeTable.add(new double[]{920.4, 917.89, 914.82, 913.05, 907.18, 901.33, 895.59, 889.98, 884.51, + 879.17, 873.97, 869.07, 864.32, 859.67, 855.13, 850.69, 846.59}); + PTravelTimeTable.add(new double[]{924.85, 922.33, 919.27, 917.5, 911.62, 905.78, 900.04, 894.42, 888.95, + 883.62, 878.42, 873.51, 868.76, 864.12, 859.58, 855.14, 851.04}); + PTravelTimeTable.add(new double[]{929.29, 926.78, 923.71, 921.95, 916.07, 910.22, 904.48, 898.87, 893.4, + 888.06, 882.86, 877.96, 873.21, 868.56, 864.02, 859.59, 855.48}); + PTravelTimeTable.add(new double[]{933.74, 931.22, 928.16, 926.39, 920.52, 914.67, 908.93, 903.32, 897.84, + 892.51, 887.31, 882.41, 877.65, 873.01, 868.47, 864.03, 859.93}); + PTravelTimeTable.add(new double[]{938.18, 935.67, 932.6, 930.84, 924.96, 919.11, 913.38, 907.76, 902.29, + 896.96, 891.76, 886.85, 882.1, 877.45, 872.91, 868.48, 864.38}); + + STravelTimeTable.add(new double[]{0.0, 4.34, 9.68, 13.02, 24.16, 35.27, 46.35, 57.34, 68.13, 78.72, 89.12, + 98.99000000000001, 108.57, 117.96000000000001, 127.17, 136.2, 144.64}); + STravelTimeTable.add(new double[]{32.14, 31.98, 30.38, 30.74, 35.74, 43.61, 52.78, 62.52, 72.42, 82.37, + 92.27000000000001, 101.74000000000001, 111.0, 120.13, 129.12, 137.97, 146.25}); + STravelTimeTable.add(new double[]{60.75, 57.98, 55.06, 55.14, 57.38, 62.05, 68.43, 75.89, 83.96000000000001, + 92.41, 101.11, 109.53999999999999, 117.94, 126.35, 134.74, 143.07, 150.88}); + STravelTimeTable.add(new double[]{85.43, 82.66, 79.73, 79.72, 80.94, 83.92, 88.39, 93.95, 100.21000000000001, + 107.03, 114.28999999999999, 121.4, 128.65, 136.07999999999998, 143.6, 151.17000000000002, 158.28}); + STravelTimeTable.add(new double[]{110.1, 107.33, 104.4, 104.33, 104.99000000000001, 107.0, 110.24000000000001, + 114.4, 119.19, 124.57, 130.46, 136.21, 142.24, 148.56, 155.1, 161.8, 168.05}); + STravelTimeTable.add(new double[]{134.76, 131.99, 129.06, 128.93, 129.22, 130.59, 132.98, 136.12, 139.74, + 143.91, 148.59, 153.06, 157.89, 163.12, 168.65, 174.42000000000002, 179.76}); + STravelTimeTable.add(new double[]{159.41, 156.63, 153.7, 153.52, 153.53, 154.43, 156.2, 158.54, 161.21, + 164.36, 168.01, 171.27, 174.99, 179.18, 183.74, 188.6, 192.98}); + STravelTimeTable.add(new double[]{184.04, 181.26, 178.32, 178.1, 177.87, 178.4, 179.69, 181.38, 183.24, + 185.52, 188.26, 190.37, 193.06, 196.3, 199.96, 203.96, 207.36}); + STravelTimeTable.add(new double[]{208.65, 205.87, 202.92000000000002, 202.66, 202.21, 202.44, 203.34, 204.45, + 205.6, 207.12, 209.06, 210.0, 211.78, 214.16, 216.98, 220.17000000000002, 222.57999999999998}); + STravelTimeTable.add(new double[]{233.24, 230.45, 227.5, 227.19, 226.56, 226.52, 227.07999999999998, + 227.67000000000002, 228.15, 228.97, 230.2, 229.89, 230.9, 232.5, 234.56, 237.01, 238.37}); + STravelTimeTable.add(new double[]{257.8, 255.01, 252.05, 251.7, 250.88, 250.61, 250.89, 250.93, 250.79, + 250.97, 250.84, 249.89, 250.23, 251.14, 252.52, 254.28, 254.5}); + STravelTimeTable.add(new double[]{282.33, 279.53, 276.56, 276.17, 275.19, 274.71, 274.72, 274.15999999999997, + 273.43, 273.02, 271.23, 269.88, 269.65, 269.96, 270.71, 271.52, 270.78}); + STravelTimeTable.add(new double[]{306.83, 304.02, 301.04, 300.61, 299.47, 298.79, 298.57, 297.3, 295.99, + 295.05, 291.53, 289.82, 289.09000000000003, 288.84000000000003, 289.03, 288.19, 287.11}); + STravelTimeTable.add(new double[]{331.29, 328.47, 325.48, 325.01, 323.72, 322.86, 322.36, 320.27, 318.45, + 315.58, 311.72, 309.67, 308.47, 307.73, 307.39, 304.79, 303.4}); + STravelTimeTable.add(new double[]{355.7, 352.89, 349.88, 349.37, 347.93, 346.9, 345.65999999999997, 343.04, + 340.3, 335.79, 331.77, 329.38, 327.76, 326.56, 325.01, 321.32, 319.64}); + STravelTimeTable.add(new double[]{380.08, 377.25, 374.24, 373.69, 372.11, 370.91, 368.66, 365.58, 360.52, + 355.87, 351.65999999999997, 348.94, 346.90999999999997, 345.29, 341.55, 337.75, 335.81}); + STravelTimeTable.add(new double[]{404.40999999999997, 401.57, 398.55, 397.96, 396.25, 394.82, 391.36, 385.83, + 380.59, 375.77, 371.36, 368.31, 365.91, 362.32, 357.99, 354.06, 351.89}); + STravelTimeTable.add(new double[]{428.69, 425.85, 422.81, 422.18, 420.34, 417.65999999999997, 411.68, 405.87, + 400.48, 395.47, 390.84, 387.48, 383.6, 378.75, 374.3, 370.26, 367.81}); + STravelTimeTable.add(new double[]{452.92, 450.07, 447.02, 446.36, 444.01, 437.81, 431.68, 425.73, 420.15, + 414.95, 410.09000000000003, 405.33, 400.0, 395.05, 390.5, 386.32, 383.62}); + STravelTimeTable.add(new double[]{477.1, 474.24, 471.17, 470.47, 464.07, 457.75, 451.47, 445.35, 439.59, + 434.18, 427.64, 421.7, 416.28, 411.24, 406.56, 402.18, 399.4}); + STravelTimeTable.add(new double[]{499.77, 496.38, 492.44, 490.47, 483.94, 477.46, 471.02, 464.72, 458.06, + 450.85, 443.96, 437.94, 432.43, 427.26, 422.4, 417.98, 415.15}); + STravelTimeTable.add(new double[]{519.66, 516.24, 512.27, 510.25, 503.57, 496.92, 489.91, 481.99, 474.39, + 467.11, 460.15, 454.05, 448.39, 443.08, 438.19, 433.74, 430.88}); + STravelTimeTable.add(new double[]{539.3, 535.85, 531.83, 529.77, 522.56, 514.36, 506.22, 498.25, 490.59, + 483.24, 476.18, 469.93, 464.2, 458.87, 453.95, 449.48, 446.58}); + STravelTimeTable.add(new double[]{557.88, 554.15, 549.7, 547.19, 538.86, 530.6, 522.41, 514.37, 506.62, + 499.15, 492.0, 485.73, 479.97, 474.62, 469.69, 465.19, 462.24}); + STravelTimeTable.add(new double[]{574.14, 570.4, 565.93, 563.4, 555.02, 546.7, 538.41, 530.26, 522.44, 514.95, + 507.78, 501.49, 495.72, 490.35, 485.4, 480.88, 477.87}); + STravelTimeTable.add(new double[]{590.26, 586.5, 582.01, 579.46, 570.97, 562.56, 554.22, 546.06, 538.22, + 530.71, 523.54, 517.23, 511.44, 506.05, 501.08, 496.52, 493.44}); + STravelTimeTable.add(new double[]{606.14, 602.37, 597.85, 595.29, 586.78, 578.35, 570.0, 561.82, 553.97, + 546.46, 539.27, 532.94, 527.13, 521.72, 516.71, 512.11, 508.96}); + STravelTimeTable.add(new double[]{621.93, 618.16, 613.64, 611.07, 602.55, 594.11, 585.75, 577.56, 569.7, + 562.17, 554.97, 548.62, 542.79, 537.35, 532.29, 527.64, 524.41}); + STravelTimeTable.add(new double[]{637.69, 633.92, 629.4, 626.82, 618.29, 609.84, 601.47, 593.27, 585.4, + 577.85, 570.63, 564.26, 558.4, 552.91, 547.81, 543.11, 539.79}); + STravelTimeTable.add(new double[]{653.43, 649.65, 645.13, 642.55, 634.01, 625.55, 617.17, 608.95, 601.06, + 593.5, 586.25, 579.85, 573.95, 568.42, 563.27, 558.5, 555.1}); + STravelTimeTable.add(new double[]{669.14, 665.36, 660.83, 658.25, 649.7, 641.22, 632.82, 624.59, 616.68, + 609.09, 601.81, 595.37, 589.43, 583.85, 578.65, 573.82, 570.33}); + STravelTimeTable.add(new double[]{684.81, 681.03, 676.5, 673.91, 665.34, 656.85, 648.43, 640.18, 632.24, + 624.61, 617.3, 610.83, 604.84, 599.21, 593.95, 589.07, 585.49}); + STravelTimeTable.add(new double[]{700.45, 696.66, 692.12, 689.53, 680.94, 672.42, 663.98, 655.7, 647.73, + 640.07, 632.72, 626.21, 620.17, 614.5, 609.18, 604.24, 600.58}); + STravelTimeTable.add(new double[]{716.02, 712.23, 707.69, 705.09, 696.47, 687.93, 679.46, 671.14, 663.14, + 655.45, 648.07, 641.51, 635.43, 629.7, 624.33, 619.33, 615.58}); + STravelTimeTable.add(new double[]{731.53, 727.73, 723.18, 720.58, 711.93, 703.36, 694.86, 686.52, 678.48, + 670.76, 663.34, 656.73, 650.6, 644.83, 639.4, 634.33, 630.5}); + STravelTimeTable.add(new double[]{746.97, 743.16, 738.6, 735.99, 727.32, 718.72, 710.18, 701.81, 693.74, + 685.98, 678.52, 671.88, 665.7, 659.87, 654.38, 649.25, 645.33}); + STravelTimeTable.add(new double[]{762.32, 758.51, 753.95, 751.32, 742.62, 733.99, 725.43, 717.02, 708.92, + 701.12, 693.63, 686.93, 680.7, 674.82, 669.28, 664.08, 660.08}); + STravelTimeTable.add(new double[]{777.6, 773.79, 769.21, 766.58, 757.85, 749.19, 740.59, 732.15, 724.01, + 716.18, 708.64, 701.9, 695.62, 689.68, 684.09, 678.83, 674.74}); + STravelTimeTable.add(new double[]{792.8, 788.98, 784.39, 781.75, 772.99, 764.3, 755.67, 747.19, 739.02, + 731.14, 723.57, 716.78, 710.45, 704.46, 698.8, 693.48, 689.31}); + STravelTimeTable.add(new double[]{807.91, 804.08, 799.48, 796.83, 788.04, 779.32, 770.65, 762.14, 753.93, + 746.02, 738.4, 731.57, 725.19, 719.14, 713.42, 708.04, 703.79}); + STravelTimeTable.add(new double[]{822.93, 819.09, 814.49, 811.83, 803.0, 794.24, 785.55, 777.0, 768.75, 760.8, + 753.14, 746.26, 739.83, 733.73, 727.95, 722.51, 718.18}); + STravelTimeTable.add(new double[]{837.86, 834.01, 829.4, 826.73, 817.87, 809.08, 800.35, 791.77, 783.48, + 775.49, 767.79, 760.86, 754.38, 748.22, 742.39, 736.88, 732.47}); + STravelTimeTable.add(new double[]{852.69, 848.84, 844.21, 841.53, 832.64, 823.82, 815.05, 806.44, 798.11, + 790.08, 782.34, 775.36, 768.83, 762.62, 756.73, 751.15, 746.66}); + STravelTimeTable.add(new double[]{867.42, 863.57, 858.93, 856.24, 847.32, 838.46, 829.66, 821.01, 812.65, + 804.57, 796.79, 789.77, 783.18, 776.92, 770.97, 765.33, 760.76}); + STravelTimeTable.add(new double[]{882.06, 878.2, 873.56, 870.86, 861.9, 853.0, 844.17, 835.48, 827.08, 818.97, + 811.14, 804.07, 797.43, 791.11, 785.1, 779.41, 774.76}); + STravelTimeTable.add(new double[]{896.6, 892.73, 888.08, 885.37, 876.38, 867.45, 858.58, 849.85, 841.41, + 833.26, 825.39, 818.27, 811.58, 805.21, 799.14, 793.38, 788.66}); + STravelTimeTable.add(new double[]{911.04, 907.16, 902.5, 899.78, 890.75, 881.79, 872.88, 864.12, 855.64, + 847.45, 839.54, 832.37, 825.63, 819.2, 813.08, 807.26, 802.46}); + STravelTimeTable.add(new double[]{925.37, 921.49, 916.81, 914.08, 905.02, 896.02, 887.08, 878.28, 869.77, + 861.53, 853.58, 846.37, 839.58, 833.09, 826.91, 821.03, 816.16}); + STravelTimeTable.add(new double[]{939.6, 935.71, 931.02, 928.28, 919.19, 910.15, 901.18, 892.34, 883.79, + 875.51, 867.52, 860.26, 853.42, 846.88, 840.64, 834.7, 829.76}); + STravelTimeTable.add(new double[]{953.72, 949.82, 945.13, 942.38, 933.25, 924.18, 915.17, 906.29, 897.7, + 889.39, 881.35, 874.04, 867.15, 860.56, 854.27, 848.27, 843.27}); + STravelTimeTable.add(new double[]{967.73, 963.83, 959.12, 956.36, 947.2, 938.09, 929.05, 920.14, 911.51, + 903.15, 895.07, 887.72, 880.78, 874.14, 867.8, 861.75, 856.67}); + STravelTimeTable.add(new double[]{981.64, 977.73, 973.01, 970.24, 961.04, 951.9, 942.82, 933.87, 925.2, + 916.81, 908.69, 901.3, 894.31, 887.62, 881.23, 875.12, 869.98}); + STravelTimeTable.add(new double[]{995.43, 991.52, 986.79, 984.01, 974.77, 965.6, 956.48, 947.5, 938.8, 930.37, + 922.21, 914.77, 907.74, 901.0, 894.55, 888.39, 883.18}); + STravelTimeTable.add(new double[]{1009.12, 1005.19, 1000.45, 997.66, 988.4, 979.19, 970.04, 961.03, 952.29, + 943.82, 935.63, 928.14, 921.06, 914.28, 907.77, 901.56, 896.28}); + STravelTimeTable.add(new double[]{1022.7, 1018.77, 1014.02, 1011.22, 1001.92, 992.68, 983.5, 974.45, 965.68, + 957.17, 948.93, 941.41, 934.28, 927.44, 920.89, 914.62, 909.27}); + STravelTimeTable.add(new double[]{1036.17, 1032.23, 1027.47, 1024.67, 1015.34, 1006.07, 996.85, 987.77, + 978.96, 970.41, 962.13, 954.56, 947.39, 940.5, 933.9, 927.57, 922.17}); + STravelTimeTable.add(new double[]{1049.54, 1045.59, 1040.82, 1038.0, 1028.65, 1019.34, 1010.09, 1000.97, + 992.12, 983.54, 975.23, 967.61, 960.39, 953.46, 946.8, 940.42, 934.96}); + STravelTimeTable.add(new double[]{1062.79, 1058.84, 1054.06, 1051.23, 1041.84, 1032.5, 1023.22, 1014.07, + 1005.18, 996.56, 988.21, 980.55, 973.29, 966.31, 959.6, 953.17, 947.64}); + STravelTimeTable.add(new double[]{1075.94, 1071.98, 1067.19, 1064.35, 1054.93, 1045.56, 1036.24, 1027.05, + 1018.13, 1009.48, 1001.08, 993.39, 986.08, 979.05, 972.3, 965.81, 960.22}); + STravelTimeTable.add(new double[]{1088.97, 1085.0, 1080.2, 1077.35, 1067.9, 1058.5, 1049.15, 1039.93, 1030.97, + 1022.28, 1013.85, 1006.11, 998.76, 991.68, 984.88, 978.35, 972.69}); + STravelTimeTable.add(new double[]{1101.89, 1097.91, 1093.11, 1090.25, 1080.76, 1071.33, 1061.95, 1052.69, + 1043.71, 1034.98, 1026.51, 1018.73, 1011.33, 1004.21, 997.36, 990.77, 985.06}); + STravelTimeTable.add(new double[]{1114.7, 1110.72, 1105.9, 1103.03, 1093.52, 1084.05, 1074.64, 1065.35, + 1056.33, 1047.57, 1039.06, 1031.24, 1023.8, 1016.63, 1009.73, 1003.09, 997.33}); + STravelTimeTable.add(new double[]{1127.39, 1123.41, 1118.58, 1115.71, 1106.16, 1096.66, 1087.21, 1077.89, + 1068.84, 1060.04, 1051.5, 1043.63, 1036.15, 1028.94, 1021.99, 1015.31, 1009.48}); + STravelTimeTable.add(new double[]{1139.98, 1135.99, 1131.15, 1128.26, 1118.68, 1109.16, 1099.68, 1090.33, + 1081.24, 1072.4, 1063.82, 1055.92, 1048.39, 1041.14, 1034.15, 1027.41, 1021.53}); + STravelTimeTable.add(new double[]{1152.45, 1148.45, 1143.6, 1140.71, 1131.1, 1121.54, 1112.03, 1102.65, + 1093.52, 1084.66, 1076.04, 1068.1, 1060.53, 1053.23, 1046.19, 1039.41, 1033.48}); + STravelTimeTable.add(new double[]{1164.8, 1160.8, 1155.94, 1153.04, 1143.4, 1133.81, 1124.27, 1114.86, 1105.7, + 1096.8, 1088.15, 1080.17, 1072.56, 1065.22, 1058.13, 1051.3, 1045.31}); + STravelTimeTable.add(new double[]{1177.05, 1173.04, 1168.17, 1165.26, 1155.59, 1145.97, 1136.4, 1126.95, + 1117.77, 1108.83, 1100.14, 1092.12, 1084.47, 1077.09, 1069.96, 1063.09, 1057.04}); + STravelTimeTable.add(new double[]{1189.18, 1185.16, 1180.28, 1177.36, 1167.67, 1158.02, 1148.42, 1138.94, + 1129.72, 1120.75, 1112.03, 1103.97, 1096.28, 1088.85, 1081.68, 1074.76, 1068.66}); + STravelTimeTable.add(new double[]{1201.19, 1197.17, 1192.29, 1189.36, 1179.63, 1169.95, 1160.32, 1150.81, + 1141.56, 1132.56, 1123.8, 1115.71, 1107.98, 1100.51, 1093.29, 1086.33, 1080.18}); + STravelTimeTable.add(new double[]{1213.09, 1209.07, 1204.17, 1201.23, 1191.48, 1181.77, 1172.11, 1162.57, + 1153.29, 1144.25, 1135.46, 1127.33, 1119.56, 1112.05, 1104.79, 1097.78, 1091.58}); + STravelTimeTable.add(new double[]{1224.88, 1220.85, 1215.94, 1213.0, 1203.21, 1193.48, 1183.79, 1174.22, + 1164.9, 1155.84, 1147.01, 1138.84, 1131.03, 1123.48, 1116.18, 1109.12, 1102.86}); + STravelTimeTable.add(new double[]{1236.55, 1232.51, 1227.6, 1224.65, 1214.83, 1205.07, 1195.35, 1185.75, + 1176.4, 1167.3, 1158.44, 1150.24, 1142.39, 1134.79, 1127.45, 1120.35, 1114.04}); + STravelTimeTable.add(new double[]{1248.11, 1244.06, 1239.14, 1236.18, 1226.34, 1216.54, 1206.8, 1197.17, + 1187.79, 1178.65, 1169.76, 1161.52, 1153.63, 1145.99, 1138.61, 1131.46, 1125.11}); + STravelTimeTable.add(new double[]{1259.55, 1255.49, 1250.57, 1247.59, 1237.73, 1227.9, 1218.12, 1208.46, + 1199.05, 1189.89, 1180.96, 1172.68, 1164.76, 1157.08, 1149.65, 1142.46, 1136.06}); + STravelTimeTable.add(new double[]{1270.87, 1266.81, 1261.87, 1258.89, 1248.99, 1239.14, 1229.33, 1219.64, + 1210.2, 1201.01, 1192.05, 1183.73, 1175.77, 1168.06, 1160.59, 1153.35, 1146.9}); + STravelTimeTable.add(new double[]{1282.07, 1278.0, 1273.05, 1270.07, 1260.14, 1250.26, 1240.42, 1230.71, + 1221.24, 1212.01, 1203.02, 1194.67, 1186.67, 1178.92, 1171.4, 1164.13, 1157.63}); + STravelTimeTable.add(new double[]{1293.15, 1289.08, 1284.12, 1281.12, 1271.17, 1261.27, 1251.4, 1241.66, + 1232.16, 1222.9, 1213.87, 1205.49, 1197.45, 1189.66, 1182.11, 1174.79, 1168.25}); + STravelTimeTable.add(new double[]{1304.11, 1300.03, 1295.07, 1292.07, 1282.09, 1272.15, 1262.26, 1252.49, + 1242.96, 1233.67, 1224.61, 1216.19, 1208.11, 1200.29, 1192.7, 1185.34, 1178.75}); + STravelTimeTable.add(new double[]{1314.95, 1310.87, 1305.9, 1302.89, 1292.88, 1282.92, 1273.0, 1263.2, + 1253.64, 1244.32, 1235.23, 1226.78, 1218.67, 1210.8, 1203.17, 1195.78, 1189.14}); + STravelTimeTable.add(new double[]{1325.68, 1321.59, 1316.61, 1313.59, 1303.55, 1293.57, 1283.62, 1273.79, + 1264.2, 1254.85, 1245.74, 1237.25, 1229.1, 1221.2, 1213.53, 1206.09, 1199.41}); + STravelTimeTable.add(new double[]{1336.28, 1332.19, 1327.2, 1324.17, 1314.11, 1304.1, 1294.12, 1284.27, + 1274.65, 1265.27, 1256.12, 1247.6, 1239.42, 1231.48, 1223.77, 1216.29, 1209.56}); + STravelTimeTable.add(new double[]{1346.77, 1342.67, 1337.67, 1334.63, 1324.55, 1314.51, 1304.51, 1294.62, + 1284.98, 1275.57, 1266.39, 1257.83, 1249.61, 1241.63, 1233.88, 1226.37, 1219.59}); + STravelTimeTable.add(new double[]{1357.13, 1353.02, 1348.02, 1344.97, 1334.86, 1324.79, 1314.76, 1304.85, + 1295.18, 1285.74, 1276.52, 1267.93, 1259.68, 1251.67, 1243.88, 1236.32, 1229.5}); + STravelTimeTable.add(new double[]{1367.36, 1363.25, 1358.23, 1355.19, 1345.05, 1334.95, 1324.9, 1314.96, + 1305.25, 1295.78, 1286.54, 1277.92, 1269.63, 1261.58, 1253.76, 1246.16, 1239.3}); + STravelTimeTable.add(new double[]{1377.47, 1373.35, 1368.33, 1365.27, 1355.11, 1344.99, 1334.91, 1324.94, + 1315.21, 1305.71, 1296.44, 1287.78, 1279.46, 1271.37, 1263.52, 1255.88, 1248.97}); + STravelTimeTable.add(new double[]{1387.45, 1383.33, 1378.3, 1375.23, 1365.05, 1354.9, 1344.79, 1334.8, + 1325.04, 1315.51, 1306.21, 1297.52, 1289.16, 1281.04, 1273.15, 1265.47, 1258.52}); + STravelTimeTable.add(new double[]{1397.31, 1393.18, 1388.14, 1385.07, 1374.86, 1364.69, 1354.55, 1344.53, + 1334.74, 1325.19, 1315.86, 1307.13, 1298.74, 1290.59, 1282.65, 1274.94, 1267.94}); + STravelTimeTable.add(new double[]{1407.04, 1402.91, 1397.86, 1394.78, 1384.54, 1374.34, 1364.18, 1354.14, + 1344.32, 1334.74, 1325.37, 1316.62, 1308.19, 1300.0, 1292.03, 1284.28, 1277.24}); + STravelTimeTable.add(new double[]{1416.64, 1412.5, 1407.45, 1404.36, 1394.1, 1383.87, 1373.69, 1363.61, + 1353.77, 1344.15, 1334.76, 1325.97, 1317.52, 1309.29, 1301.28, 1293.49, 1286.41}); + STravelTimeTable.add(new double[]{1426.11, 1421.97, 1416.9, 1413.81, 1403.52, 1393.27, 1383.05, 1372.95, + 1363.08, 1353.44, 1344.02, 1335.2, 1326.71, 1318.44, 1310.4, 1302.57, 1295.45}); + STravelTimeTable.add(new double[]{1435.44, 1431.29, 1426.22, 1423.12, 1412.8, 1402.53, 1392.29, 1382.16, + 1372.26, 1362.59, 1353.14, 1344.29, 1335.77, 1327.47, 1319.39, 1311.53, 1304.36}); + STravelTimeTable.add(new double[]{1444.64, 1440.49, 1435.41, 1432.3, 1421.96, 1411.66, 1401.39, 1391.24, + 1381.31, 1371.62, 1362.14, 1353.25, 1344.7, 1336.37, 1328.25, 1320.35, 1313.16}); + STravelTimeTable.add(new double[]{1453.71, 1449.55, 1444.46, 1441.34, 1430.98, 1420.65, 1410.36, 1400.18, + 1390.23, 1380.51, 1371.0, 1362.09, 1353.5, 1345.14, 1337.01, 1329.09, 1321.88}); + STravelTimeTable.add(new double[]{1462.63, 1458.47, 1453.37, 1450.25, 1439.86, 1429.51, 1419.2, 1409.0, + 1399.02, 1389.28, 1379.75, 1370.83, 1362.23, 1353.86, 1345.71, 1337.78, 1330.56}); + STravelTimeTable.add(new double[]{1471.43, 1467.26, 1462.16, 1459.03, 1448.63, 1438.27, 1427.94, 1417.73, + 1407.74, 1397.99, 1388.46, 1379.52, 1370.91, 1362.53, 1354.37, 1346.42, 1339.18}); + STravelTimeTable.add(new double[]{1480.16, 1475.98, 1470.88, 1467.75, 1457.34, 1446.97, 1436.63, 1426.41, + 1416.42, 1406.65, 1397.11, 1388.16, 1379.54, 1371.14, 1362.96, 1355.0, 1347.73}); + STravelTimeTable.add(new double[]{1488.83, 1484.66, 1479.55, 1476.42, 1466.0, 1455.62, 1445.27, 1435.04, + 1425.04, 1415.26, 1405.7, 1396.73, 1388.09, 1379.68, 1371.48, 1363.49, 1356.2}); + STravelTimeTable.add(new double[]{1497.46, 1493.28, 1488.17, 1485.03, 1474.6, 1464.2, 1453.85, 1443.6, + 1433.58, 1423.79, 1414.21, 1405.23, 1396.57, 1388.14, 1379.92, 1371.91, 1364.6}); + STravelTimeTable.add(new double[]{1506.0, 1501.82, 1496.71, 1493.57, 1483.12, 1472.71, 1462.34, 1452.08, + 1442.05, 1432.24, 1422.65, 1413.65, 1404.97, 1396.51, 1388.28, 1380.26, 1372.94}); + STravelTimeTable.add(new double[]{1514.47, 1510.29, 1505.17, 1502.02, 1491.56, 1481.14, 1470.76, 1460.48, + 1450.43, 1440.61, 1431.01, 1422.0, 1413.31, 1404.86, 1396.62, 1388.6, 1381.28}); + STravelTimeTable.add(new double[]{1522.86, 1518.67, 1513.55, 1510.4, 1499.93, 1489.5, 1479.1, 1468.82, + 1458.77, 1448.95, 1439.35, 1430.34, 1421.65, 1413.2, 1404.96, 1396.94, 1389.62}); + STravelTimeTable.add(new double[]{1531.2, 1527.01, 1521.89, 1518.74, 1508.27, 1497.84, 1487.45, 1477.16, + 1467.11, 1457.29, 1447.69, 1438.68, 1429.99, 1421.54, 1413.3, 1405.28, 1397.96}); + STravelTimeTable.add(new double[]{1539.54, 1535.35, 1530.23, 1527.08, 1516.61, 1506.18, 1495.79, 1485.51, + 1475.45, 1465.63, 1456.03, 1447.02, 1438.33, 1429.88, 1421.64, 1413.62, 1406.3}); + STravelTimeTable.add(new double[]{1547.88, 1543.69, 1538.57, 1535.42, 1524.95, 1514.52, 1504.13, 1493.85, + 1483.8, 1473.97, 1464.37, 1455.36, 1446.67, 1438.22, 1429.98, 1421.96, 1414.64}); + STravelTimeTable.add(new double[]{1556.22, 1552.03, 1546.91, 1543.76, 1533.29, 1522.86, 1512.47, 1502.19, + 1492.14, 1482.31, 1472.71, 1463.7, 1455.01, 1446.56, 1438.32, 1430.31, 1422.98}); + STravelTimeTable.add(new double[]{1564.56, 1560.37, 1555.25, 1552.1, 1541.63, 1531.2, 1520.81, 1510.53, + 1500.48, 1490.65, 1481.05, 1472.04, 1463.36, 1454.9, 1446.66, 1438.65, 1431.32}); + STravelTimeTable.add(new double[]{1572.9, 1568.71, 1563.59, 1560.44, 1549.97, 1539.54, 1529.15, 1518.87, + 1508.82, 1498.99, 1489.39, 1480.38, 1471.7, 1463.24, 1455.0, 1446.99, 1439.66}); + STravelTimeTable.add(new double[]{1581.24, 1577.05, 1571.93, 1568.78, 1558.31, 1547.88, 1537.49, 1527.21, + 1517.16, 1507.33, 1497.73, 1488.72, 1480.04, 1471.58, 1463.35, 1455.33, 1448.01}); + STravelTimeTable.add(new double[]{1589.58, 1585.39, 1580.27, 1577.12, 1566.65, 1556.22, 1545.83, 1535.55, + 1525.5, 1515.67, 1506.07, 1497.06, 1488.38, 1479.92, 1471.69, 1463.67, 1456.35}); + STravelTimeTable.add(new double[]{1597.92, 1593.74, 1588.61, 1585.46, 1574.99, 1564.56, 1554.17, 1543.89, + 1533.84, 1524.02, 1514.41, 1505.4, 1496.72, 1488.26, 1480.03, 1472.01, 1464.69}); + STravelTimeTable.add(new double[]{1606.26, 1602.08, 1596.95, 1593.8, 1583.33, 1572.9, 1562.51, 1552.23, + 1542.18, 1532.36, 1522.75, 1513.74, 1505.06, 1496.6, 1488.37, 1480.35, 1473.03}); + STravelTimeTable.add(new double[]{1614.6, 1610.42, 1605.29, 1602.14, 1591.67, 1581.24, 1570.85, 1560.57, + 1550.52, 1540.7, 1531.09, 1522.08, 1513.4, 1504.94, 1496.71, 1488.69, 1481.37}); + STravelTimeTable.add(new double[]{1622.94, 1618.76, 1613.63, 1610.48, 1600.01, 1589.58, 1579.19, 1568.91, + 1558.86, 1549.04, 1539.43, 1530.42, 1521.74, 1513.28, 1505.05, 1497.03, 1489.71}); + STravelTimeTable.add(new double[]{1631.28, 1627.1, 1621.97, 1618.82, 1608.35, 1597.92, 1587.53, 1577.25, + 1567.2, 1557.38, 1547.77, 1538.76, 1530.08, 1521.62, 1513.39, 1505.37, 1498.05}); + STravelTimeTable.add(new double[]{1639.62, 1635.44, 1630.31, 1627.16, 1616.69, 1606.26, 1595.87, 1585.59, + 1575.54, 1565.72, 1556.11, 1547.1, 1538.42, 1529.96, 1521.73, 1513.71, 1506.39}); + STravelTimeTable.add(new double[]{1647.97, 1643.78, 1638.65, 1635.51, 1625.03, 1614.61, 1604.21, 1593.93, + 1583.88, 1574.06, 1564.46, 1555.45, 1546.76, 1538.31, 1530.07, 1522.05, 1514.73}); + STravelTimeTable.add(new double[]{1656.31, 1652.12, 1647.0, 1643.85, 1633.38, 1622.95, 1612.55, 1602.27, + 1592.22, 1582.4, 1572.8, 1563.79, 1555.1, 1546.65, 1538.41, 1530.39, 1523.07}); + STravelTimeTable.add(new double[]{1664.65, 1660.46, 1655.34, 1652.19, 1641.72, 1631.29, 1620.89, 1610.61, + 1600.56, 1590.74, 1581.14, 1572.13, 1563.44, 1554.99, 1546.75, 1538.73, 1531.41}); + STravelTimeTable.add(new double[]{1672.99, 1668.8, 1663.68, 1660.53, 1650.06, 1639.63, 1629.24, 1618.95, + 1608.9, 1599.08, 1589.48, 1580.47, 1571.78, 1563.33, 1555.09, 1547.07, 1539.75}); + STravelTimeTable.add(new double[]{1681.33, 1677.14, 1672.02, 1668.87, 1658.4, 1647.97, 1637.58, 1627.3, + 1617.25, 1607.42, 1597.82, 1588.81, 1580.12, 1571.67, 1563.43, 1555.41, 1548.09}); + STravelTimeTable.add(new double[]{1689.67, 1685.48, 1680.36, 1677.21, 1666.74, 1656.31, 1645.92, 1635.64, + 1625.59, 1615.76, 1606.16, 1597.15, 1588.46, 1580.01, 1571.77, 1563.75, 1556.43}); + STravelTimeTable.add(new double[]{1698.01, 1693.82, 1688.7, 1685.55, 1675.08, 1664.65, 1654.26, 1643.98, + 1633.93, 1624.1, 1614.5, 1605.49, 1596.8, 1588.35, 1580.11, 1572.1, 1564.77}); + STravelTimeTable.add(new double[]{1706.35, 1702.16, 1697.04, 1693.89, 1683.42, 1672.99, 1662.6, 1652.32, + 1642.27, 1632.44, 1622.84, 1613.83, 1605.15, 1596.69, 1588.45, 1580.44, 1573.11}); + STravelTimeTable.add(new double[]{1714.69, 1710.5, 1705.38, 1702.23, 1691.76, 1681.33, 1670.94, 1660.66, + 1650.61, 1640.78, 1631.18, 1622.17, 1613.49, 1605.03, 1596.8, 1588.78, 1581.45}); + STravelTimeTable.add(new double[]{1723.03, 1718.84, 1713.72, 1710.57, 1700.1, 1689.67, 1679.28, 1669.0, + 1658.95, 1649.12, 1639.52, 1630.51, 1621.83, 1613.37, 1605.14, 1597.12, 1589.8}); + STravelTimeTable.add(new double[]{1731.37, 1727.18, 1722.06, 1718.91, 1708.44, 1698.01, 1687.62, 1677.34, + 1667.29, 1657.46, 1647.86, 1638.85, 1630.17, 1621.71, 1613.48, 1605.46, 1598.14}); + + PKPTravelTimeTable.add(new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}); + PKPTravelTimeTable.add(new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}); + PKPTravelTimeTable.add(new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 1085.33, 1063.71, 1044.28}); + PKPTravelTimeTable.add(new double[]{1124.84, 1119.11, 1117.27, 1111.11, 1098.95, 1087.25, 1065.64, 1046.21}); + PKPTravelTimeTable.add(new double[]{1126.76, 1121.04, 1119.19, 1113.04, 1100.88, 1089.17, 1067.56, 1048.13}); + PKPTravelTimeTable.add(new double[]{1128.68, 1122.96, 1121.11, 1114.96, 1102.8, 1091.1, 1069.49, 1050.05}); + PKPTravelTimeTable.add(new double[]{1130.61, 1124.88, 1123.04, 1116.88, 1104.72, 1093.02, 1071.41, 1051.98}); + PKPTravelTimeTable.add(new double[]{1132.53, 1126.81, 1124.96, 1118.81, 1106.65, 1094.94, 1073.33, 1053.9}); + PKPTravelTimeTable.add(new double[]{1134.45, 1128.73, 1126.88, 1120.73, 1108.57, 1096.86, 1075.25, 1055.82}); + PKPTravelTimeTable.add(new double[]{1136.37, 1130.65, 1128.8, 1122.65, 1110.49, 1098.79, 1077.17, 1057.74}); + PKPTravelTimeTable.add(new double[]{1138.29, 1132.57, 1130.72, 1124.57, 1112.41, 1100.7, 1079.09, 1059.66}); + PKPTravelTimeTable.add(new double[]{1140.21, 1134.49, 1132.64, 1126.49, 1114.33, 1102.62, 1081.01, 1061.57}); + PKPTravelTimeTable.add(new double[]{1142.13, 1136.4, 1134.56, 1128.4, 1116.24, 1104.54, 1082.92, 1063.49}); + PKPTravelTimeTable.add(new double[]{1144.04, 1138.32, 1136.47, 1130.32, 1118.15, 1106.45, 1084.83, 1065.4}); + PKPTravelTimeTable.add(new double[]{1145.95, 1140.23, 1138.38, 1132.23, 1120.06, 1108.36, 1086.74, 1067.3}); + PKPTravelTimeTable.add(new double[]{1147.86, 1142.14, 1140.29, 1134.13, 1121.97, 1110.27, 1088.65, 1069.21}); + PKPTravelTimeTable.add(new double[]{1149.76, 1144.04, 1142.19, 1136.04, 1123.88, 1112.17, 1090.55, 1071.11}); + PKPTravelTimeTable.add(new double[]{1151.67, 1145.94, 1144.09, 1137.94, 1125.78, 1114.07, 1092.45, 1073.0}); + PKPTravelTimeTable.add(new double[]{1153.56, 1147.84, 1145.99, 1139.83, 1127.67, 1115.96, 1094.34, 1074.9}); + PKPTravelTimeTable.add(new double[]{1155.45, 1149.73, 1147.88, 1141.72, 1129.56, 1117.85, 1096.23, 1076.78}); + PKPTravelTimeTable.add(new double[]{1157.34, 1151.61, 1149.77, 1143.61, 1131.45, 1119.74, 1098.11, 1078.66}); + PKPTravelTimeTable.add(new double[]{1159.22, 1153.49, 1151.65, 1145.49, 1133.32, 1121.61, 1099.98, 1080.53}); + PKPTravelTimeTable.add(new double[]{1161.09, 1155.37, 1153.52, 1147.36, 1135.19, 1123.48, 1101.85, 1082.4}); + PKPTravelTimeTable.add(new double[]{1162.96, 1157.23, 1155.38, 1149.22, 1137.06, 1125.34, 1103.71, 1084.25}); + PKPTravelTimeTable.add(new double[]{1164.81, 1159.08, 1157.24, 1151.08, 1138.91, 1127.19, 1105.56, 1086.09}); + PKPTravelTimeTable.add(new double[]{1166.66, 1160.93, 1159.08, 1152.92, 1140.75, 1129.04, 1107.4, 1087.93}); + PKPTravelTimeTable.add(new double[]{1168.49, 1162.76, 1160.91, 1154.76, 1142.58, 1130.87, 1109.22, 1089.75}); + PKPTravelTimeTable.add(new double[]{1170.31, 1164.59, 1162.74, 1156.58, 1144.4, 1132.68, 1111.04, 1091.56}); + PKPTravelTimeTable.add(new double[]{1172.12, 1166.39, 1164.54, 1158.38, 1146.21, 1134.49, 1112.83, 1093.35}); + PKPTravelTimeTable.add(new double[]{1173.92, 1168.19, 1166.34, 1160.18, 1148.0, 1136.27, 1114.62, 1095.13}); + PKPTravelTimeTable.add(new double[]{1175.69, 1169.96, 1168.11, 1161.95, 1149.77, 1138.04, 1116.38, 1096.88}); + PKPTravelTimeTable.add(new double[]{1177.45, 1171.72, 1169.87, 1163.71, 1151.52, 1139.79, 1118.13, 1098.62}); + PKPTravelTimeTable.add(new double[]{1179.19, 1173.46, 1171.61, 1165.44, 1153.26, 1141.52, 1119.85, 1100.34}); + PKPTravelTimeTable.add(new double[]{1180.9, 1175.17, 1173.32, 1167.15, 1154.96, 1143.23, 1121.55, 1102.02}); + PKPTravelTimeTable.add(new double[]{1182.59, 1176.86, 1175.01, 1168.84, 1156.65, 1144.91, 1123.22, 1103.69}); + PKPTravelTimeTable.add(new double[]{1184.25, 1178.52, 1176.67, 1170.5, 1158.3, 1146.56, 1124.86, 1105.32}); + PKPTravelTimeTable.add(new double[]{1185.88, 1180.15, 1178.3, 1172.12, 1159.93, 1148.18, 1126.47, 1106.92}); + PKPTravelTimeTable.add(new double[]{1187.48, 1181.74, 1179.89, 1173.72, 1161.51, 1149.76, 1128.05, 1108.48}); + PKPTravelTimeTable.add(new double[]{1189.04, 1183.3, 1181.45, 1175.27, 1163.06, 1151.31, 1129.58, 1110.0}); + PKPTravelTimeTable.add(new double[]{1190.55, 1184.82, 1182.96, 1176.78, 1164.57, 1152.81, 1131.07, 1111.49}); + PKPTravelTimeTable.add(new double[]{1192.03, 1186.29, 1184.44, 1178.26, 1166.04, 1154.28, 1132.53, 1112.93}); + PKPTravelTimeTable.add(new double[]{1193.47, 1187.73, 1185.87, 1179.69, 1167.47, 1155.7, 1133.94, 1114.33}); + PKPTravelTimeTable.add(new double[]{1194.86, 1189.12, 1187.26, 1181.08, 1168.85, 1157.08, 1135.31, 1115.69}); + PKPTravelTimeTable.add(new double[]{1196.2, 1190.46, 1188.61, 1182.42, 1170.19, 1158.42, 1136.63, 1117.0}); + PKPTravelTimeTable.add(new double[]{1197.5, 1191.76, 1189.9, 1183.72, 1171.48, 1159.7, 1137.91, 1118.26}); + PKPTravelTimeTable.add(new double[]{1198.75, 1193.01, 1191.15, 1184.96, 1172.73, 1160.94, 1139.14, 1119.48}); + PKPTravelTimeTable.add(new double[]{1199.96, 1194.21, 1192.35, 1186.16, 1173.92, 1162.13, 1140.32, 1120.64}); + PKPTravelTimeTable.add(new double[]{1201.11, 1195.36, 1193.5, 1187.31, 1175.06, 1163.27, 1141.45, 1121.76}); + PKPTravelTimeTable.add(new double[]{1202.2, 1196.46, 1194.6, 1188.4, 1176.15, 1164.35, 1142.52, 1122.83}); + PKPTravelTimeTable.add(new double[]{1203.25, 1197.5, 1195.64, 1189.44, 1177.19, 1165.39, 1143.55, 1123.84}); + PKPTravelTimeTable.add(new double[]{1204.24, 1198.49, 1196.63, 1190.43, 1178.18, 1166.37, 1144.52, 1124.81}); + PKPTravelTimeTable.add(new double[]{1205.18, 1199.43, 1197.57, 1191.37, 1179.11, 1167.3, 1145.44, 1125.72}); + PKPTravelTimeTable.add(new double[]{1206.06, 1200.31, 1198.45, 1192.25, 1179.99, 1168.17, 1146.31, 1126.57}); + PKPTravelTimeTable.add(new double[]{1206.89, 1201.14, 1199.28, 1193.07, 1180.81, 1168.99, 1147.12, 1127.37}); + PKPTravelTimeTable.add(new double[]{1207.66, 1201.91, 1200.05, 1193.84, 1181.58, 1169.75, 1147.88, 1128.12}); + PKPTravelTimeTable.add(new double[]{1208.38, 1202.63, 1200.77, 1194.56, 1182.29, 1170.46, 1148.58, 1128.82}); + PKPTravelTimeTable.add(new double[]{1209.04, 1203.29, 1201.43, 1195.22, 1182.94, 1171.12, 1149.22, 1129.46}); + PKPTravelTimeTable.add(new double[]{1209.64, 1203.89, 1202.03, 1195.82, 1183.54, 1171.71, 1149.81, 1130.04}); + PKPTravelTimeTable.add(new double[]{1210.19, 1204.44, 1202.57, 1196.36, 1184.08, 1172.25, 1150.35, 1130.57}); + PKPTravelTimeTable.add(new double[]{1210.68, 1204.93, 1203.06, 1196.85, 1184.57, 1172.74, 1150.83, 1131.04}); + PKPTravelTimeTable.add(new double[]{1211.11, 1205.36, 1203.49, 1197.28, 1185.0, 1173.16, 1151.25, 1131.46}); + PKPTravelTimeTable.add(new double[]{1211.49, 1205.73, 1203.87, 1197.65, 1185.37, 1173.53, 1151.62, 1131.83}); + PKPTravelTimeTable.add(new double[]{1211.81, 1206.05, 1204.19, 1197.97, 1185.69, 1173.85, 1151.93, 1132.13}); + PKPTravelTimeTable.add(new double[]{1212.07, 1206.31, 1204.44, 1198.23, 1185.94, 1174.1, 1152.18, 1132.38}); + PKPTravelTimeTable.add(new double[]{1212.27, 1206.51, 1204.65, 1198.43, 1186.14, 1174.3, 1152.38, 1132.58}); + PKPTravelTimeTable.add(new double[]{1212.41, 1206.66, 1204.79, 1198.58, 1186.29, 1174.45, 1152.52, 1132.72}); + PKPTravelTimeTable.add(new double[]{1212.5, 1206.74, 1204.88, 1198.66, 1186.37, 1174.53, 1152.61, 1132.8}); + PKPTravelTimeTable.add(new double[]{1212.53, 1206.77, 1204.91, 1198.69, 1186.4, 1174.56, 1152.64, 1132.83}); + + dataCheck(); + } + + private static void dataCheck() { + int errors = 0; + for (int i = 0; i < PTravelTimeTable.size() - 1; i++) { + for (int j = 0; j < DEPTHS.length; j++) { + if (PTravelTimeTable.get(i + 1)[j] < PTravelTimeTable.get(i)[j]) { + errors++; + } + } + } + for (int i = 0; i < STravelTimeTable.size() - 1; i++) { + for (int j = 0; j < DEPTHS.length; j++) { + if (STravelTimeTable.get(i + 1)[j] < STravelTimeTable.get(i)[j]) { + errors++; + } + } + } + + Logger.debug("[TravelTimeTable] found " + errors + " errors."); + } + + @SuppressWarnings("unused") + public static double getPKPWaveTravelTime(double depth, double angle) { + double val = _getPKPWaveTravelTime(depth, angle); + if (val == 0) { + return Double.POSITIVE_INFINITY; + } else { + return val; + } + } + + private static double _getPKPWaveTravelTime(double depth, double angle) { + depth = Math.max(0, Math.min(DEPTHS_PKP[DEPTHS_PKP.length - 1], depth)); + int d = 0; + double q = 0; + for (int i = 0; i < DEPTHS_PKP.length - 1; i++) { + if (DEPTHS_PKP[i + 1] >= depth) { + d = i; + double max = DEPTHS_PKP[i + 1]; + double min = DEPTHS_PKP[i]; + q = (depth - min) / (max - min); + break; + } + } + + if (angle <= PKP_START) { + return Double.POSITIVE_INFINITY; + } else if (angle - PKP_START >= PKPTravelTimeTable.size() - 1) { + return PKPTravelTimeTable.get(PKPTravelTimeTable.size() - 1)[d] * (1 - q) + + PKPTravelTimeTable.get(PKPTravelTimeTable.size() - 1)[d + 1] * (q); + } + + int low = (int) (angle - PKP_START); + int high = low + 1; + + double valHigh = PKPTravelTimeTable.get(high)[d] * (1 - q) + PKPTravelTimeTable.get(high)[d + 1] * (q); + double valLow = PKPTravelTimeTable.get(low)[d] * (1 - q) + PKPTravelTimeTable.get(low)[d + 1] * (q); + + if (PKPTravelTimeTable.get(high)[d] <= 0 || PKPTravelTimeTable.get(high)[d + 1] <= 0 + || PKPTravelTimeTable.get(low)[d] <= 0 || PKPTravelTimeTable.get(low)[d + 1] <= 0) { + return Double.POSITIVE_INFINITY; + } + + double r = angle % 1.0; + return (1 - r) * valLow + r * valHigh; + } + + /** + * @param depth depth in km + * @param angle angle + * @return P wave travel time in seconds + */ + public static double getPWaveTravelTime(double depth, double angle) { + depth = Math.max(0, Math.min(DEPTHS[DEPTHS.length - 1], depth)); + int d = 0; + double q = 0; + for (int i = 0; i < DEPTHS.length - 1; i++) { + if (DEPTHS[i + 1] >= depth) { + d = i; + double max = DEPTHS[i + 1]; + double min = DEPTHS[i]; + q = (depth - min) / (max - min); + break; + } + } + + if (angle <= 0) { + return PTravelTimeTable.get(0)[d] * (1 - q) + PTravelTimeTable.get(0)[d + 1] * (q); + } else if (angle >= PTravelTimeTable.size() - 1) { + return PTravelTimeTable.get(PTravelTimeTable.size() - 1)[d] * (1 - q) + + PTravelTimeTable.get(PTravelTimeTable.size() - 1)[d + 1] * (q); + } + + int low = (int) (angle); + int high = low + 1; + + double valHigh = PTravelTimeTable.get(high)[d] * (1 - q) + PTravelTimeTable.get(high)[d + 1] * (q); + double valLow = PTravelTimeTable.get(low)[d] * (1 - q) + PTravelTimeTable.get(low)[d + 1] * (q); + + double r = angle % 1.0; + return (1 - r) * valLow + r * valHigh; + } + + public static double getSWaveTravelTime(double depth, double angle) { + depth = Math.max(0, Math.min(DEPTHS[DEPTHS.length - 1], depth)); + int d = 0; + double q = 0; + for (int i = 0; i < DEPTHS.length - 1; i++) { + if (DEPTHS[i + 1] >= depth) { + d = i; + double max = DEPTHS[i + 1]; + double min = DEPTHS[i]; + q = (depth - min) / (max - min); + break; + } + } + if (angle <= 0) { + return STravelTimeTable.get(0)[d] * (1 - q) + STravelTimeTable.get(0)[d + 1] * (q); + } else if (angle >= STravelTimeTable.size() - 1) { + return STravelTimeTable.get(STravelTimeTable.size() - 1)[d] * (1 - q) + + STravelTimeTable.get(STravelTimeTable.size() - 1)[d + 1] * (q); + } + int low = (int) (angle); + int high = low + 1; + + double valHigh = STravelTimeTable.get(high)[d] * (1 - q) + STravelTimeTable.get(high)[d + 1] * (q); + double valLow = STravelTimeTable.get(low)[d] * (1 - q) + STravelTimeTable.get(low)[d + 1] * (q); + + double r = angle % 1.0; + return (1 - r) * valLow + r * valHigh; + } + + /** + * -1 WHEN IT HASN'T OCCURRED YET +INFINITY WHEN IT ALREADY PASSED THE EARTH + **/ + + @SuppressWarnings("unused") + public static double getPKPWaveTravelAngle(double depth, double ageSec) { + depth = Math.max(0, Math.min(DEPTHS_PKP[DEPTHS_PKP.length - 1], depth)); + int d = 0; + double q = 0; + for (int i = 0; i < DEPTHS_PKP.length - 1; i++) { + if (DEPTHS_PKP[i + 1] >= depth) { + d = i; + double max = DEPTHS_PKP[i + 1]; + double min = DEPTHS_PKP[i]; + q = (depth - min) / (max - min); + break; + } + } + + // System.out.println("lower: " + DEPTHS[d] + ", upper: " + DEPTHS[d + 1] + ", " + // + q); + + // System.out.println("val0=" + val0+", "+d+", "+q); + // its still underground + + double valN = PKPTravelTimeTable.get(PKPTravelTimeTable.size() - 1)[d] * (1 - q) + + PKPTravelTimeTable.get(PKPTravelTimeTable.size() - 1)[d + 1] * (q); + // System.out.println("valN=" + valN); + // exceeded 125° + if (ageSec > valN) { + return Double.POSITIVE_INFINITY; + } + + int lo = 0; + int hi = PKPTravelTimeTable.size() - 1; + + while (lo <= hi) { + int mid = (hi + lo) / 2; + double val = PKPTravelTimeTable.get(mid)[d] * (1 - q) + PKPTravelTimeTable.get(mid)[d + 1] * (q); + if (ageSec < val) { + hi = mid - 1; + } else if (ageSec >= val) { + lo = mid + 1; + } + } + + double valLo = PKPTravelTimeTable.get(lo)[d] * (1 - q) + PKPTravelTimeTable.get(lo)[d + 1] * (q); + double valHi = PKPTravelTimeTable.get(hi)[d] * (1 - q) + PKPTravelTimeTable.get(hi)[d + 1] * (q); + if (PKPTravelTimeTable.get(hi)[d] <= 0 || PKPTravelTimeTable.get(hi)[d + 1] <= 0 + || PKPTravelTimeTable.get(lo)[d] <= 0 || PKPTravelTimeTable.get(lo)[d + 1] <= 0) { + return Double.POSITIVE_INFINITY; + } + double r = (ageSec - valHi) / (valLo - valHi); return hi + r + PKP_START; - } - - public static double getPWaveTravelAngle(double depth, double ageSec, boolean outOfBounds) { - depth = Math.max(0, Math.min(DEPTHS[DEPTHS.length - 1], depth)); - int d = 0; - double q = 0; - for (int i = 0; i < DEPTHS.length - 1; i++) { - if (DEPTHS[i + 1] >= depth) { - d = i; - double max = DEPTHS[i + 1]; - double min = DEPTHS[i]; - q = (depth - min) / (max - min); - break; - } - } + } + + public static double getPWaveTravelAngle(double depth, double ageSec, boolean outOfBounds) { + depth = Math.max(0, Math.min(DEPTHS[DEPTHS.length - 1], depth)); + int d = 0; + double q = 0; + for (int i = 0; i < DEPTHS.length - 1; i++) { + if (DEPTHS[i + 1] >= depth) { + d = i; + double max = DEPTHS[i + 1]; + double min = DEPTHS[i]; + q = (depth - min) / (max - min); + break; + } + } double val0 = PTravelTimeTable.get(0)[d] * (1 - q) + PTravelTimeTable.get(0)[d + 1] * (q); - // System.out.println("val0=" + val0+", "+d+", "+q); - // its still underground - if (ageSec <= val0) { - return outOfBounds ? -1 : 0.0; - } - - double valN = PTravelTimeTable.get(PTravelTimeTable.size() - 1)[d] * (1 - q) - + PTravelTimeTable.get(PTravelTimeTable.size() - 1)[d + 1] * (q); - // System.out.println("valN=" + valN); - // exceeded 125° - if (ageSec > valN) { - return outOfBounds ? -1 : PTravelTimeTable.size() - 1; - } - - int lo = 0; - int hi = PTravelTimeTable.size() - 1; - - while (lo <= hi) { - int mid = (hi + lo) / 2; - double val = PTravelTimeTable.get(mid)[d] * (1 - q) + PTravelTimeTable.get(mid)[d + 1] * (q); - if (ageSec < val) { - hi = mid - 1; - } else if (ageSec >= val) { - lo = mid + 1; - } - } - - double valLo = PTravelTimeTable.get(lo)[d] * (1 - q) + PTravelTimeTable.get(lo)[d + 1] * (q); - double valHi = PTravelTimeTable.get(hi)[d] * (1 - q) + PTravelTimeTable.get(hi)[d + 1] * (q); - double r = (ageSec - valHi) / (valLo - valHi); - return hi + r; - } - - public static double getSWaveTravelAngle(double depth, double ageSec, boolean outOfBounds) { - depth = Math.max(0, Math.min(DEPTHS[DEPTHS.length - 1], depth)); - int d = 0; - double q = 0; - for (int i = 0; i < DEPTHS.length - 1; i++) { - if (DEPTHS[i + 1] >= depth) { - d = i; - double max = DEPTHS[i + 1]; - double min = DEPTHS[i]; - q = (depth - min) / (max - min); - break; - } - } - - double val0 = STravelTimeTable.get(0)[d] * (1 - q) + STravelTimeTable.get(0)[d + 1] * (q); - // It's still underground - if (ageSec <= val0) { - return outOfBounds ? -1 : 0.0; - } - - double valN = STravelTimeTable.get(STravelTimeTable.size() - 1)[d] * (1 - q) - + STravelTimeTable.get(STravelTimeTable.size() - 1)[d + 1] * (q); - if (ageSec > valN) { - return outOfBounds ? -1 : PTravelTimeTable.size() - 1; - } - - int lo = 0; - int hi = STravelTimeTable.size() - 1; - - while (lo <= hi) { - int mid = (hi + lo) / 2; - double val = STravelTimeTable.get(mid)[d] * (1 - q) + STravelTimeTable.get(mid)[d + 1] * (q); - if (ageSec < val) { - hi = mid - 1; - } else if (ageSec >= val) { - lo = mid + 1; - } - } - - double valLo = STravelTimeTable.get(lo)[d] * (1 - q) + STravelTimeTable.get(lo)[d + 1] * (q); - double valHi = STravelTimeTable.get(hi)[d] * (1 - q) + STravelTimeTable.get(hi)[d + 1] * (q); - double r = (ageSec - valHi) / (valLo - valHi); - return hi + r; - } - - @SuppressWarnings("unused") - public static double getEpicenterDistance(double depth, double deltaT) { - double max = 20000; - int runs = 20; - double current = 0; - - double min = getSWaveTravelTime(depth, 0) - getPWaveTravelTime(depth, 0); - if (deltaT < min) { - return -1; - } - - for (int i = 0; i < runs; i++) { - double v = current + (max / Math.pow(2, i + 1)); // distance - double dt = Math.abs(getSWaveTravelTime(depth, TauPTravelTimeCalculator.toAngle(v)) - getPWaveTravelTime(depth, TauPTravelTimeCalculator.toAngle(v))); - if (dt < deltaT) { - current += (max / Math.pow(2, i + 1)); - } - } - return current; - } + // System.out.println("val0=" + val0+", "+d+", "+q); + // its still underground + if (ageSec <= val0) { + return outOfBounds ? -1 : 0.0; + } + + double valN = PTravelTimeTable.get(PTravelTimeTable.size() - 1)[d] * (1 - q) + + PTravelTimeTable.get(PTravelTimeTable.size() - 1)[d + 1] * (q); + // System.out.println("valN=" + valN); + // exceeded 125° + if (ageSec > valN) { + return outOfBounds ? -1 : PTravelTimeTable.size() - 1; + } + + int lo = 0; + int hi = PTravelTimeTable.size() - 1; + + while (lo <= hi) { + int mid = (hi + lo) / 2; + double val = PTravelTimeTable.get(mid)[d] * (1 - q) + PTravelTimeTable.get(mid)[d + 1] * (q); + if (ageSec < val) { + hi = mid - 1; + } else if (ageSec >= val) { + lo = mid + 1; + } + } + + double valLo = PTravelTimeTable.get(lo)[d] * (1 - q) + PTravelTimeTable.get(lo)[d + 1] * (q); + double valHi = PTravelTimeTable.get(hi)[d] * (1 - q) + PTravelTimeTable.get(hi)[d + 1] * (q); + double r = (ageSec - valHi) / (valLo - valHi); + return hi + r; + } + + public static double getSWaveTravelAngle(double depth, double ageSec, boolean outOfBounds) { + depth = Math.max(0, Math.min(DEPTHS[DEPTHS.length - 1], depth)); + int d = 0; + double q = 0; + for (int i = 0; i < DEPTHS.length - 1; i++) { + if (DEPTHS[i + 1] >= depth) { + d = i; + double max = DEPTHS[i + 1]; + double min = DEPTHS[i]; + q = (depth - min) / (max - min); + break; + } + } + + double val0 = STravelTimeTable.get(0)[d] * (1 - q) + STravelTimeTable.get(0)[d + 1] * (q); + // It's still underground + if (ageSec <= val0) { + return outOfBounds ? -1 : 0.0; + } + + double valN = STravelTimeTable.get(STravelTimeTable.size() - 1)[d] * (1 - q) + + STravelTimeTable.get(STravelTimeTable.size() - 1)[d + 1] * (q); + if (ageSec > valN) { + return outOfBounds ? -1 : PTravelTimeTable.size() - 1; + } + + int lo = 0; + int hi = STravelTimeTable.size() - 1; + + while (lo <= hi) { + int mid = (hi + lo) / 2; + double val = STravelTimeTable.get(mid)[d] * (1 - q) + STravelTimeTable.get(mid)[d + 1] * (q); + if (ageSec < val) { + hi = mid - 1; + } else if (ageSec >= val) { + lo = mid + 1; + } + } + + double valLo = STravelTimeTable.get(lo)[d] * (1 - q) + STravelTimeTable.get(lo)[d + 1] * (q); + double valHi = STravelTimeTable.get(hi)[d] * (1 - q) + STravelTimeTable.get(hi)[d + 1] * (q); + double r = (ageSec - valHi) / (valLo - valHi); + return hi + r; + } + + @SuppressWarnings("unused") + public static double getEpicenterDistance(double depth, double deltaT) { + double max = 20000; + int runs = 20; + double current = 0; + + double min = getSWaveTravelTime(depth, 0) - getPWaveTravelTime(depth, 0); + if (deltaT < min) { + return -1; + } + + for (int i = 0; i < runs; i++) { + double v = current + (max / Math.pow(2, i + 1)); // distance + double dt = Math.abs(getSWaveTravelTime(depth, TauPTravelTimeCalculator.toAngle(v)) - getPWaveTravelTime(depth, TauPTravelTimeCalculator.toAngle(v))); + if (dt < deltaT) { + current += (max / Math.pow(2, i + 1)); + } + } + return current; + } } diff --git a/GlobalQuakeCore/src/test/java/globalquake/core/regions/RegionUpdaterTest.java b/GlobalQuakeCore/src/test/java/globalquake/core/regions/RegionUpdaterTest.java index 695520461..905abd342 100644 --- a/GlobalQuakeCore/src/test/java/globalquake/core/regions/RegionUpdaterTest.java +++ b/GlobalQuakeCore/src/test/java/globalquake/core/regions/RegionUpdaterTest.java @@ -11,7 +11,7 @@ public class RegionUpdaterTest { @Test - public void testNonnull(){ + public void testNonnull() { RegionalInst inst = new RegionalInst(50, 17); new RegionUpdater(inst); assertEquals(RegionUpdater.DEFAULT_REGION, inst.getRegion()); @@ -19,7 +19,7 @@ public void testNonnull(){ @Test - public void testBasicUpdate(){ + public void testBasicUpdate() { RegionalInst inst = new RegionalInst(50, 17); RegionUpdater updater = new RegionUpdater(inst); updater.updateRegion(); @@ -27,14 +27,14 @@ public void testBasicUpdate(){ } @Test - public void testEarthquakeRegion(){ + public void testEarthquakeRegion() { Earthquake earthquake = new Earthquake(new Cluster()); assertNotNull(earthquake.getRegion()); } @Test - public void testArchivedEarthquakeRegion(){ - ArchivedQuake archivedQuake = new ArchivedQuake(null, 50,17,0,0,0, QualityClass.S, 100); + public void testArchivedEarthquakeRegion() { + ArchivedQuake archivedQuake = new ArchivedQuake(null, 50, 17, 0, 0, 0, QualityClass.S, 100); assertNotNull(archivedQuake.getRegion()); } @@ -44,7 +44,7 @@ static class RegionalInst implements Regional { private final double lon; private String region; - public RegionalInst(double lat, double lon){ + public RegionalInst(double lat, double lon) { this.lat = lat; this.lon = lon; } diff --git a/GlobalQuakeCore/src/test/java/globalquake/core/regions/RegionsTest.java b/GlobalQuakeCore/src/test/java/globalquake/core/regions/RegionsTest.java index 0730f2e1a..35c551216 100644 --- a/GlobalQuakeCore/src/test/java/globalquake/core/regions/RegionsTest.java +++ b/GlobalQuakeCore/src/test/java/globalquake/core/regions/RegionsTest.java @@ -24,7 +24,7 @@ public void getShorelineDistanceTest() throws IOException { Regions.init(); double lat = 62.659630, - lon = -42.440372; + lon = -42.440372; assertEquals(19.53736973813437, Regions.getShorelineDistance(lat, lon), 0.1); @@ -38,6 +38,7 @@ public void getShorelineDistanceTest() throws IOException { assertEquals(55, Regions.getShorelineDistance(lat, lon), 1); } + @SuppressWarnings("unused") public void bilinearInterpolationTest() throws IOException { HashMap lookupTable = LookupTableIO.importLookupTableFromFile(); @@ -49,6 +50,7 @@ public void bilinearInterpolationTest() throws IOException { interpolation = interpolate(-2.376240, -38.963751, lookupTable); assertEquals(125, interpolation, 5); } + @SuppressWarnings("unused") public void lookupTableEffectivityTest() throws IOException { Regions.init(); @@ -70,7 +72,7 @@ public void lookupTableEffectivityTest() throws IOException { double legacy = legacyEndTime - legacyStartTime; double lookup = lookupEndTime - lookupStartTime; - assert(lookup < legacy); + assert (lookup < legacy); } @SuppressWarnings("unused") @@ -87,10 +89,10 @@ public void lookupTableGenerationTest() { assertEquals(4, testLookupTable.size()); double lat = 0, lon; - for(int i = 0; i < 2; i++){ + for (int i = 0; i < 2; i++) { lon = 0; - for(int j = 0; j < 2; j++){ + for (int j = 0; j < 2; j++) { String expectedKey = String.format("%.6f,%.6f", lat, lon); assertTrue(testLookupTable.containsKey(expectedKey)); diff --git a/GlobalQuakeCore/src/test/java/globalquake/core/station/AbstractStationTest.java b/GlobalQuakeCore/src/test/java/globalquake/core/station/AbstractStationTest.java index a62774ba2..434fa1eb5 100644 --- a/GlobalQuakeCore/src/test/java/globalquake/core/station/AbstractStationTest.java +++ b/GlobalQuakeCore/src/test/java/globalquake/core/station/AbstractStationTest.java @@ -8,8 +8,8 @@ public class AbstractStationTest { @Test - public void testIntervals(){ - AbstractStation abstractStation = new GlobalStation("", "", "", "",5,5,5,5,null, -1, InputType.UNKNOWN); + public void testIntervals() { + AbstractStation abstractStation = new GlobalStation("", "", "", "", 5, 5, 5, 5, null, -1, InputType.UNKNOWN); StationInterval int1 = new StationInterval(10, 50, StationState.INACTIVE); StationInterval int2 = new StationInterval(50, 70, StationState.ACTIVE); StationInterval int3 = new StationInterval(100, 150, StationState.ACTIVE); @@ -24,8 +24,8 @@ public void testIntervals(){ } @Test - public void testReport(){ - AbstractStation abstractStation = new GlobalStation("", "", "", "",5,5,5,5,null, -1, InputType.UNKNOWN); + public void testReport() { + AbstractStation abstractStation = new GlobalStation("", "", "", "", 5, 5, 5, 5, null, -1, InputType.UNKNOWN); abstractStation.reportState(StationState.ACTIVE, 0); abstractStation.reportState(StationState.ACTIVE, 10); diff --git a/GlobalQuakeServer/src/main/java/gqserver/bot/DiscordBotDebug.java b/GlobalQuakeServer/src/main/java/gqserver/bot/DiscordBotDebug.java index 48d37089f..79b678ce3 100644 --- a/GlobalQuakeServer/src/main/java/gqserver/bot/DiscordBotDebug.java +++ b/GlobalQuakeServer/src/main/java/gqserver/bot/DiscordBotDebug.java @@ -28,12 +28,12 @@ public static void main(String[] args) { @Override public void onReady(@NotNull ReadyEvent event) { - for(Guild guild:jda.getGuilds()){ + for (Guild guild : jda.getGuilds()) { System.out.printf("GUILD %s - %s\n".formatted(guild.getName(), guild.getId())); - for(Role role : guild.getRoles()){ + for (Role role : guild.getRoles()) { System.out.printf(" ROLE %s - %s\n".formatted(role.getName(), role.getId())); } - for(TextChannel channel : guild.getTextChannels()){ + for (TextChannel channel : guild.getTextChannels()) { System.out.printf(" CHANNEL %s - %s\n".formatted(channel.getName(), channel.getId())); } } @@ -68,6 +68,6 @@ public void onReady(@NotNull ReadyEvent event) { jda.getGuildById("955128942078087228").getTextChannelById("955128942078087230") .sendMessageEmbeds(builder.build()).queue();*/ - // jda.getGuildById("1150807505115549736").getTextChannelById("1151878913123962940").createInvite().queue(invite -> System.err.println(invite.getUrl())); + // jda.getGuildById("1150807505115549736").getTextChannelById("1151878913123962940").createInvite().queue(invite -> System.err.println(invite.getUrl())); } } diff --git a/GlobalQuakeServer/src/main/java/gqserver/events/GlobalQuakeServerEventHandler.java b/GlobalQuakeServer/src/main/java/gqserver/events/GlobalQuakeServerEventHandler.java index 240d3f2a7..652b5e4f7 100644 --- a/GlobalQuakeServer/src/main/java/gqserver/events/GlobalQuakeServerEventHandler.java +++ b/GlobalQuakeServer/src/main/java/gqserver/events/GlobalQuakeServerEventHandler.java @@ -20,21 +20,21 @@ public GlobalQuakeServerEventHandler runHandler() { return this; } - public void stopHandler(){ + public void stopHandler() { GlobalQuake.instance.stopService(executor); eventListeners.clear(); } - public void registerEventListener(GlobalQuakeServerEventListener eventListener){ + public void registerEventListener(GlobalQuakeServerEventListener eventListener) { eventListeners.add(eventListener); } @SuppressWarnings("unused") - public boolean removeEventListener(GlobalQuakeServerEventListener eventListener){ + public boolean removeEventListener(GlobalQuakeServerEventListener eventListener) { return eventListeners.remove(eventListener); } - public void fireEvent(GlobalQuakeServerEvent event){ + public void fireEvent(GlobalQuakeServerEvent event) { executor.submit(() -> { Logger.tag("EventServer").trace("Server event fired: %s".formatted(event.toString())); for (GlobalQuakeServerEventListener eventListener : eventListeners) { diff --git a/GlobalQuakeServer/src/main/java/gqserver/fdsnws_event/EventsV1Handler.java b/GlobalQuakeServer/src/main/java/gqserver/fdsnws_event/EventsV1Handler.java index 4ba2053d7..0fb75f71d 100644 --- a/GlobalQuakeServer/src/main/java/gqserver/fdsnws_event/EventsV1Handler.java +++ b/GlobalQuakeServer/src/main/java/gqserver/fdsnws_event/EventsV1Handler.java @@ -21,18 +21,17 @@ import globalquake.core.earthquake.EarthquakeDataExport; import globalquake.core.exception.RuntimeApplicationException; -public class EventsV1Handler implements HttpHandler{ +public class EventsV1Handler implements HttpHandler { @Override public void handle(HttpExchange exchange) throws IOException { HttpCatchAllLogger.logIncomingRequest(exchange); - //check if application.wadl was requested - if(exchange.getRequestURI().toString().endsWith("application.wadl")){ + if (exchange.getRequestURI().toString().endsWith("application.wadl")) { URL wadlURL = getClass().getClassLoader().getResource("fdsnws_event_application.wadl"); - if(wadlURL == null){ + if (wadlURL == null) { HttpRequestException ex = new HttpRequestException(500, "Internal Server Error"); ex.transmitToClient(exchange); Logger.error(new RuntimeApplicationException("Wadl URL is null!")); @@ -41,9 +40,9 @@ public void handle(HttpExchange exchange) throws IOException { String wadl; - try(InputStream in = wadlURL.openStream()){ + try (InputStream in = wadlURL.openStream()) { wadl = new String(in.readAllBytes()); - } catch(Exception e){ + } catch (Exception e) { Logger.error(e); HttpRequestException ex = new HttpRequestException(500, "Internal Server Error"); ex.transmitToClient(exchange); @@ -57,9 +56,9 @@ public void handle(HttpExchange exchange) throws IOException { //Parse the query string first to avoid extra work if there is an error FdsnwsEventsRequest request; - try{ + try { request = new FdsnwsEventsRequest(exchange); - }catch(HttpRequestException e){ + } catch (HttpRequestException e) { //An error occurred parsing the query string e.transmitToClient(exchange); return; @@ -70,7 +69,7 @@ public void handle(HttpExchange exchange) throws IOException { List earthquakes = EarthquakeDataExport.getArchivedAndLiveEvents(); List filteredQuakes = filterEventDataWithRequest(earthquakes, request); - + String formattedResult; String contentType; @@ -107,58 +106,61 @@ public void handle(HttpExchange exchange) throws IOException { } - private List filterEventDataWithRequest(List earthquakes, FdsnwsEventsRequest request){ + private List filterEventDataWithRequest(List earthquakes, FdsnwsEventsRequest request) { //Order does not necessarily matter here. //A basic wrapper is made to easily filter the earthquakes - class protoquake {public ArchivedQuake quake; public boolean include;} + class protoquake { + public ArchivedQuake quake; + public boolean include; + } List protoquakes = new ArrayList<>(); - for(ArchivedQuake quake : earthquakes){ + for (ArchivedQuake quake : earthquakes) { protoquake protoquake = new protoquake(); protoquake.quake = quake; protoquake.include = true; protoquakes.add(protoquake); } - + //If an event falls outside of any of the filters, it is removed from the list - for(protoquake protoquake : protoquakes){ + for (protoquake protoquake : protoquakes) { //Filter by time - if(protoquake.quake.getOrigin() < request.starttime.getTime()){ + if (protoquake.quake.getOrigin() < request.starttime.getTime()) { protoquake.include = false; } - if(protoquake.quake.getOrigin() > request.endtime.getTime()){ + if (protoquake.quake.getOrigin() > request.endtime.getTime()) { protoquake.include = false; } //Filter by latitude - if(protoquake.quake.getLat() < request.minlatitude){ + if (protoquake.quake.getLat() < request.minlatitude) { protoquake.include = false; } - if(protoquake.quake.getLat() > request.maxlatitude){ + if (protoquake.quake.getLat() > request.maxlatitude) { protoquake.include = false; } //Filter by longitude - if(protoquake.quake.getLon() < request.minlongitude){ + if (protoquake.quake.getLon() < request.minlongitude) { protoquake.include = false; } - if(protoquake.quake.getLon() > request.maxlongitude){ + if (protoquake.quake.getLon() > request.maxlongitude) { protoquake.include = false; } //Filter by depth - if(protoquake.quake.getDepth() < request.mindepth){ + if (protoquake.quake.getDepth() < request.mindepth) { protoquake.include = false; } - if(protoquake.quake.getDepth() > request.maxdepth){ + if (protoquake.quake.getDepth() > request.maxdepth) { protoquake.include = false; } //Filter by magnitude - if(protoquake.quake.getMag() < request.minmagnitude){ + if (protoquake.quake.getMag() < request.minmagnitude) { protoquake.include = false; } - if(protoquake.quake.getMag() > request.maxmagnitude){ + if (protoquake.quake.getMag() > request.maxmagnitude) { protoquake.include = false; } } @@ -168,7 +170,7 @@ class protoquake {public ArchivedQuake quake; public boolean include;} //Convert the protoquakes back into a list of ArchivedQuakes List filteredEarthquakes = new ArrayList<>(); - for(protoquake protoquake : protoquakes){ + for (protoquake protoquake : protoquakes) { filteredEarthquakes.add(protoquake.quake); } @@ -177,7 +179,7 @@ class protoquake {public ArchivedQuake quake; public boolean include;} } - private static void sendResponse(HttpExchange exchange, HttpResponse response) throws IOException{ + private static void sendResponse(HttpExchange exchange, HttpResponse response) throws IOException { exchange.getResponseHeaders().set("Content-Type", response.responseContentType()); exchange.getResponseHeaders().set("Access-Control-Allow-Origin", "*"); //TODO: make this configurable exchange.sendResponseHeaders(response.responseCode(), response.responseContent().length()); @@ -225,17 +227,17 @@ private static class FdsnwsEventsRequest { private String eventid; //Select a specific event by ID; event identifiers are data center specific private int limit; //Limit the results to the specified number of events. private int offset; //Return results starting at the event count specified, starting at 1. - + private String orderby; //Order the results. The allowed values are: - //time - the default, order by origin descending time - //time-asc - order by origin ascending time - //magnitude - order by descending magnitude - //magnitude-asc - order by ascending magnitude + //time - the default, order by origin descending time + //time-asc - order by origin ascending time + //magnitude - order by descending magnitude + //magnitude-asc - order by ascending magnitude private String catalog; //Limit to events from a specified catalog. private String contributor; //Limit to events contributed by a specified contributor. private Date updatedafter; //Limit to events updated after the specified time. - //* While this option is not required it is highly recommended due to usefulness. + //* While this option is not required it is highly recommended due to usefulness. private String format; //Specify the output format. XML, json|geojson, text. private int nodata; //HTTP status code to return when no data is found. Default is 204, no content. @@ -266,103 +268,103 @@ private void setNotImplementedParameters(){ } */ - public FdsnwsEventsRequest(HttpExchange exchange) throws HttpRequestException{ + public FdsnwsEventsRequest(HttpExchange exchange) throws HttpRequestException { initDefaultParameters(); parseQuery(exchange.getRequestURI()); } - private void parseQuery(URI uri) throws HttpRequestException{ + private void parseQuery(URI uri) throws HttpRequestException { //Comments here appear once when needed to avoid duplicated explanations Map parameters = parseQueryString(uri.getQuery()); String start1 = parameters.get("start"); String start2 = parameters.get("starttime"); //If both are null, then the default is used - if(start1 != null){ + if (start1 != null) { starttime = EventsV1ParamChecks.parseDate(start1); - }else if(start2 != null){ + } else if (start2 != null) { starttime = EventsV1ParamChecks.parseDate(start2); } //If an error occurred, tell the user and log it - if(starttime == null){ + if (starttime == null) { throw new HttpRequestException(400, "Issue parsing start time. Use the format \"YYYY-MM-DDTHH:MM:SS\" UTC time"); } String end1 = parameters.get("end"); String end2 = parameters.get("endtime"); - if(end1 != null){ + if (end1 != null) { endtime = EventsV1ParamChecks.parseDate(end1); - }else if(end2 != null){ + } else if (end2 != null) { endtime = EventsV1ParamChecks.parseDate(end2); } - if(endtime == null){ + if (endtime == null) { throw new HttpRequestException(400, "Issue parsing end time. Use the format of \"YYYY-MM-DDTHH:MM:SS\" UTC time"); } String minlat1 = parameters.get("minlat"); String minlat2 = parameters.get("minimumlatitude"); - if(minlat1 != null){ + if (minlat1 != null) { minlatitude = EventsV1ParamChecks.parseLatitude(minlat1); - }else if(minlat2 != null){ + } else if (minlat2 != null) { minlatitude = EventsV1ParamChecks.parseLatitude(minlat2); } - if(minlatitude == null){ + if (minlatitude == null) { throw new HttpRequestException(400, "Issue parsing minimum latitude. Make sure it is between -90 and 90"); } String maxlat1 = parameters.get("maxlat"); String maxlat2 = parameters.get("maximumlatitude"); - if(maxlat1 != null){ + if (maxlat1 != null) { maxlatitude = EventsV1ParamChecks.parseLatitude(maxlat1); - }else if(maxlat2 != null){ + } else if (maxlat2 != null) { maxlatitude = EventsV1ParamChecks.parseLatitude(maxlat2); } - if(maxlatitude == null){ + if (maxlatitude == null) { throw new HttpRequestException(400, "Issue parsing maximum latitude. Make sure it is between -90 and 90"); } String minlon1 = parameters.get("minlon"); String minlon2 = parameters.get("minimumlongitude"); - if(minlon1 != null){ + if (minlon1 != null) { minlongitude = EventsV1ParamChecks.parseLongitude(minlon1); - }else if(minlon2 != null){ + } else if (minlon2 != null) { minlongitude = EventsV1ParamChecks.parseLongitude(minlon2); } - if(minlongitude == null){ + if (minlongitude == null) { throw new HttpRequestException(400, "Issue parsing minimum longitude. Make sure it is between -180 and 180"); } String maxlon1 = parameters.get("maxlon"); String maxlon2 = parameters.get("maximumlongitude"); - if(maxlon1 != null){ + if (maxlon1 != null) { maxlongitude = EventsV1ParamChecks.parseLongitude(maxlon1); - }else if(maxlon2 != null){ + } else if (maxlon2 != null) { maxlongitude = EventsV1ParamChecks.parseLongitude(maxlon2); } - if(maxlongitude == null){ + if (maxlongitude == null) { throw new HttpRequestException(400, "Issue parsing maximum longitude. Make sure it is between -180 and 180"); } - + String lat1 = parameters.get("lat"); String lat2 = parameters.get("latitude"); - if(lat1 != null){ + if (lat1 != null) { latitude = EventsV1ParamChecks.parseLatitude(lat1); - }else if(lat2 != null){ + } else if (lat2 != null) { latitude = EventsV1ParamChecks.parseLatitude(lat2); } //Either lat was null and the result is null - if( (lat1 != null || lat2 != null) && latitude == null){ + if ((lat1 != null || lat2 != null) && latitude == null) { throw new HttpRequestException(400, "Issue parsing latitude. Make sure it is between -90 and 90"); } String lon1 = parameters.get("lon"); String lon2 = parameters.get("longitude"); - if(lon1 != null){ + if (lon1 != null) { longitude = EventsV1ParamChecks.parseLongitude(lon1); - }else if(lon2 != null){ + } else if (lon2 != null) { longitude = EventsV1ParamChecks.parseLongitude(lon2); } - if( (lon1 != null || lon2 != null) && longitude == null){ + if ((lon1 != null || lon2 != null) && longitude == null) { throw new HttpRequestException(400, "Issue parsing longitude. Make sure it is between -180 and 180"); } @@ -370,40 +372,40 @@ private void parseQuery(URI uri) throws HttpRequestException{ //maxradius String mindepth1 = parameters.get("mindepth"); - if(mindepth1 != null){ + if (mindepth1 != null) { mindepth = EventsV1ParamChecks.parseDepth(mindepth1); } - if(mindepth == null){ + if (mindepth == null) { throw new HttpRequestException(400, "Issue parsing minimum depth"); } String maxdepth1 = parameters.get("maxdepth"); - if(maxdepth1 != null){ + if (maxdepth1 != null) { maxdepth = EventsV1ParamChecks.parseDepth(maxdepth1); } - if(maxdepth == null){ + if (maxdepth == null) { throw new HttpRequestException(400, "Issue parsing maximum depth"); } String minmag1 = parameters.get("minmag"); String minmag2 = parameters.get("minmagnitude"); - if(minmag1 != null){ + if (minmag1 != null) { minmagnitude = EventsV1ParamChecks.parseMagnitude(minmag1); - }else if(minmag2 != null){ + } else if (minmag2 != null) { minmagnitude = EventsV1ParamChecks.parseMagnitude(minmag2); } - if(minmagnitude == null){ + if (minmagnitude == null) { throw new HttpRequestException(400, "Issue parsing minimum magnitude, make sure it is between -10 and 10"); } String maxmag1 = parameters.get("maxmag"); String maxmag2 = parameters.get("maxmagnitude"); - if(maxmag1 != null){ + if (maxmag1 != null) { maxmagnitude = EventsV1ParamChecks.parseMagnitude(maxmag1); - }else if(maxmag2 != null){ + } else if (maxmag2 != null) { maxmagnitude = EventsV1ParamChecks.parseMagnitude(maxmag2); } - if(maxmagnitude == null){ + if (maxmagnitude == null) { throw new HttpRequestException(400, "Issue parsing maximum magnitude, make sure it is between -10 and 10"); } @@ -419,28 +421,28 @@ private void parseQuery(URI uri) throws HttpRequestException{ //catalog //contributor //updatedafter - + String format1 = parameters.get("format"); - if(format1 != null){ + if (format1 != null) { //This might throw an exception format = EventsV1ParamChecks.parseFormat(format1); } - if(format == null){ + if (format == null) { throw new HttpRequestException(400, "Issue parsing format. Make sure it is one of \"xml\", \"json\", \"geojson\", or \"text\""); } String nodata1 = parameters.get("nodata"); - if(nodata1 != null){ + if (nodata1 != null) { nodata = EventsV1ParamChecks.parseNoData(nodata1); } - if(nodata == 0){ + if (nodata == 0) { throw new HttpRequestException(400, "Issue parsing nodata. Make sure it is between 1 and 999"); } } - - private void initDefaultParameters(){ + + private void initDefaultParameters() { //Required parameters are set to reasonable defaults starttime = new Date(System.currentTimeMillis() - 3600 * 1000); //one hour ago endtime = new Date(System.currentTimeMillis()); //now @@ -487,35 +489,35 @@ private Map parseQueryString(String queryString) { } @SuppressWarnings("unused") - public static class HttpRequestException extends Exception{ + public static class HttpRequestException extends Exception { private final int errorCode; private final String errorMessage; private boolean revealError = true; - public HttpRequestException(int errorCode, String errorMessage){ + public HttpRequestException(int errorCode, String errorMessage) { this.errorCode = errorCode; this.errorMessage = errorMessage; } - public int getErrorCode(){ + public int getErrorCode() { return errorCode; } - public String getErrorMessage(){ + public String getErrorMessage() { return errorMessage; } - public boolean shouldRevealError(){ + public boolean shouldRevealError() { return revealError; } - public void setRevealError(boolean revealError){ + public void setRevealError(boolean revealError) { this.revealError = revealError; } - public void transmitToClient(HttpExchange exchange) throws IOException{ + public void transmitToClient(HttpExchange exchange) throws IOException { HttpResponse response; - if(!revealError){ + if (!revealError) { response = new HttpResponse(500, "Internal Server Error", "text/plain"); sendResponse(exchange, response); } diff --git a/GlobalQuakeServer/src/main/java/gqserver/fdsnws_event/EventsV1ParamChecks.java b/GlobalQuakeServer/src/main/java/gqserver/fdsnws_event/EventsV1ParamChecks.java index 2b043ebc9..64c1af781 100644 --- a/GlobalQuakeServer/src/main/java/gqserver/fdsnws_event/EventsV1ParamChecks.java +++ b/GlobalQuakeServer/src/main/java/gqserver/fdsnws_event/EventsV1ParamChecks.java @@ -10,14 +10,14 @@ public class EventsV1ParamChecks { //2011-03-11T05:00:00 UTC - static public Date parseDate(String date){ + static public Date parseDate(String date) { //Takes a string in the format of "YYYY-MM-DDTHH:MM:SS" UTC time and returns a Date object SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); dateFormat.setTimeZone(java.util.TimeZone.getTimeZone("UTC")); Date parsedDate; - try{ + try { parsedDate = dateFormat.parse(date); - }catch(Exception e){ + } catch (Exception e) { return null; } return parsedDate; @@ -25,15 +25,15 @@ static public Date parseDate(String date){ //A bunch of fancy parseFloats that check for stuff - static public Float parseLatitude(String latitude){ + static public Float parseLatitude(String latitude) { //Takes a string in the format of "[-]DD.DD" and returns a Float object float parsedLatitude; - try{ + try { parsedLatitude = Float.parseFloat(latitude); - if(parsedLatitude > 90 || parsedLatitude < -90){ + if (parsedLatitude > 90 || parsedLatitude < -90) { return null; } - }catch(Exception e){ + } catch (Exception e) { return null; } @@ -42,42 +42,42 @@ static public Float parseLatitude(String latitude){ //radius - static public Float parseLongitude(String longitude){ + static public Float parseLongitude(String longitude) { //Takes a string in the format of "[-]DDD.DD" and returns a Float object float parsedLongitude; - try{ + try { parsedLongitude = Float.parseFloat(longitude); - if(parsedLongitude > 180 || parsedLongitude < -180){ + if (parsedLongitude > 180 || parsedLongitude < -180) { return null; } - }catch(Exception e){ + } catch (Exception e) { return null; } return parsedLongitude; } - static public Float parseDepth(String depth){ + static public Float parseDepth(String depth) { /*Takes a string and makes sure it is a valid depth *In the future, this will need an appropriate range check - */ + */ float parsedDepth; - try{ + try { parsedDepth = Float.parseFloat(depth); - }catch(Exception e){ + } catch (Exception e) { return null; } return parsedDepth; } - static public Float parseMagnitude(String magnitude){ + static public Float parseMagnitude(String magnitude) { //Takes a string and makes sure it is a valid magnitude float parsedMagnitude; - try{ + try { parsedMagnitude = Float.parseFloat(magnitude); - if(parsedMagnitude > 10 || parsedMagnitude < -10){ + if (parsedMagnitude > 10 || parsedMagnitude < -10) { return null; } - }catch(Exception e){ + } catch (Exception e) { return null; } @@ -86,16 +86,16 @@ static public Float parseMagnitude(String magnitude){ //several other things - static public String parseFormat(String format) throws HttpRequestException{ + static public String parseFormat(String format) throws HttpRequestException { //Takes a string and makes sure it is a valid format List validFormats = Arrays.asList("quakeml", "geojson", "text", "json", "xml"); List disallowedDroids = Arrays.asList("xmlp", "geojsonp", "jsonp", "quakemlp", "textp"); - if(validFormats.contains(format)){ + if (validFormats.contains(format)) { return format; } - if(disallowedDroids.contains(format)){ + if (disallowedDroids.contains(format)) { throw new HttpRequestException(400, "Invalid format. The format " + format + " are not the droids you're looking for"); } @@ -104,15 +104,15 @@ static public String parseFormat(String format) throws HttpRequestException{ } - static public int parseNoData(String noData){ + static public int parseNoData(String noData) { //Takes a string and makes sure it is a valid nodata int parsedNoData; - try{ + try { parsedNoData = Integer.parseInt(noData); - if(parsedNoData > 999 || parsedNoData < 1){ + if (parsedNoData > 999 || parsedNoData < 1) { return 0; } - }catch(Exception e){ + } catch (Exception e) { return 0; } return parsedNoData; diff --git a/GlobalQuakeServer/src/main/java/gqserver/fdsnws_event/FdsnwsEventsHTTPServer.java b/GlobalQuakeServer/src/main/java/gqserver/fdsnws_event/FdsnwsEventsHTTPServer.java index 150c851b5..20ba3cfed 100644 --- a/GlobalQuakeServer/src/main/java/gqserver/fdsnws_event/FdsnwsEventsHTTPServer.java +++ b/GlobalQuakeServer/src/main/java/gqserver/fdsnws_event/FdsnwsEventsHTTPServer.java @@ -17,14 +17,14 @@ public class FdsnwsEventsHTTPServer { private final Duration clientCleanExitTime = Duration.ofSeconds(3); private FdsnwsEventsHTTPServer() { - if(instance != null){ + if (instance != null) { return; } serverRunning = false; server = null; } - private void initRoutes(){ + private void initRoutes() { server.createContext("/", new HttpCatchAllLogger()); EventsV1Handler ev1handler = new EventsV1Handler(); @@ -41,7 +41,7 @@ public static FdsnwsEventsHTTPServer getInstance() { } public void startServer() throws Exception { - if(serverRunning){ + if (serverRunning) { Logger.warn("fdsnws_event Server was attempted to be started but was already running"); return; } @@ -63,7 +63,7 @@ public void stopServer() { return; } - server.stop((int)clientCleanExitTime.getSeconds()); + server.stop((int) clientCleanExitTime.getSeconds()); serverRunning = false; Logger.info("fdsnws_event Server stopped"); } diff --git a/GlobalQuakeServer/src/main/java/gqserver/fdsnws_event/HttpCatchAllLogger.java b/GlobalQuakeServer/src/main/java/gqserver/fdsnws_event/HttpCatchAllLogger.java index f8ae7f2b9..a96916c81 100644 --- a/GlobalQuakeServer/src/main/java/gqserver/fdsnws_event/HttpCatchAllLogger.java +++ b/GlobalQuakeServer/src/main/java/gqserver/fdsnws_event/HttpCatchAllLogger.java @@ -1,6 +1,7 @@ package gqserver.fdsnws_event; import java.io.IOException; + import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; @@ -11,7 +12,7 @@ public class HttpCatchAllLogger implements HttpHandler { @Override public void handle(HttpExchange exchange) throws IOException { logIncomingRequest(exchange); - + exchange.sendResponseHeaders(404, 0); //set status code to 404 exchange.close(); //send 404 and close connection } @@ -26,5 +27,5 @@ public static void logIncomingRequest(HttpExchange exchange) { Logger.info("{} :: {} :: {} :: {}", requestProtocol, requestMethod, requestURI, requestIP); } - + } diff --git a/GlobalQuakeServer/src/main/java/gqserver/server/DataRequest.java b/GlobalQuakeServer/src/main/java/gqserver/server/DataRequest.java index 792f4002a..94325e0a2 100644 --- a/GlobalQuakeServer/src/main/java/gqserver/server/DataRequest.java +++ b/GlobalQuakeServer/src/main/java/gqserver/server/DataRequest.java @@ -45,7 +45,7 @@ public synchronized void enqueue(DataRecord dataRecord) { } public synchronized void sendAll() { - while(!dataRecordQueue.isEmpty()){ + while (!dataRecordQueue.isEmpty()) { DataRecord dataRecord = dataRecordQueue.remove(); client.queuePacket(new DataRecordPacket(station.getId(), dataRecord.toByteArray())); } diff --git a/GlobalQuakeServer/src/main/java/gqserver/server/DataService.java b/GlobalQuakeServer/src/main/java/gqserver/server/DataService.java index 6b8cee357..098785c65 100644 --- a/GlobalQuakeServer/src/main/java/gqserver/server/DataService.java +++ b/GlobalQuakeServer/src/main/java/gqserver/server/DataService.java @@ -62,9 +62,9 @@ public DataService() { currentEarthquakes = new ConcurrentLinkedQueue<>(); } - public void run(){ + public void run() { GlobalQuakeServer.instance.getEventHandler().registerEventListener(this); - GlobalQuakeServer.instance.getServerEventHandler().registerEventListener(new GlobalQuakeServerEventListener(){ + GlobalQuakeServer.instance.getServerEventHandler().registerEventListener(new GlobalQuakeServerEventListener() { @Override public void onClientLeave(ClientLeftEvent event) { clientDataRequestMap.remove(event.client()); @@ -79,9 +79,9 @@ public void onClientLeave(ClientLeftEvent event) { } private void cleanup() { - synchronized (stationDataQueueLock){ - for(Queue queue : stationDataQueueMap.values()){ - while(!queue.isEmpty() && isOld(queue.peek())){ + synchronized (stationDataQueueLock) { + for (Queue queue : stationDataQueueMap.values()) { + while (!queue.isEmpty() && isOld(queue.peek())) { queue.remove(); } } @@ -95,8 +95,8 @@ private void cleanup() { for (Iterator iterator = currentEarthquakes.iterator(); iterator.hasNext(); ) { EarthquakeInfo earthquakeInfo = iterator.next(); - for(Earthquake earthquake : GlobalQuake.instance.getEarthquakeAnalysis().getEarthquakes()){ - if(earthquake.getUuid().equals(earthquakeInfo.uuid())){ + for (Earthquake earthquake : GlobalQuake.instance.getEarthquakeAnalysis().getEarthquakes()) { + if (earthquake.getUuid().equals(earthquakeInfo.uuid())) { continue mainloop; } } @@ -115,7 +115,7 @@ private boolean isOld(DataRecord dataRecord) { Instant.ofEpochMilli(GlobalQuake.instance.currentTimeMillis()).minus(Settings.logsStoreTimeMinutes, ChronoUnit.MINUTES)); } - public StationStatus createStatus(AbstractStation station){ + public StationStatus createStatus(AbstractStation station) { return new StationStatus(station.isInEventMode(), station.hasDisplayableData(), (float) station.getMaxRatio60S()); } @@ -137,7 +137,7 @@ private void sendIntensityData() { if (!data.isEmpty()) { broadcast(getStationReceivingClients(), new StationsIntensityPacket(GlobalQuake.instance.getStationManager().getIndexing(), GlobalQuake.instance.currentTimeMillis(), data)); } - } catch(Exception e){ + } catch (Exception e) { Logger.tag("Server").error(e); } } @@ -162,7 +162,7 @@ public void onQuakeRemove(QuakeRemoveEvent event) { public void onQuakeUpdate(QuakeUpdateEvent event) { Earthquake earthquake = event.earthquake(); - if(earthquake == null){ + if (earthquake == null) { return; } @@ -188,21 +188,21 @@ public void onNewData(SeedlinkDataEvent seedlinkDataEvent) { stationDataQueueMap.get(station).add(record); } - for(var kv : clientDataRequestMap.entrySet()){ - for(DataRequest dr : kv.getValue()){ - if(dr.getStation().getId() == station.getId()){ + for (var kv : clientDataRequestMap.entrySet()) { + for (DataRequest dr : kv.getValue()) { + if (dr.getStation().getId() == station.getId()) { dr.enqueue(record); - if(dr.getQueueSize() > 20 && !dr.ready) { + if (dr.getQueueSize() > 20 && !dr.ready) { Logger.tag("Server").warn("Client data queue exceeded a certain limit, sending everyting..."); dr.ready = true; } - if(dr.getQueueSize() > 30){ + if (dr.getQueueSize() > 30) { Logger.tag("Server").warn("Client data queue exceeded another limit, clearing it!"); dr.clear(); } - if(dr.ready){ + if (dr.ready) { dr.sendAll(); } } @@ -237,7 +237,7 @@ private Packet createArchivedPacket(ArchivedQuake archivedQuake) { private List createArchivedEventsData(ArrayList archivedEvents) { List result = new ArrayList<>(); - for(ArchivedEvent archivedEvent : archivedEvents){ + for (ArchivedEvent archivedEvent : archivedEvents) { result.add(new ArchivedEventData( (float) archivedEvent.lat(), (float) archivedEvent.lon(), @@ -253,8 +253,8 @@ private Packet createQuakePacket(Earthquake earthquake) { private AdvancedHypocenterData createAdvancedHypocenterData(Earthquake earthquake) { Hypocenter hypocenter = earthquake.getHypocenter(); - if(hypocenter == null || hypocenter.quality == null || - hypocenter.polygonConfidenceIntervals == null || hypocenter.depthConfidenceInterval == null){ + if (hypocenter == null || hypocenter.quality == null || + hypocenter.polygonConfidenceIntervals == null || hypocenter.depthConfidenceInterval == null) { return null; } @@ -268,7 +268,7 @@ private AdvancedHypocenterData createAdvancedHypocenterData(Earthquake earthquak private List createMagsData(Hypocenter hypocenter) { List result = new ArrayList<>(); - for(MagnitudeReading magnitudeReading : hypocenter.mags){ + for (MagnitudeReading magnitudeReading : hypocenter.mags) { result.add((float) magnitudeReading.magnitude()); } @@ -277,7 +277,7 @@ private List createMagsData(Hypocenter hypocenter) { private StationCountData createStationCountData(Cluster cluster) { Hypocenter previousHypocenter = cluster.getPreviousHypocenter(); - if(previousHypocenter == null){ + if (previousHypocenter == null) { return null; } @@ -290,7 +290,7 @@ private StationCountData createStationCountData(Cluster cluster) { private LocationConfidenceIntervalData createLocationConfidenceData(List intervals) { List list = new ArrayList<>(); - for(PolygonConfidenceInterval interval : intervals){ + for (PolygonConfidenceInterval interval : intervals) { list.add(new PolygonConfidenceIntervalData( interval.n(), (float) interval.offset(), @@ -332,11 +332,11 @@ private void broadcast(List clients, Packet packet) { }); } - private List getEarthquakeReceivingClients(){ + private List getEarthquakeReceivingClients() { return getClients().stream().filter(serverClient -> serverClient.getClientConfig().earthquakeData()).toList(); } - private List getStationReceivingClients(){ + private List getStationReceivingClients() { return getClients().stream().filter(serverClient -> serverClient.getClientConfig().stationData()).toList(); } @@ -351,25 +351,25 @@ public void processPacket(ServerClient client, Packet packet) { processEarthquakeRequest(client, earthquakeRequestPacket); } else if (packet instanceof ArchivedQuakesRequestPacket) { processArchivedQuakesRequest(client); - } else if(packet instanceof StationsRequestPacket){ + } else if (packet instanceof StationsRequestPacket) { processStationsRequestPacket(client); - } else if(packet instanceof DataRequestPacket dataRequestPacket){ + } else if (packet instanceof DataRequestPacket dataRequestPacket) { processDataRequest(client, dataRequestPacket); } } - private void processDataRequest(ServerClient client, DataRequestPacket packet){ + private void processDataRequest(ServerClient client, DataRequestPacket packet) { stationMap.putIfAbsent(packet.station(), (GlobalStation) GlobalQuake.instance.getStationManager().getStationByIdentifier(packet.station())); GlobalStation station = stationMap.get(packet.station()); - if(station == null){ + if (station == null) { Logger.tag("Server").warn("Received data request for non-existing station!"); return; } clientDataRequestMap.putIfAbsent(client, new HashSet<>()); Set dataRequests = clientDataRequestMap.get(client); - if(!packet.cancel()) { - if(dataRequests.size() >= DATA_REQUESTS_MAX_COUNT){ + if (!packet.cancel()) { + if (dataRequests.size() >= DATA_REQUESTS_MAX_COUNT) { Logger.tag("Server").warn("Too many data requests for client #%d!".formatted(client.getID())); } else { sendDataRequest(dataRequests, new DataRequest(station, client)); @@ -380,7 +380,7 @@ private void processDataRequest(ServerClient client, DataRequestPacket packet){ } private void sendDataRequest(Set dataRequests, DataRequest dataRequest) { - if(!dataRequests.add(dataRequest)){ + if (!dataRequests.add(dataRequest)) { // data request from that client to this station already exists return; } @@ -388,11 +388,11 @@ private void sendDataRequest(Set dataRequests, DataRequest dataRequ Queue dataRecords = new PriorityQueue<>(getDataRecordComparator()); Queue data = stationDataQueueMap.get(dataRequest.getStation()); - if(data != null){ + if (data != null) { dataRecords.addAll(data); } - while(!dataRecords.isEmpty()){ + while (!dataRecords.isEmpty()) { DataRecord dataRecord = dataRecords.remove(); dataRequest.enqueue(dataRecord); } @@ -403,40 +403,40 @@ private void sendDataRequest(Set dataRequests, DataRequest dataRequ private void processStationsRequestPacket(ServerClient client) { List data = new ArrayList<>(); - for (AbstractStation station : GlobalQuake.instance.getStationManager().getStations()){ + for (AbstractStation station : GlobalQuake.instance.getStationManager().getStations()) { data.add(new StationInfoData( - station.getId(), - (float) station.getLatitude(), - (float) station.getLongitude(), - station.getNetworkCode(), - station.getStationCode(), - station.getChannelName(), - station.getLocationCode(), - GlobalQuake.instance.currentTimeMillis(), - (float) station.getMaxRatio60S(), - station.isInEventMode(), - station.getInputType() - )); - if(data.size() >= STATIONS_INFO_PACKET_MAX_SIZE){ + station.getId(), + (float) station.getLatitude(), + (float) station.getLongitude(), + station.getNetworkCode(), + station.getStationCode(), + station.getChannelName(), + station.getLocationCode(), + GlobalQuake.instance.currentTimeMillis(), + (float) station.getMaxRatio60S(), + station.isInEventMode(), + station.getInputType() + )); + if (data.size() >= STATIONS_INFO_PACKET_MAX_SIZE) { client.queuePacket(new StationsInfoPacket(GlobalQuake.instance.getStationManager().getIndexing(), data)); data = new ArrayList<>(); } } - if(!data.isEmpty()){ + if (!data.isEmpty()) { client.queuePacket(new StationsInfoPacket(GlobalQuake.instance.getStationManager().getIndexing(), data)); } } private void processArchivedQuakesRequest(ServerClient client) { - for(ArchivedQuake archivedQuake : GlobalQuake.instance.getArchive().getArchivedQuakes()){ + for (ArchivedQuake archivedQuake : GlobalQuake.instance.getArchive().getArchivedQuakes()) { client.queuePacket(createArchivedPacket(archivedQuake)); } } private void processEarthquakeRequest(ServerClient client, EarthquakeRequestPacket earthquakeRequestPacket) { - for(Earthquake earthquake : GlobalQuakeServer.instance.getEarthquakeAnalysis().getEarthquakes()){ - if(earthquake.getUuid().equals(earthquakeRequestPacket.uuid())){ + for (Earthquake earthquake : GlobalQuakeServer.instance.getEarthquakeAnalysis().getEarthquakes()) { + if (earthquake.getUuid().equals(earthquakeRequestPacket.uuid())) { client.queuePacket(createQuakePacket(earthquake)); return; } diff --git a/GlobalQuakeServer/src/main/java/gqserver/server/GQServerSocket.java b/GlobalQuakeServer/src/main/java/gqserver/server/GQServerSocket.java index deb462300..db9ee4679 100644 --- a/GlobalQuakeServer/src/main/java/gqserver/server/GQServerSocket.java +++ b/GlobalQuakeServer/src/main/java/gqserver/server/GQServerSocket.java @@ -80,7 +80,7 @@ public void run(String ip, int port) { clientsLimitWatchdog.scheduleAtFixedRate(this::updateLimits, 0, 60, TimeUnit.SECONDS); acceptService.submit(this::runAccept); - if(Main.isHeadless()){ + if (Main.isHeadless()) { statusReportingService.scheduleAtFixedRate(this::printStatus, 0, 30, TimeUnit.SECONDS); } @@ -110,7 +110,7 @@ private void printStatus() { if (stats != null) { Logger.tag("ServerStatus").info( "accepted: %d, wrongVersion: %d, wrongPacket: %d, serverFull: %d, success: %d, error: %d, ipRejects: %d" - .formatted(stats.accepted, stats.wrongVersion, stats.wrongPacket, stats.serverFull, stats.successfull, stats.errors, stats.ipRejects)); + .formatted(stats.accepted, stats.wrongVersion, stats.wrongPacket, stats.serverFull, stats.successfull, stats.errors, stats.ipRejects)); } } @@ -131,7 +131,7 @@ private void checkClients() { } } clients.removeAll(toRemove); - }catch(Exception e) { + } catch (Exception e) { Logger.tag("Server").error(e); } } @@ -229,7 +229,7 @@ private void runAccept() { lastSocket.setSoTimeout(0); // we can wait for clients forever Socket socket = lastSocket.accept(); - if(!checkAddress(socket)){ + if (!checkAddress(socket)) { socket.close(); Logger.tag("Server").warn("Client rejected for reaching max connection count!"); stats.ipRejects++; @@ -246,7 +246,7 @@ private void runAccept() { try { client = new ServerClient(socket); Logger.tag("Server").info("Performing handshake for client #%d".formatted(client.getID())); - if(!handshake(client)){ + if (!handshake(client)) { clientLeft(socket); } } catch (IOException e) { diff --git a/GlobalQuakeServer/src/main/java/gqserver/server/StationStatus.java b/GlobalQuakeServer/src/main/java/gqserver/server/StationStatus.java index d438b7b10..00ffe06d3 100644 --- a/GlobalQuakeServer/src/main/java/gqserver/server/StationStatus.java +++ b/GlobalQuakeServer/src/main/java/gqserver/server/StationStatus.java @@ -2,7 +2,7 @@ import java.util.Objects; -public record StationStatus(boolean eventMode, boolean hasData, float intensity){ +public record StationStatus(boolean eventMode, boolean hasData, float intensity) { @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/GlobalQuakeServer/src/main/java/gqserver/ui/server/DatabaseMonitorFrame.java b/GlobalQuakeServer/src/main/java/gqserver/ui/server/DatabaseMonitorFrame.java index a5e3ab850..a47f839c9 100644 --- a/GlobalQuakeServer/src/main/java/gqserver/ui/server/DatabaseMonitorFrame.java +++ b/GlobalQuakeServer/src/main/java/gqserver/ui/server/DatabaseMonitorFrame.java @@ -141,14 +141,14 @@ public void actionPerformed(ActionEvent actionEvent) { bottomPanel.add(new StationCountPanel(manager, new GridLayout(2, 2))); - mainProgressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, 100); + mainProgressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, 100); mainProgressBar.setValue(0); mainProgressBar.setStringPainted(true); mainProgressBar.setString("Init..."); buttonsOutsidePanel.add(buttonsPanel); buttonsOutsidePanel.add(mainProgressBar); - + bottomPanel.add(buttonsOutsidePanel); return bottomPanel; } @@ -162,7 +162,7 @@ public void initDone() { } public JButton getBtnSelectStations() { - return btnSelectStations; + return btnSelectStations; } } diff --git a/GlobalQuakeServer/src/main/java/gqserver/ui/server/ServerStatusPanel.java b/GlobalQuakeServer/src/main/java/gqserver/ui/server/ServerStatusPanel.java index 8daf04513..404081cd9 100644 --- a/GlobalQuakeServer/src/main/java/gqserver/ui/server/ServerStatusPanel.java +++ b/GlobalQuakeServer/src/main/java/gqserver/ui/server/ServerStatusPanel.java @@ -42,35 +42,35 @@ private JPanel createTopPanel() { JPanel topPanel = new JPanel(); topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS)); - JPanel addressPanel = new JPanel(new GridLayout(2,1)); + JPanel addressPanel = new JPanel(new GridLayout(2, 1)); addressPanel.setBorder(BorderFactory.createTitledBorder("Server address")); JPanel ipPanel = new JPanel(); ipPanel.setLayout(new BoxLayout(ipPanel, BoxLayout.X_AXIS)); ipPanel.add(new JLabel("IP Address: ")); - ipPanel.add(addressField = new JTextField(Settings.lastServerIP,20)); + ipPanel.add(addressField = new JTextField(Settings.lastServerIP, 20)); addressPanel.add(ipPanel); JPanel portPanel = new JPanel(); portPanel.setLayout(new BoxLayout(portPanel, BoxLayout.X_AXIS)); portPanel.add(new JLabel("Port: ")); - portPanel.add(portField = new JTextField(String.valueOf(Settings.lastServerPORT),20)); + portPanel.add(portField = new JTextField(String.valueOf(Settings.lastServerPORT), 20)); addressPanel.add(portPanel); topPanel.add(addressPanel); - JPanel controlPanel = new JPanel(new GridLayout(2,1)); + JPanel controlPanel = new JPanel(new GridLayout(2, 1)); controlPanel.setBorder(BorderFactory.createTitledBorder("Control Panel")); controlPanel.add(statusLabel = new JLabel("Status: Idle")); controlPanel.add(controlButton = new JButton("Start Server")); - GlobalQuakeServer.instance.getServerEventHandler().registerEventListener(new GlobalQuakeServerEventListener(){ + GlobalQuakeServer.instance.getServerEventHandler().registerEventListener(new GlobalQuakeServerEventListener() { @Override public void onServerStatusChanged(ServerStatusChangedEvent event) { - switch (event.status()){ + switch (event.status()) { case IDLE -> { addressField.setEnabled(true); portField.setEnabled(true); @@ -96,7 +96,7 @@ public void onServerStatusChanged(ServerStatusChangedEvent event) { controlButton.addActionListener(actionEvent -> { SocketStatus status = GlobalQuakeServer.instance.getServerSocket().getStatus(); - if(status == SocketStatus.IDLE){ + if (status == SocketStatus.IDLE) { try { String ip = addressField.getText(); int port = Integer.parseInt(portField.getText()); @@ -108,11 +108,11 @@ public void onServerStatusChanged(ServerStatusChangedEvent event) { GlobalQuakeServer.instance.initStations(); GlobalQuakeServer.instance.getServerSocket().run(ip, port); GlobalQuakeServer.instance.startRuntime(); - } catch(Exception e){ + } catch (Exception e) { Main.getErrorHandler().handleException(new RuntimeApplicationException("Failed to start server", e)); } - } else if(status == SocketStatus.RUNNING) { - if(confirm("Are you sure you want to close the server?")) { + } else if (status == SocketStatus.RUNNING) { + if (confirm("Are you sure you want to close the server?")) { try { GlobalQuakeServer.instance.getServerSocket().stop(); GlobalQuakeServer.instance.stopRuntime(); diff --git a/GlobalQuakeServer/src/main/java/gqserver/ui/server/table/GQTable.java b/GlobalQuakeServer/src/main/java/gqserver/ui/server/table/GQTable.java index 2a4a25cbe..26bc774a5 100644 --- a/GlobalQuakeServer/src/main/java/gqserver/ui/server/table/GQTable.java +++ b/GlobalQuakeServer/src/main/java/gqserver/ui/server/table/GQTable.java @@ -8,7 +8,7 @@ public class GQTable extends JTable { - public GQTable(FilterableTableModel tableModel){ + public GQTable(FilterableTableModel tableModel) { super(tableModel); setFont(new Font("Arial", Font.PLAIN, 14)); setRowHeight(20); diff --git a/GlobalQuakeServer/src/main/java/gqserver/ui/server/tabs/ClientsTab.java b/GlobalQuakeServer/src/main/java/gqserver/ui/server/tabs/ClientsTab.java index 3856070f1..e79139a63 100644 --- a/GlobalQuakeServer/src/main/java/gqserver/ui/server/tabs/ClientsTab.java +++ b/GlobalQuakeServer/src/main/java/gqserver/ui/server/tabs/ClientsTab.java @@ -14,16 +14,16 @@ public class ClientsTab extends JPanel { - public ClientsTab(){ + public ClientsTab() { setLayout(new BorderLayout()); ClientsTableModel model; add(new JScrollPane(new GQTable<>( model = new ClientsTableModel(GlobalQuakeServer.instance.getServerSocket().getClients())))); - Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(model::applyFilter, 0,1, TimeUnit.SECONDS); + Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(model::applyFilter, 0, 1, TimeUnit.SECONDS); - GlobalQuakeServer.instance.getServerEventHandler().registerEventListener(new GlobalQuakeServerEventListener(){ + GlobalQuakeServer.instance.getServerEventHandler().registerEventListener(new GlobalQuakeServerEventListener() { @Override public void onClientLeave(ClientLeftEvent clientLeftEvent) { model.applyFilter(); diff --git a/GlobalQuakeServer/src/main/java/gqserver/ui/server/tabs/ClustersTab.java b/GlobalQuakeServer/src/main/java/gqserver/ui/server/tabs/ClustersTab.java index 37340204e..078875d91 100644 --- a/GlobalQuakeServer/src/main/java/gqserver/ui/server/tabs/ClustersTab.java +++ b/GlobalQuakeServer/src/main/java/gqserver/ui/server/tabs/ClustersTab.java @@ -11,14 +11,14 @@ public class ClustersTab extends JPanel { - public ClustersTab(){ + public ClustersTab() { setLayout(new BorderLayout()); ClusterTableModel model; add(new JScrollPane(new GQTable<>( model = new ClusterTableModel(GlobalQuakeServer.instance.getClusterAnalysis().getClusters())))); - Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(model::applyFilter, 0,1, TimeUnit.SECONDS); + Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(model::applyFilter, 0, 1, TimeUnit.SECONDS); } } diff --git a/GlobalQuakeServer/src/main/java/gqserver/ui/server/tabs/EarthquakesTab.java b/GlobalQuakeServer/src/main/java/gqserver/ui/server/tabs/EarthquakesTab.java index 47ca643f6..b4ce2a4db 100644 --- a/GlobalQuakeServer/src/main/java/gqserver/ui/server/tabs/EarthquakesTab.java +++ b/GlobalQuakeServer/src/main/java/gqserver/ui/server/tabs/EarthquakesTab.java @@ -14,14 +14,14 @@ public class EarthquakesTab extends JPanel { - public EarthquakesTab(){ + public EarthquakesTab() { setLayout(new BorderLayout()); EarthquakeTableModel model; add(new JScrollPane(new GQTable<>( model = new EarthquakeTableModel(GlobalQuakeServer.instance.getEarthquakeAnalysis().getEarthquakes())))); - GlobalQuakeServer.instance.getEventHandler().registerEventListener(new GlobalQuakeEventListener(){ + GlobalQuakeServer.instance.getEventHandler().registerEventListener(new GlobalQuakeEventListener() { @Override public void onQuakeUpdate(QuakeUpdateEvent event) { model.applyFilter(); diff --git a/GlobalQuakeServer/src/main/java/gqserver/ui/server/tabs/SeedlinksTab.java b/GlobalQuakeServer/src/main/java/gqserver/ui/server/tabs/SeedlinksTab.java index 3b65caca3..8399a73d5 100644 --- a/GlobalQuakeServer/src/main/java/gqserver/ui/server/tabs/SeedlinksTab.java +++ b/GlobalQuakeServer/src/main/java/gqserver/ui/server/tabs/SeedlinksTab.java @@ -11,14 +11,14 @@ public class SeedlinksTab extends JPanel { - public SeedlinksTab(){ + public SeedlinksTab() { setLayout(new BorderLayout()); SeedlinkStatusTableModel model; add(new JScrollPane(new GQTable<>( model = new SeedlinkStatusTableModel(GlobalQuakeServer.instance.getStationDatabaseManager().getStationDatabase().getSeedlinkNetworks())))); - Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(model::applyFilter, 0,1, TimeUnit.SECONDS); + Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(model::applyFilter, 0, 1, TimeUnit.SECONDS); } } diff --git a/GlobalQuakeServer/src/main/java/gqserver/ui/server/tabs/StatusTab.java b/GlobalQuakeServer/src/main/java/gqserver/ui/server/tabs/StatusTab.java index 1a0006af7..1c4848606 100644 --- a/GlobalQuakeServer/src/main/java/gqserver/ui/server/tabs/StatusTab.java +++ b/GlobalQuakeServer/src/main/java/gqserver/ui/server/tabs/StatusTab.java @@ -22,30 +22,30 @@ public class StatusTab extends JPanel { private final JProgressBar ramProgressBar; public StatusTab() { - setLayout(new GridLayout(4,1)); + setLayout(new GridLayout(4, 1)); long maxMem = Runtime.getRuntime().maxMemory(); - clientsProgressBar = new JProgressBar(JProgressBar.HORIZONTAL,0, Settings.maxClients); + clientsProgressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, Settings.maxClients); clientsProgressBar.setStringPainted(true); add(clientsProgressBar); - seedlinksProgressBar = new JProgressBar(JProgressBar.HORIZONTAL,0, 10); + seedlinksProgressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, 10); seedlinksProgressBar.setStringPainted(true); add(seedlinksProgressBar); - stationsProgressBar = new JProgressBar(JProgressBar.HORIZONTAL,0, 10); + stationsProgressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, 10); stationsProgressBar.setStringPainted(true); add(stationsProgressBar); - ramProgressBar = new JProgressBar(JProgressBar.HORIZONTAL,0, (int) (maxMem / MB)); + ramProgressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, (int) (maxMem / MB)); ramProgressBar.setStringPainted(true); add(ramProgressBar); updateRamProgressBar(); updateClientsProgressBar(); - GlobalQuakeServer.instance.getServerEventHandler().registerEventListener(new GlobalQuakeServerEventListener(){ + GlobalQuakeServer.instance.getServerEventHandler().registerEventListener(new GlobalQuakeServerEventListener() { @Override public void onClientJoin(ClientJoinedEvent clientJoinedEvent) { updateClientsProgressBar(); @@ -57,7 +57,10 @@ public void onClientLeave(ClientLeftEvent clientLeftEvent) { } }); - Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> {updateRamProgressBar();updateStations();}, 0, 100, TimeUnit.MILLISECONDS); + Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> { + updateRamProgressBar(); + updateStations(); + }, 0, 100, TimeUnit.MILLISECONDS); } private synchronized void updateStations() { diff --git a/GlobalQuakeServer/src/test/java/gqserver/server/GQServerSocketTest.java b/GlobalQuakeServer/src/test/java/gqserver/server/GQServerSocketTest.java index e176a3589..c53764963 100644 --- a/GlobalQuakeServer/src/test/java/gqserver/server/GQServerSocketTest.java +++ b/GlobalQuakeServer/src/test/java/gqserver/server/GQServerSocketTest.java @@ -16,7 +16,7 @@ public class GQServerSocketTest { public static void main(String[] args) throws InterruptedException { var pool = Executors.newFixedThreadPool(100); - for(int i = 0; i < 100; i++){ + for (int i = 0; i < 100; i++) { pool.submit(() -> { try { ddos(); @@ -27,15 +27,15 @@ public static void main(String[] args) throws InterruptedException { } } - public static void ddos() throws IOException, InterruptedException{ - Socket socket = new Socket(); + public static void ddos() throws IOException, InterruptedException { + Socket socket = new Socket(); socket.connect(new InetSocketAddress("0.0.0.0", 12345)); ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream()); out.writeObject(new HandshakePacket(GQApi.COMPATIBILITY_VERSION, new ServerClientConfig(false, false))); - while(true){ + while (true) { Thread.sleep(1000); out.writeObject(new HeartbeatPacket()); }