Format code for #1938 (#1942)
diff --git a/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/env/IpUtils.java b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/env/IpUtils.java
index 15c5797..42acc70 100644
--- a/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/env/IpUtils.java
+++ b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/env/IpUtils.java
@@ -21,11 +21,11 @@
import lombok.NoArgsConstructor;
import java.io.IOException;
+import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
-import java.net.Inet6Address;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
@@ -40,9 +40,9 @@
public static final String IP_REGEX = "((\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)){3})";
public static final String PREFERRED_NETWORK_INTERFACE = "elasticjob.preferred.network.interface";
-
+
public static final String PREFERRED_NETWORK_IP = "elasticjob.preferred.network.ip";
-
+
private static volatile String cachedIpAddress;
private static volatile String cachedHostName;
@@ -97,7 +97,7 @@
}
return result;
}
-
+
private static NetworkInterface getFirstNetworkInterface(final List<NetworkInterface> validNetworkInterfaces) {
NetworkInterface result = null;
for (NetworkInterface each : validNetworkInterfaces) {
@@ -115,7 +115,7 @@
}
return result;
}
-
+
private static boolean isPreferredNetworkInterface(final NetworkInterface networkInterface) {
String preferredNetworkInterface = System.getProperty(PREFERRED_NETWORK_INTERFACE);
return Objects.equals(networkInterface.getDisplayName(), preferredNetworkInterface);
@@ -131,17 +131,16 @@
return true;
}
}
-
+
private static boolean isPreferredAddress(final InetAddress inetAddress) {
String preferredNetworkIp = System.getProperty(PREFERRED_NETWORK_IP);
- if (preferredNetworkIp == null) {
+ if (null == preferredNetworkIp) {
return true;
}
-
String hostAddress = inetAddress.getHostAddress();
- return hostAddress.matches(preferredNetworkIp) || hostAddress.startsWith(preferredNetworkIp);
+ return hostAddress.startsWith(preferredNetworkIp) || hostAddress.matches(preferredNetworkIp);
}
-
+
private static boolean isValidAddress(final InetAddress inetAddress) {
try {
return !inetAddress.isLoopbackAddress() && !inetAddress.isAnyLocalAddress()
diff --git a/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/env/IpUtilsTest.java b/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/env/IpUtilsTest.java
index 29e8014..dccd668 100644
--- a/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/env/IpUtilsTest.java
+++ b/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/env/IpUtilsTest.java
@@ -29,10 +29,10 @@
import java.util.List;
import java.util.Vector;
+import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
-import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -43,7 +43,7 @@
public void assertGetIp() {
assertNotNull(IpUtils.getIp());
}
-
+
@Test
@SneakyThrows
public void assertPreferredNetworkInterface() {
@@ -56,7 +56,7 @@
assertTrue(result);
System.clearProperty(IpUtils.PREFERRED_NETWORK_INTERFACE);
}
-
+
@Test
@SneakyThrows
public void assertPreferredNetworkAddress() {
@@ -76,7 +76,7 @@
assertFalse((boolean) declaredMethod.invoke("isPreferredAddress", inetAddress));
System.clearProperty(IpUtils.PREFERRED_NETWORK_IP);
}
-
+
@Test
@SneakyThrows
public void assertGetFirstNetworkInterface() {
@@ -111,7 +111,7 @@
assertThat(declaredMethod.invoke("getFirstNetworkInterface", validNetworkInterfaces), is(networkInterface1));
System.clearProperty(IpUtils.PREFERRED_NETWORK_IP);
}
-
+
@Test
@SneakyThrows
public void assertGetHostName() {