/** * Gets next IP address. If the IP address doesn't have next IP then return <code>null</code>. * * @return Next IP address. */ public IP nextIP() { return new IP(value + 1); }
/** * Gets previous IP address. If the IP address doesn't have previous IP then return * <code>null</code>. * * @return Previous IP address. */ public IP preIP() { return new IP(value - 1); }
/** * Gets minimum IP which represents <b>0.0.0.0</b>. * * @return Minimum IP address. */ public static IP MIN_IP() { return new IP(0L); }
/** * Gets max IP which represents <b>255.255.255.255]</b>. * * @return Max IP address. */ public static IP MAX_IP() { return new IP(0xffffffffL); }
/** * Gets previous IP address. If the IP address doesn't have previous IP then return * <code>null</code>. * * @return Previous IP address. */ public IP preIP() { return new IP(value - 1); }
/** * Gets next IP address. If the IP address doesn't have next IP then return <code>null</code>. * * @return Next IP address. */ public IP nextIP() { return new IP(value + 1); }
/** * Gets max IP which represents <b>255.255.255.255]</b>. * * @return Max IP address. */ public static IP MAX_IP() { return new IP(0xffffffffL); }
/** * Gets minimum IP which represents <b>0.0.0.0</b>. * * @return Minimum IP address. */ public static IP MIN_IP() { return new IP(0L); }
public static IP toIP(SocketAddress socketAddress) { if (socketAddress instanceof InetSocketAddress) { byte[] address = ((InetSocketAddress) socketAddress).getAddress().getAddress(); return new IP(address); } else { throw new IllegalArgumentException("Not support type:" + socketAddress.getClass().getName()); } }
public static IP toIP(SocketAddress socketAddress){ if (socketAddress instanceof InetSocketAddress){ byte[] address = ((InetSocketAddress) socketAddress).getAddress().getAddress(); return new IP(address); }else{ throw new IllegalArgumentException("Not support type:" + socketAddress.getClass().getName()); } }
public boolean contains(InetAddress address) { if (address instanceof Inet4Address) { IP ip = new IP(address.getAddress()); return contains(ip); } return false; }
public boolean contains(InetAddress address){ if (address instanceof Inet4Address){ IP ip = new IP(address.getAddress()); return contains(ip); } return false; }
/** * Creates a IP instance by a string. * * @param ip IP as a string. such as "192.168.1.1". * @return Instance of <code>Ip</code>. */ public static IP parseFromString(String ip) { String regex = "\\s*(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\s*"; Pattern pattern = Pattern.compile(regex); Matcher m = pattern.matcher(ip); checkArgument(m.find(), "IP string should match the regex:%s", regex); int a = Integer.parseInt(m.group(1)); int b = Integer.parseInt(m.group(2)); int c = Integer.parseInt(m.group(3)); int d = Integer.parseInt(m.group(4)); return new IP(a, b, c, d); }
/** * Creates a IP instance by a string. * * @param ip IP as a string. such as "192.168.1.1". * @return Instance of <code>Ip</code>. */ public static IP parseFromString(String ip) { String regex = "\\s*(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\s*"; Pattern pattern = Pattern.compile(regex); Matcher m = pattern.matcher(ip); checkArgument(m.find(), "IP string should match the regex:%s", regex); int a = Integer.parseInt(m.group(1)); int b = Integer.parseInt(m.group(2)); int c = Integer.parseInt(m.group(3)); int d = Integer.parseInt(m.group(4)); return new IP(a, b, c, d); }