mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix bug;
This commit is contained in:
parent
e2266f593f
commit
3b3871ba1e
@ -2,6 +2,7 @@ package cn.hutool.core.net;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.map.BiMap;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
@ -83,6 +84,6 @@ public class MaskBit {
|
||||
*/
|
||||
public static long getMaskIpLong(final int maskBit) {
|
||||
Assert.isTrue(MASK_BIT_MAP.containsKey(maskBit), "非法的掩码位数:{}", maskBit);
|
||||
return -1L << (32 - maskBit);
|
||||
return (0xffffffffL << (32 - maskBit)) & 0xffffffffL;
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ public class Ipv4UtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ipv4ToLongTest(){
|
||||
public void ipv4ToLongTest() {
|
||||
long l = Ipv4Util.ipv4ToLong("127.0.0.1");
|
||||
Assert.assertEquals(2130706433L, l);
|
||||
l = Ipv4Util.ipv4ToLong("114.114.114.114");
|
||||
@ -132,6 +132,13 @@ public class Ipv4UtilTest {
|
||||
Assert.assertEquals(4294967295L, l);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaskIpLongTest() {
|
||||
for (int i = 1; i <= 32; i++) {
|
||||
Assert.assertEquals(Ipv4Util.ipv4ToLong(MaskBit.get(i)), MaskBit.getMaskIpLong(i));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private void testGenerateIpList(final String fromIp, final String toIp) {
|
||||
Assert.assertEquals(
|
||||
|
Loading…
x
Reference in New Issue
Block a user