forked from eclipse-vertx/vertx-sql-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCidr.java
More file actions
40 lines (33 loc) · 1.07 KB
/
Cidr.java
File metadata and controls
40 lines (33 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package io.vertx.pgclient.data;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
/**
* A PostgreSQL <a href="https://www.postgresql.org/docs/current/datatype-net-types.html#DATATYPE-CIDR">classless internet domain routing</a>.
*/
public class Cidr {
private InetAddress address;
private Integer netmask;
public InetAddress getAddress(){
return address;
}
public Cidr setAddress(InetAddress address) {
if (address instanceof Inet4Address || address instanceof Inet6Address) {
this.address = address;
} else {
throw new IllegalArgumentException("Invalid IP address type");
}
return this;
}
public Integer getNetmask(){
return netmask;
}
public Cidr setNetmask(Integer netmask) {
if (netmask != null && ((getAddress() instanceof Inet4Address && (netmask < 0 || netmask > 32)) ||
(getAddress() instanceof Inet6Address && (netmask < 0 || netmask > 128)))) {
throw new IllegalArgumentException("Invalid netmask: " + netmask);
}
this.netmask = netmask;
return this;
}
}