public final class SubnetMask extends CacheableDataType implements Comparable<SubnetMask>
All constructors for this class are private. Creating instances of
SubnetMask
is done via the static methods on the class.
Instances of this class are immutable, making them inherently thread-safe.
This class overrides equals(java.lang.Object)
and hashCode()
so that instances
play nicely with the Collection classes.
This class implements the Comparable
interface to ensure that a
sorted list of subnet masks is presented in an intuitive order.
Modifier and Type | Field and Description |
---|---|
static SubnetMask |
MASK_255_0_0_0 |
static SubnetMask |
MASK_255_255_0_0 |
static SubnetMask |
MASK_255_255_248_0 |
static SubnetMask |
MASK_255_255_255_0 |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(SubnetMask o) |
boolean |
equals(Object o) |
static SubnetMask |
fromCidr(String cidr)
Returns a
SubnetMask object that represents the value of the
subnet mask implied by the given CIDR notation. |
IpAddress.Family |
getFamily()
Returns the IP address family of this subnet mask.
|
int |
getOneBitCount()
Returns the number of 1 bits in the mask.
|
int |
hashCode() |
IpAddress |
hostPortion(IpAddress address)
Applies this mask (via logical AND of NOT(mask) ) to calculate and
return the host portion of the specified address.
|
IpAddress |
networkPortion(IpAddress address)
Applies this mask (via logical AND) to calculate and return the
network portion of the specified address.
|
byte[] |
toByteArray()
Returns a newly allocated byte array containing bytes that represent
the subnet mask.
|
String |
toDebugString()
Returns a string representation of this subnet mask showing the
internal state.
|
IpAddress |
toIpAddress()
Returns the IP address equivalent to this subnet mask.
|
String |
toString() |
static SubnetMask |
valueOf(byte[] maskBytes)
Returns a
SubnetMask object that represents the subnet mask
defined by the specified byte array. |
static SubnetMask |
valueOf(IpAddress mask)
Returns a
SubnetMask object that represents the subnet mask
with the value of the given IP address. |
static SubnetMask |
valueOf(String mask)
Returns a
SubnetMask object that represents the value of the
subnet mask defined by the specified string. |
getRefQ, keyFromBytes
public static final SubnetMask MASK_255_0_0_0
public static final SubnetMask MASK_255_255_0_0
public static final SubnetMask MASK_255_255_248_0
public static final SubnetMask MASK_255_255_255_0
public String toDebugString()
public byte[] toByteArray()
public IpAddress toIpAddress()
public IpAddress.Family getFamily()
public int getOneBitCount()
public int compareTo(SubnetMask o)
compareTo
in interface Comparable<SubnetMask>
public IpAddress networkPortion(IpAddress address)
SubnetMask.MASK_255_255_248_0 .networkPortion(IpAddress.valueOf("15.37.129.123"))will return the "IP address"
15.37.128.0
address
- the address to processNullPointerException
- if address is nullIllegalArgumentException
- if there is a mismatch of IPv4/IPv6public IpAddress hostPortion(IpAddress address)
SubnetMask.MASK_255_255_248_0 .hostPortion(IpAddress.valueOf("15.37.129.123"))will return the "IP address"
0.0.1.123
address
- the address to processNullPointerException
- if address is nullIllegalArgumentException
- if there is a mismatch of IPv4/IPv6public static SubnetMask valueOf(IpAddress mask)
SubnetMask
object that represents the subnet mask
with the value of the given IP address.mask
- the subnet mask value expressed as an IP addressNullPointerException
- if mask is nullIllegalArgumentException
- if mask is not a valid value for
a subnet maskpublic static SubnetMask valueOf(byte[] maskBytes)
SubnetMask
object that represents the subnet mask
defined by the specified byte array. Note that the mask bytes are
presumed to be in network byte order; that is, the highest order byte of
the mask is at index 0.
If the bytes array is of length 4, it is interpretted as an IPv4 subnet mask. If the bytes array is of length 16, it is interpretted as an IPv6 subnet mask. Other array lengths will throw an exception.
maskBytes
- the subnet mask bytesNullPointerException
- if maskBytes is nullIllegalArgumentException
- if maskBytes do not define
a valid subnet maskpublic static SubnetMask valueOf(String mask)
SubnetMask
object that represents the value of the
subnet mask defined by the specified string. Both uppercase and
lowercase hex digits are allowed (for IPv6 masks).
Acceptable formats are:
"n.n.n.n"
) --
where 'n' is from 0 to 255"x:x:x:x:x:x:x:x"
) -- where 'x' is from 0000 to FFFF.
Leading zeros may be dropped. "FFFF:FFFF:FFC0::"
) "[FFFF:FFFF:FFC0::]"
) mask
- the string representation of the subnet maskNullPointerException
- if mask is nullIllegalArgumentException
- if mask is not an acceptable formatpublic static SubnetMask fromCidr(String cidr)
SubnetMask
object that represents the value of the
subnet mask implied by the given CIDR notation. For example:
SubnetMask.fromCidr("192.168.0.0/23")would return the subnet mask equivalent to
"255.255.254.0"
cidr
- the CIDR notationCopyright © 2015. All Rights Reserved.