public abstract class IPAddressSeqRange extends Object implements IPAddressRange
Note that the IPAddress and IPAddressString classes allow you to specify a range of values for each segment.
That allows you to represent single addresses, any address prefix subnet (eg 1.2.0.0/16 or 1:2:3:4::/64) or any subnet that can be represented with segment ranges (1.2.0-255.* or 1:2:3:4:*), see
IPAddressString for details.
IPAddressString and IPAddress cover all potential subnets and addresses that can be represented by a single address string of 4 or less segments for IPv4, and 8 or less segments for IPv6.
This class allows the representation of any sequential address range, including those that cannot be represented by IPAddress.
String representations include the full address for both the lower and upper bounds of the range.
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_RANGE_SEPARATOR |
| Modifier and Type | Method and Description |
|---|---|
int |
compareCounts(IPAddressSeqRange other)
Compares the counts of this range with the give range.
|
IPAddressSeqRange[] |
complement()
Returns the complement of the address range within the address space.
|
IPAddressSeqRangeList |
complementIntoList() |
boolean |
contains(IPAddress other)
Returns whether this aggregation of addresses contains all addresses in the given address or subnet
|
boolean |
contains(IPAddressSeqRange other)
Returns whether this aggregation of addresses contains all addresses in the given sequential range
|
boolean |
containsPrefixBlock(int prefixLen)
Returns whether the values of this series contains the prefix block for the given prefix length,
which means it contains all addresses with the same prefix.
|
boolean |
containsSinglePrefixBlock(int prefixLen)
Returns whether the values of this series contains a single prefix block for the given prefix length.
|
abstract IPAddress |
coverWithPrefixBlock()
Returns the minimal-size prefix block that covers all the addresses in this range.
|
BigInteger |
enumerate(IPAddress other)
Returns the distance of the given address from the initial value of this range.
|
boolean |
equals(Object o)
Returns whether the given sequential address range is equal to this sequential address range.
|
IPAddressSeqRange |
extend(IPAddress other)
Extend this sequential range to include all addresses in the given individual address or subnet.
|
IPAddressSeqRange |
extend(IPAddressRange other)
Extend this sequential range to include all address in the given range, which can be an IPAddress or IPAddressSeqRange.
|
IPAddressSeqRange |
extend(IPAddressSeqRange other)
Extend this sequential range to include all addresses in the given sequential range.
|
abstract IPAddress |
get(BigInteger index)
Returns the individual address at the given index into this sequential range.
|
abstract IPAddress |
get(long index)
Returns the individual address at the given index into this sequential range.
|
int |
getBitCount()
Provides the number of bits comprising this address item
|
byte[] |
getBytes() |
byte[] |
getBytes(byte[] bytes)
Copies the bytes of the lowest address item represented by this address item into the supplied array,
and returns that array.
|
byte[] |
getBytes(byte[] bytes,
int index)
Copies the bytes of the lowest address item represented by this address item into the supplied array starting at the given index,
and returns that array.
|
BigInteger |
getCount()
Returns the number of individual addresses in this range.
|
abstract Iterable<? extends IPAddress> |
getIterable()
Useful for using an instance in a "for-each loop", as in
for(addr : address.getIterable()) { ... |
IPAddress |
getLower()
Returns the lowest address in the sequential range, the one with the lowest numeric value
|
IPAddress |
getUpper()
Returns the highest address in the sequential range, the one with the highest numeric value
|
byte[] |
getUpperBytes() |
byte[] |
getUpperBytes(byte[] bytes)
Copies the bytes of the largest address item represented by this address item into the supplied array,
and returns that array.
|
byte[] |
getUpperBytes(byte[] bytes,
int index)
Copies the bytes of the largest address item represented by this address item into the supplied array at the given index,
and returns that array.
|
BigInteger |
getUpperValue()
Returns the highest value represented by this address item, the highest value included in the range of values
|
BigInteger |
getValue()
Returns the lowest value represented by this address item, the lowest value included in the range of values
|
int |
hashCode() |
boolean |
includesMax()
Returns whether this sequential range's upper value is the highest address, the address whose bits are all ones.
|
boolean |
includesZero()
Returns whether this sequential range's lower value is the zero address.
|
IPAddressSeqRange |
intersect(IPAddressSeqRange other)
Returns the intersection of this range with the given range, a range which includes those addresses in both this and the given range.
|
IPAddressSeqRangeList |
intoSequentialRangeList()
Creates a sequential range list from the address, which will contain the same set of individual addresses as this range of addresses.
|
boolean |
isIPv4() |
boolean |
isIPv6() |
boolean |
isMax()
Returns whether this sequential range spans from the highest address, the address whose bits are all ones, to itself.
|
boolean |
isMore(IPAddressSeqRange other)
Deprecated.
use
compareCounts(IPAddressSeqRange) instead |
boolean |
isMultiple()
Returns true if there is more than one address in this range.
|
boolean |
isSequential()
Returns whether the address or subnet represents a range of values that are sequential.
|
boolean |
isZero()
Returns whether this sequential range spans from the zero address to itself.
|
abstract Iterator<? extends IPAddress> |
iterator()
Returns an iterator of the individual addresses in ascending order, following the natural order of IPAddress from lowest numeric value to highest.
|
static IPAddressSeqRange[] |
join(IPAddressSeqRange... ranges)
Joins the given ranges into the fewest number of ranges.
|
IPAddressSeqRange |
join(IPAddressSeqRange other)
Joins two ranges if they are contiguous ranges.
|
static IPAddressSeqRangeList[] |
joinIntoList(IPAddressSeqRange... ranges)
Creates ranges lists from the given ranges.
|
IPAddressSeqRangeList |
joinIntoList(IPAddressSeqRange other)
Joins two ranges.
|
IPAddressSeqRange |
lowerFromSplit(IPAddress other)
Same as split, but returns only the lower range.
|
boolean |
overlaps(IPAddress other)
Returns true if this sequential range overlaps the given address or subnet.
|
boolean |
overlaps(IPAddressSeqRange other)
Returns true if this sequential range overlaps the given sequential range.
|
abstract Iterator<? extends IPAddress> |
prefixBlockIterator(int prefLength)
Iterates through the range of prefix blocks in this range instance using the given prefix length.
|
abstract AddressComponentRangeSpliterator<? extends IPAddressSeqRange,? extends IPAddress> |
prefixBlockSpliterator(int prefLength)
Partitions and traverses through the individual prefix blocks for the given prefix length.
|
abstract Stream<? extends IPAddress> |
prefixBlockStream(int prefLength)
Returns a sequential stream of the prefix blocks for the given prefix length.
|
Iterator<? extends IPAddressSeqRange> |
prefixIterator(int prefixLength)
Iterates through the range of prefixes in this range instance using the given prefix length.
|
abstract AddressComponentSpliterator<? extends IPAddressSeqRange> |
prefixSpliterator(int prefLength)
Partitions and traverses through the individual prefixes for the given prefix length.
|
abstract Stream<? extends IPAddressSeqRange> |
prefixStream(int prefLength)
Returns a sequential stream of the individual prefixes for the given prefix length.
|
abstract IPAddress[] |
spanWithPrefixBlocks()
Produces a minimal array of prefix blocks that spans the same set of addresses.
|
abstract IPAddress[] |
spanWithSequentialBlocks()
Produces a minimal array of blocks that are sequential that cover the same set of addresses.
|
IPAddressSeqRange[] |
split(IPAddress other)
Splits this range at the given address into two ranges, one lower and one upper.
|
abstract AddressComponentRangeSpliterator<? extends IPAddressSeqRange,? extends IPAddress> |
spliterator()
Partitions and traverses through the individual addresses.
|
abstract Stream<? extends IPAddress> |
stream()
Returns a sequential stream of the individual addresses.
|
IPAddressSeqRange[] |
subtract(IPAddressSeqRange other)
Subtracts the given range from this range, to produce either zero, one, or two address ranges that contain the addresses in this range and not in the given range.
|
IPAddressSeqRangeList |
subtractIntoList(IPAddressSeqRange other)
Subtracts the given range from this range, to produce either zero, one, or two address ranges, stored in a IPAddressSeqRangeList, which is sorted, that contain the addresses in this range and not in the given range.
|
String |
toCanonicalString()
Produces a canonical string for the address range.
|
String |
toCanonicalString(String separator)
Produces a canonical string for the address range with the given separator string.
|
IPv4AddressSeqRange |
toIPv4()
If this sequential range is IPv4, or can be converted to IPv4 by applying the same conversion to all address in the range, returns that
IPv4AddressSeqRange. |
IPv6AddressSeqRange |
toIPv6()
If this sequential range is IPv6, or can be converted to IPv6 by applying the same conversion to all address in the range, returns that
IPv6AddressSeqRange. |
String |
toNormalizedString()
Produces a normalized string for the address range.
|
String |
toNormalizedString(String separator) |
String |
toString()
Produces the canonical string for the address, also available from
toCanonicalString(). |
String |
toString(Function<? super IPAddress,String> lowerStringer,
String separator,
Function<? super IPAddress,String> upperStringer) |
IPAddressSeqRange |
upperFromSplit(IPAddress other)
Same as split, but returns only the upper range.
|
intoContainmentTrie, toSequentialRangecoverWithSequentialRangestream, streamcompareTo, getBitsForCount, getBlockSize, getByteCount, getMinPrefixLengthForBlock, getPrefixCount, getPrefixLengthForSingleBlock, isFullRangepublic static final String DEFAULT_RANGE_SEPARATOR
public BigInteger getCount()
IPAddressRangegetCount in interface AddressItemgetCount in interface IPAddressRangegetCount in interface IPAddressAggregation<IPAddress,IPAddressSeqRange>public boolean isMultiple()
IPAddressRangeisMultiple in interface AddressItemisMultiple in interface IPAddressRangeisMultiple in interface IPAddressAggregation<IPAddress,IPAddressSeqRange>public boolean isIPv4()
public boolean isIPv6()
public IPv4AddressSeqRange toIPv4()
IPv4AddressSeqRange. Otherwise, returns null.public IPv6AddressSeqRange toIPv6()
IPv6AddressSeqRange. Otherwise, returns null.@Deprecated public boolean isMore(IPAddressSeqRange other)
compareCounts(IPAddressSeqRange) insteadother - the range to compare, which does not need to range across the same address spacepublic int compareCounts(IPAddressSeqRange other)
other - the range to compare, which does not need to range across the same address spacepublic abstract Iterable<? extends IPAddress> getIterable()
IPAddressRangefor(addr : address.getIterable()) { ... }
Otherwise just call IPAddressAggregation.iterator() directly.
getIterable in interface AddressComponentRangegetIterable in interface IPAddressRangepublic abstract Iterator<? extends IPAddress> prefixBlockIterator(int prefLength)
prefixBlockIterator in interface IPAddressRangeprefLength - public abstract AddressComponentRangeSpliterator<? extends IPAddressSeqRange,? extends IPAddress> prefixBlockSpliterator(int prefLength)
IPAddressRangeprefixBlockSpliterator in interface IPAddressRangepublic abstract Stream<? extends IPAddress> prefixBlockStream(int prefLength)
IPAddressRangeBaseStream.parallel() on the returned stream.prefixBlockStream in interface IPAddressRangepublic Iterator<? extends IPAddressSeqRange> prefixIterator(int prefixLength)
Since a range between two arbitrary addresses cannot always be represented with a single IPAddress instance,
the returned iterator iterates through IPAddressSeqRange instances.
For instance, if iterating from 1.2.3.4 to 1.2.4.5 with prefix 8, the range shares the same prefix 1, but the range cannot be represented by the address 1.2.3-4.4-5 which does not include 1.2.3.255 or 1.2.4.0 both of which are in the original range. Nor can the range be represented by 1.2.3-4.0-255 which includes 1.2.4.6 and 1.2.3.3, both of which were not in the original range. An IPAddressSeqRange is thus required to represent that prefixed range.
prefixIterator in interface IPAddressRangeprefixLength - public abstract AddressComponentSpliterator<? extends IPAddressSeqRange> prefixSpliterator(int prefLength)
IPAddressRangeprefixSpliterator in interface IPAddressRangepublic abstract Stream<? extends IPAddressSeqRange> prefixStream(int prefLength)
IPAddressRangeBaseStream.parallel() on the returned stream.prefixStream in interface IPAddressRangepublic abstract Iterator<? extends IPAddress> iterator()
IPAddressAggregationiterator in interface AddressComponentRangeiterator in interface IPAddressAggregation<IPAddress,IPAddressSeqRange>public abstract AddressComponentRangeSpliterator<? extends IPAddressSeqRange,? extends IPAddress> spliterator()
IPAddressRangespliterator in interface AddressComponentRangespliterator in interface IPAddressRangespliterator in interface IPAddressAggregation<IPAddress,IPAddressSeqRange>public abstract Stream<? extends IPAddress> stream()
IPAddressAggregationBaseStream.parallel() on the returned stream.stream in interface AddressComponentRangestream in interface IPAddressAggregation<IPAddress,IPAddressSeqRange>public IPAddress getLower()
getLower in interface AddressComponentRangegetLower in interface IPAddressAggregation<IPAddress,IPAddressSeqRange>public IPAddress getUpper()
getUpper in interface AddressComponentRangegetUpper in interface IPAddressAggregation<IPAddress,IPAddressSeqRange>public abstract IPAddress get(BigInteger index)
If the increment is negative, or the increment exceeds getCount() - 1, this method throws IndexOutOfBoundsException.
Otherwise, this returns the address that is the given index upwards into the list of sequential ranges, with the increment of zero returning the first address.
index - public abstract IPAddress get(long index)
If the increment is negative, or the increment exceeds getCount() - 1, this method throws IndexOutOfBoundsException.
Otherwise, this returns the address that is the given index upwards into the list of sequential ranges, with the increment of zero returning the first address.
index - public String toNormalizedString()
getLower() and getUpper().toNormalizedString in interface IPAddressRangepublic String toCanonicalString(String separator)
public String toCanonicalString()
getLower() and getUpper().toCanonicalString in interface IPAddressRangepublic String toString(Function<? super IPAddress,String> lowerStringer, String separator, Function<? super IPAddress,String> upperStringer)
public String toString()
toCanonicalString().public abstract IPAddress coverWithPrefixBlock()
coverWithPrefixBlock in interface IPAddressAggregation<IPAddress,IPAddressSeqRange>public abstract IPAddress[] spanWithPrefixBlocks()
IPAddressRangespanWithPrefixBlocks in interface IPAddressRangepublic abstract IPAddress[] spanWithSequentialBlocks()
IPAddressRangeIPAddressRange.spanWithPrefixBlocks() and is never longer.spanWithSequentialBlocks in interface IPAddressRangepublic static IPAddressSeqRange[] join(IPAddressSeqRange... ranges)
If the input ranges are both IPv4 and IPv6, then the joined IPv4 ranges will be followed by the joined IPv6 ranges.
ranges - public static IPAddressSeqRangeList[] joinIntoList(IPAddressSeqRange... ranges)
ranges - public boolean overlaps(IPAddress other)
overlaps in interface IPAddressAggregation<IPAddress,IPAddressSeqRange>other - public boolean overlaps(IPAddressSeqRange other)
overlaps in interface IPAddressAggregation<IPAddress,IPAddressSeqRange>other - public boolean contains(IPAddress other)
IPAddressAggregationcontains in interface IPAddressAggregation<IPAddress,IPAddressSeqRange>public boolean contains(IPAddressSeqRange other)
IPAddressAggregationcontains in interface IPAddressAggregation<IPAddress,IPAddressSeqRange>public BigInteger enumerate(IPAddress other)
If within or above the range, it is the distance to the lower boundary of the sequential range. If below the range, returns the number of addresses following the address to the lower range boundary.
The method does not return null if this range does not contain the address. You can call contains(IPAddress) or you can compare with getCount() to check for containment.
An address is in the range if 0 <= enumerate(IPAddress) < getCount().
Returns null when the argument is a multi-valued subnet. The argument must be an individual address.
If the given address does not have the same version or type as the addresses in this range, then null is returned.
enumerate in interface IPAddressRangepublic boolean isSequential()
IP address sequential ranges are sequential by definition, so this returns true.
isSequential in interface IPAddressAggregation<IPAddress,IPAddressSeqRange>public boolean equals(Object o)
public IPAddressSeqRange intersect(IPAddressSeqRange other)
other - public IPAddressSeqRange join(IPAddressSeqRange other)
Otherwise, null is returned.
Use joinIntoList(IPAddressSeqRange) if you wish the result to match the original inputs.
That method returns a list which contains both this and the given range, regardless of whether they can be joined into a single range.
other - public IPAddressSeqRangeList joinIntoList(IPAddressSeqRange other)
join(IPAddressSeqRange), but instead the result includes all the addresses in both ranges, regardless of whether they are contiguous.other - public IPAddressSeqRange extend(IPAddress other)
other - public IPAddressSeqRange extend(IPAddressSeqRange other)
other - public IPAddressSeqRange extend(IPAddressRange other)
other - public IPAddressSeqRange[] subtract(IPAddressSeqRange other)
other - public IPAddressSeqRangeList subtractIntoList(IPAddressSeqRange other)
other - public IPAddressSeqRange[] complement()
IPAddressRangeReturns a minimal array of IP address sequential ranges instances containing the addresses not contained within this address range.
complement in interface IPAddressRangepublic IPAddressSeqRangeList complementIntoList()
public IPAddressSeqRange[] split(IPAddress other)
This is similar to subtract, but without removing the given address or subnet from the result.
Unlike subtract, this always returns an array of length two. In some cases, one or both of the two returned ranges is null.
If the given address or subnet includes the first address in this range, or all addresses of the given address or subnet are below the lower value of this range, then the first range is null, and the second range is the same range as this range.
If all addresses of the given address or subnet are above the upper value of this range, then the first range is is the same range as this range, and the second range is null.
If the given address has a different version than this, then both returned ranges is null.
other - public IPAddressSeqRange lowerFromSplit(IPAddress other)
other - public IPAddressSeqRange upperFromSplit(IPAddress other)
other - public IPAddressSeqRangeList intoSequentialRangeList()
IPAddressRange
Unlike IPAddressAggregation.coverWithSequentialRange(), the returned list will always contain the same set of addresses as this range, regardless of whether this range of addresses is sequential or not.
intoSequentialRangeList in interface IPAddressRangepublic boolean containsPrefixBlock(int prefixLen)
AddressItem
Use AddressItem.getMinPrefixLengthForBlock() to determine the smallest prefix length for which this method returns true.
containsPrefixBlock in interface AddressItempublic boolean containsSinglePrefixBlock(int prefixLen)
AddressItem
Use AddressItem.getPrefixLengthForSingleBlock() to determine whether there is a prefix length for which this method returns true.
containsSinglePrefixBlock in interface AddressItempublic int getBitCount()
AddressItemgetBitCount in interface AddressItempublic byte[] getBytes()
getBytes in interface AddressItempublic byte[] getBytes(byte[] bytes)
AddressItemgetBytes in interface AddressItempublic byte[] getBytes(byte[] bytes,
int index)
AddressItemgetBytes in interface AddressItempublic byte[] getUpperBytes()
getUpperBytes in interface AddressItempublic byte[] getUpperBytes(byte[] bytes)
AddressItemgetUpperBytes in interface AddressItempublic byte[] getUpperBytes(byte[] bytes,
int index)
AddressItemgetUpperBytes in interface AddressItempublic BigInteger getValue()
AddressItemgetValue in interface AddressItempublic BigInteger getUpperValue()
AddressItemgetUpperValue in interface AddressItempublic boolean isZero()
isZero in interface AddressItempublic boolean includesZero()
includesZero in interface AddressItemincludesZero in interface IPAddressAggregation<IPAddress,IPAddressSeqRange>public boolean isMax()
isMax in interface AddressItempublic boolean includesMax()
includesMax in interface AddressItemincludesMax in interface IPAddressAggregation<IPAddress,IPAddressSeqRange>