public class InetCidr extends Object implements Serializable, Comparable<InetCidr>
| Constructor and Description |
|---|
InetCidr(InetAddress addr,
InetAddress netMask)
Constructs a
InetCidr provided an ip address and an ip mask. |
InetCidr(InetAddress addr,
int mask)
Constructor for InetCidr.
|
| Modifier and Type | Method and Description |
|---|---|
static InetCidr[] |
addr2Cidr(InetAddress addr)
Returns an array of all cidr combinations with the provided ip address.
|
static void |
checkNoOverlap(List<InetCidr> list)
Checks whether the list does not contain any overlapping cidr(s).
|
int |
compareTo(InetCidr rhs)
Compare two InetCidr by its addr as main criterion, mask as second.
|
boolean |
equals(Object o) |
static InetCidr |
fromLong(long l)
Creates a new
InetCidr from its long
representation. |
InetAddress |
getAddr() |
long |
getAddrLong() |
int |
getMask() |
int |
hashCode() |
static boolean |
isSorted(List<InetCidr> list)
Checks whether a list of InetCidr is strictly sorted (no 2 equal objects).
|
long |
toLong()
Returns a
long representation of Cidr. |
String |
toString() |
public InetCidr(InetAddress addr, int mask)
Takes a network address (IPv4) and a mask length
addr - IPv4 addressmask - mask length (between 1 and 32)NullPointerException - if addr is nullIllegalArgumentException - if addr is not IPv4public InetCidr(InetAddress addr, InetAddress netMask)
InetCidr provided an ip address and an ip mask.
If the mask is not valid, an exception is raised.
addr - the ip address (IPv4)netMask - the ip maskIllegalArgumentException - if addr or netMask is null.IllegalArgumentException - if the netMask is not a valid one.public InetAddress getAddr()
public long getAddrLong()
public int getMask()
public final long toLong()
long representation of Cidr.
The high 32 bits contain the mask, the low 32 bits the network address.
long representation of the Cidrpublic static final InetCidr fromLong(long l)
InetCidr from its long
representation.l - the Cidr in its "long" formatpublic static InetCidr[] addr2Cidr(InetAddress addr)
The array is ordered from the most specific to the most general mask.
addr - addresspublic int compareTo(InetCidr rhs)
Note: this class has a natural ordering that is inconsistent with equals.
compareTo in interface Comparable<InetCidr>rhs - object to compare topublic static boolean isSorted(List<InetCidr> list)
list - list of potentially sorted InetCidrlist is sorted or nullNullPointerException - if one or more elements of the list are nullpublic static void checkNoOverlap(List<InetCidr> list)
Pre-requisite: list must be already sorted.
list - sorted list of InetCidrNullPointerException - if a list element is nullIllegalStateException - if overlapping cidr are detectedCopyright © 2018 Philip Helger. All rights reserved.