diff --git a/src/main/java/mpo/dayon/assistant/gui/Assistant.java b/src/main/java/mpo/dayon/assistant/gui/Assistant.java index afd5ee88..367edeaf 100644 --- a/src/main/java/mpo/dayon/assistant/gui/Assistant.java +++ b/src/main/java/mpo/dayon/assistant/gui/Assistant.java @@ -210,12 +210,9 @@ public void actionPerformed(ActionEvent ev) { final Cursor cursor = frame.getCursor(); frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { - publicIp = UPnP.getExternalIP(); - if (isInvalidPublicIp()) { - final URL url = new URL(WHATSMYIP_SERVER_URL); - try (final BufferedReader lines = new BufferedReader(new InputStreamReader(url.openStream()))) { - publicIp = lines.readLine(); - } + resolvePublicIp(); + if (publicIp != null) { + button.setText(publicIp); } } catch (IOException ex) { Log.error("Could not determine public IP", ex); @@ -224,9 +221,6 @@ public void actionPerformed(ActionEvent ev) { } finally { frame.setCursor(cursor); } - if (publicIp != null) { - button.setText(publicIp); - } }); choices.add(menuItem); } else { @@ -265,8 +259,14 @@ public void actionPerformed(ActionEvent ev) { choices.setLocation(choicesLocation.x - xOffset, choicesLocation.y + yOffset); } - private boolean isInvalidPublicIp() { - return publicIp == null || publicIp.startsWith("192.168") || publicIp.startsWith("10."); + private void resolvePublicIp() throws IOException { + publicIp = UPnP.getExternalIP(); + if (publicIp == null || publicIp.startsWith("192.168") || publicIp.startsWith("10.")) { + final URL url = new URL(WHATSMYIP_SERVER_URL); + try (final BufferedReader lines = new BufferedReader(new InputStreamReader(url.openStream()))) { + publicIp = lines.readLine(); + } + } } }; ip.putValue("DISPLAY_NAME", "127.0.0.1"); // always a selection @@ -312,7 +312,7 @@ private Action createNetworkAssistantConfigurationAction(Assistant assistant) { @Override public void actionPerformed(ActionEvent ev) { JFrame networkFrame = (JFrame) SwingUtilities.getRoot((Component) ev.getSource()); - String upnpActive = String.valueOf(assistant.isUpnpEnabled()); + String upnpActive = valueOf(assistant.isUpnpEnabled()); final JPanel pane = new JPanel(); pane.setLayout(new GridLayout(4, 1, 10, -10)); diff --git a/src/main/java/mpo/dayon/common/babylon/Babylon.java b/src/main/java/mpo/dayon/common/babylon/Babylon.java index 8094fe60..a9d7896a 100644 --- a/src/main/java/mpo/dayon/common/babylon/Babylon.java +++ b/src/main/java/mpo/dayon/common/babylon/Babylon.java @@ -22,7 +22,7 @@ public static synchronized String translate(String tag, Object... arguments) { String value; try { value = bundle.getString(tag); - if (value.trim().length() == 0) { + if (value.trim().isEmpty()) { value = tag; } } catch (MissingResourceException ignored) { diff --git a/src/main/java/mpo/dayon/common/squeeze/RegularTileCache.java b/src/main/java/mpo/dayon/common/squeeze/RegularTileCache.java index 9f4ea7c3..786aa812 100644 --- a/src/main/java/mpo/dayon/common/squeeze/RegularTileCache.java +++ b/src/main/java/mpo/dayon/common/squeeze/RegularTileCache.java @@ -86,7 +86,7 @@ public void clear() { */ @Override public void onCaptureProcessed() { - if (tiles.size() > 0 && tiles.size() >= maxSize) { + if (!tiles.isEmpty() && tiles.size() >= maxSize) { Log.info("Purging the cache..."); while (tiles.size() > purgeSize) { tiles.remove(lru.removeFirst());