public final class PartialSubnet extends CacheableDataType implements Comparable<PartialSubnet>
Subnet
that has one or more IpRange
s
associated with it that narrow the scope of the subnet (hence "partial").
It follows that all IP addresses represented within the range(s) must fall within the given subnet, and that if more than one range is specified they do not overlap.
All constructors for this class are private. Creating instances
of PartialSubnet
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 is presented in an intuitive order.
Modifier and Type | Method and Description |
---|---|
int |
compareTo(PartialSubnet o) |
boolean |
contains(IpAddress ip)
Returns true if this partial subnet contains the given IP address;
false otherwise.
|
boolean |
contains(IpRange range)
Returns true if this partial subnet contains the given
IP address range; false otherwise.
|
boolean |
equals(Object o) |
IpRange |
getRange()
Returns the first IP range.
|
List<IpRange> |
getRanges()
Returns a copy of the list of IP ranges.
|
Subnet |
getSubnet()
Returns the subnet.
|
int |
hashCode() |
Iterator<IpAddress> |
iterator()
Returns an IP address iterator that iterates across the IP addresses
defined in the range(s) associated with this partial subnet.
|
BigInteger |
size()
Returns the size of the partial subnet.
|
int |
sizeAsInt()
Returns the size of the partial subnet as an integer value, unless the
value would be greater than
Integer.MAX_VALUE , in which case
this method returns -1. |
long |
sizeAsLong()
Returns the size of the partial subnet as a long value, unless the
value would be greater than
Long.MAX_VALUE , in which case
this method returns -1L. |
String |
toDebugString()
Returns a multi-line string representation of this instance.
|
String |
toString() |
static PartialSubnet |
valueOf(String spec)
Returns a
PartialSubnet instance that encapsulates the
subnet and any specified IP address range(s) expressed by the given
string specification. |
static PartialSubnet |
valueOf(Subnet subnet)
Returns a
PartialSubnet instance that encapsulates the given
subnet, with an implied IP address range that spans the complete subnet. |
static PartialSubnet |
valueOf(Subnet subnet,
IpRange range)
Returns a
PartialSubnet instance that encapsulates the given
subnet, and IP address range. |
static PartialSubnet |
valueOf(Subnet subnet,
List<IpRange> ranges)
Returns a
PartialSubnet instance that encapsulates the
given subnet, and IP address ranges. |
getRefQ, keyFromBytes
public String toDebugString()
public Subnet getSubnet()
public IpRange getRange()
.getRanges().get(0);
public List<IpRange> getRanges()
public int compareTo(PartialSubnet o)
compareTo
in interface Comparable<PartialSubnet>
public boolean contains(IpAddress ip)
ip
- the IP addresspublic boolean contains(IpRange range)
range
- the IP address rangepublic BigInteger size()
sizeAsLong()
,
sizeAsInt()
public long sizeAsLong()
Long.MAX_VALUE
, in which case
this method returns -1L.size()
public int sizeAsInt()
Integer.MAX_VALUE
, in which case
this method returns -1.size()
public Iterator<IpAddress> iterator()
public static PartialSubnet valueOf(Subnet subnet)
PartialSubnet
instance that encapsulates the given
subnet, with an implied IP address range that spans the complete subnet.
This is equivalent to calling:
PartialSubnet.valueOf(subnet, (IpRange)null);
subnet
- the subnetNullPointerException
- if subnet is nullpublic static PartialSubnet valueOf(Subnet subnet, IpRange range)
PartialSubnet
instance that encapsulates the given
subnet, and IP address range.
Note that the IP range (if specified) must fall completely
within the IP addresses specified by the subnet.
If null
is specified as the range, this is taken as shorthand
for specifying a range that completely matches the entire subnet.subnet
- the subnetrange
- the IP range (or null for entire subnet)NullPointerException
- if subnet is nullIllegalArgumentException
- if range is not appropriate for
the given subnetpublic static PartialSubnet valueOf(Subnet subnet, List<IpRange> ranges)
PartialSubnet
instance that encapsulates the
given subnet, and IP address ranges.
Note that the IP ranges (if specified) must fall completely
within the IP addresses specified by the subnet, and must not overlap.
If null
or an empty list is supplied as the list of ranges,
this is taken as shorthand for specifying a single range that
completely matches the entire subnet.subnet
- the subnetranges
- the list of ranges (or null/empty for entire subnet)NullPointerException
- if subnet is nullIllegalArgumentException
- if the ranges are not appropriate
for the given subnetpublic static PartialSubnet valueOf(String spec)
PartialSubnet
instance that encapsulates the
subnet and any specified IP address range(s) expressed by the given
string specification. Note that the IP range(s) (if specified) must fall
completely within the IP addresses specified by the subnet, and if more
than one range is declared, they must not overlap.
The expected form of the specification string is:
{subnet}[,{ip-range}[,{ip-range}[,...]]]where
subnet
is the form accepted by
Subnet.valueOf(String)
, and
ip-range
is the form accepted by
IpRange.valueOf(String)
.
For example:
192.168.12.0/24,192.168.12.11-17defines a partial subnet that restricts the given subnet (
192.168.12.0
through 192.168.12.255
with subnet mask
255.255.255.0
)
to the IP addresses 192.168.12.11
through 192.168.12.17
.
Another example:
192.168.12.0/23defines a partial subnet that is equivalent to the subnet (
192.168.12.0
through 192.168.13.255
with subnet mask
255.255.254.0
)
with all IP addresses included. The implied range is
192.168.12-13.*
.
Some more examples:
10.11.12.0/24,10.11.12.0-127,10.11.12.200-205 15.37.24.0/21,15.37.24.*,15.37.25.1-100,15.37.25.121-123Note that there can be no white-space in the string.
spec
- the string specificationNullPointerException
- if spec is nullIllegalArgumentException
- if the parameter is malformedCopyright © 2015. All Rights Reserved.