Skip to content

Commit 32202a2

Browse files
authored
Format code for #1938 (#1942)
1 parent 6ee3291 commit 32202a2

File tree

2 files changed

+14
-15
lines changed
  • elasticjob-infra/elasticjob-infra-common/src
    • main/java/org/apache/shardingsphere/elasticjob/infra/env
    • test/java/org/apache/shardingsphere/elasticjob/infra/env

2 files changed

+14
-15
lines changed

elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/env/IpUtils.java

+9-10
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
import lombok.NoArgsConstructor;
2222

2323
import java.io.IOException;
24+
import java.net.Inet6Address;
2425
import java.net.InetAddress;
2526
import java.net.NetworkInterface;
2627
import java.net.SocketException;
2728
import java.net.UnknownHostException;
28-
import java.net.Inet6Address;
2929
import java.util.Enumeration;
3030
import java.util.LinkedList;
3131
import java.util.List;
@@ -40,9 +40,9 @@ public final class IpUtils {
4040
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})";
4141

4242
public static final String PREFERRED_NETWORK_INTERFACE = "elasticjob.preferred.network.interface";
43-
43+
4444
public static final String PREFERRED_NETWORK_IP = "elasticjob.preferred.network.ip";
45-
45+
4646
private static volatile String cachedIpAddress;
4747

4848
private static volatile String cachedHostName;
@@ -97,7 +97,7 @@ private static NetworkInterface findNetworkInterface() {
9797
}
9898
return result;
9999
}
100-
100+
101101
private static NetworkInterface getFirstNetworkInterface(final List<NetworkInterface> validNetworkInterfaces) {
102102
NetworkInterface result = null;
103103
for (NetworkInterface each : validNetworkInterfaces) {
@@ -115,7 +115,7 @@ private static NetworkInterface getFirstNetworkInterface(final List<NetworkInter
115115
}
116116
return result;
117117
}
118-
118+
119119
private static boolean isPreferredNetworkInterface(final NetworkInterface networkInterface) {
120120
String preferredNetworkInterface = System.getProperty(PREFERRED_NETWORK_INTERFACE);
121121
return Objects.equals(networkInterface.getDisplayName(), preferredNetworkInterface);
@@ -131,17 +131,16 @@ private static boolean ignoreNetworkInterface(final NetworkInterface networkInte
131131
return true;
132132
}
133133
}
134-
134+
135135
private static boolean isPreferredAddress(final InetAddress inetAddress) {
136136
String preferredNetworkIp = System.getProperty(PREFERRED_NETWORK_IP);
137-
if (preferredNetworkIp == null) {
137+
if (null == preferredNetworkIp) {
138138
return true;
139139
}
140-
141140
String hostAddress = inetAddress.getHostAddress();
142-
return hostAddress.matches(preferredNetworkIp) || hostAddress.startsWith(preferredNetworkIp);
141+
return hostAddress.startsWith(preferredNetworkIp) || hostAddress.matches(preferredNetworkIp);
143142
}
144-
143+
145144
private static boolean isValidAddress(final InetAddress inetAddress) {
146145
try {
147146
return !inetAddress.isLoopbackAddress() && !inetAddress.isAnyLocalAddress()

elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/env/IpUtilsTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
import java.util.List;
3030
import java.util.Vector;
3131

32+
import static org.hamcrest.CoreMatchers.is;
3233
import static org.junit.Assert.assertFalse;
3334
import static org.junit.Assert.assertNotNull;
3435
import static org.junit.Assert.assertThat;
35-
import static org.hamcrest.CoreMatchers.is;
3636
import static org.junit.Assert.assertTrue;
3737
import static org.mockito.Mockito.mock;
3838
import static org.mockito.Mockito.when;
@@ -43,7 +43,7 @@ public final class IpUtilsTest {
4343
public void assertGetIp() {
4444
assertNotNull(IpUtils.getIp());
4545
}
46-
46+
4747
@Test
4848
@SneakyThrows
4949
public void assertPreferredNetworkInterface() {
@@ -56,7 +56,7 @@ public void assertPreferredNetworkInterface() {
5656
assertTrue(result);
5757
System.clearProperty(IpUtils.PREFERRED_NETWORK_INTERFACE);
5858
}
59-
59+
6060
@Test
6161
@SneakyThrows
6262
public void assertPreferredNetworkAddress() {
@@ -76,7 +76,7 @@ public void assertPreferredNetworkAddress() {
7676
assertFalse((boolean) declaredMethod.invoke("isPreferredAddress", inetAddress));
7777
System.clearProperty(IpUtils.PREFERRED_NETWORK_IP);
7878
}
79-
79+
8080
@Test
8181
@SneakyThrows
8282
public void assertGetFirstNetworkInterface() {
@@ -111,7 +111,7 @@ public void assertGetFirstNetworkInterface() {
111111
assertThat(declaredMethod.invoke("getFirstNetworkInterface", validNetworkInterfaces), is(networkInterface1));
112112
System.clearProperty(IpUtils.PREFERRED_NETWORK_IP);
113113
}
114-
114+
115115
@Test
116116
@SneakyThrows
117117
public void assertGetHostName() {

0 commit comments

Comments
 (0)