- All Implemented Interfaces:
AddressComponentRange
,AddressItem
,AddressItemRange
,IPAddressRange
,Serializable
,Comparable<AddressItem>
- Direct Known Subclasses:
IPv4AddressSeqRange
,IPv6AddressSeqRange
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.
- Author:
- sfoley
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns whether this range contains all addresses in the given address or subnetboolean
contains
(IPAddressSeqRange other) Returns whether this range contains all addresses in the given sequential rangeboolean
containsPrefixBlock
(int prefixLen) Returns whether the values of this series contains the prefix block for the given prefix length.boolean
containsSinglePrefixBlock
(int prefixLen) Returns whether the values of this series contains a single prefix block for the given prefix length.abstract IPAddress
Returns the minimal-size prefix block that covers all the addresses in this range.boolean
extend
(IPAddressRange other) Extend this sequential range to include all address in the given range, which can be an IPAddress or IPAddressSeqRange.int
Provides the number of bits comprising this address itembyte[]
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.getCount()
The count of possible distinct values for this AddressComponent.Useful for using an instance in a "for-each loop", as infor(addr : address.getIterable()) { ...
getLower()
Returns the address in the range with the lowest numeric value.getUpper()
Returns the address in the range with the highest numeric value.byte[]
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.Returns the highest value represented by this address item, the highest value included in the range of valuesgetValue()
Returns the lowest value represented by this address item, the lowest value included in the range of valuesint
hashCode()
boolean
Returns whether this item includes the maximum possible value for the address type or version within its rangeboolean
Returns whether this item includes the value of zero within its rangeintersect
(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.boolean
isMax()
Returns whether this item matches the maximum possible value for the address type or versionboolean
isMore
(IPAddressSeqRange other) boolean
Whether this represents multiple potential values (eg a prefixed address or a segment representing a range of values)boolean
Returns whether this range represents a range of values that are sequential.boolean
isZero()
Returns whether this item matches the value of zeroiterator()
Iterates through the individual addresses of this address or subnet.join
(IPAddressSeqRange other) If this range overlaps with the given range, or if the highest value of the lower range is one below the lowest value of the higher range, then the two are joined into a new larger range that is returned.static IPAddressSeqRange[]
join
(IPAddressSeqRange... ranges) Joins the given ranges into the fewest number of ranges.boolean
overlaps
(IPAddressSeqRange other) 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.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[]
Produces an array of prefix blocks that spans the same set of addresses.abstract IPAddress[]
Produces an array of blocks that are sequential that cover the same set of addresses.abstract AddressComponentRangeSpliterator
<? extends IPAddressSeqRange, ? extends IPAddress> Partitions and traverses through the individual addresses.stream()
Returns a sequential stream of the individual address components.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.Produces a string that is unique and uses the canonical representation for all instances.toCanonicalString
(String separator) Produces a string that is unique and consistent for all instances.toNormalizedString
(String separator) toString()
toString
(Function<? super IPAddress, String> lowerStringer, String separator, Function<? super IPAddress, String> upperStringer) Methods inherited from interface inet.ipaddr.format.AddressItem
compareTo, getByteCount, getMinPrefixLengthForBlock, getPrefixCount, getPrefixLengthForSingleBlock, isFullRange
Methods inherited from interface inet.ipaddr.format.IPAddressRange
toSequentialRange
-
Method Details
-
getCount
Description copied from interface:AddressItem
The count of possible distinct values for this AddressComponent. If not multiple, this is 1. For instance, if this is the ip address series subnet 0::/64, then the count is 2 to the power of 64. If this is a the segment 3-7, then the count is 5.- Specified by:
getCount
in interfaceAddressItem
- Returns:
-
isMultiple
public boolean isMultiple()Description copied from interface:AddressItem
Whether this represents multiple potential values (eg a prefixed address or a segment representing a range of values)- Specified by:
isMultiple
in interfaceAddressItem
-
isMore
- Parameters:
other
- the range to compare, which does not need to range across the same address space- Returns:
- whether this range spans more addresses than the provided range.
-
getIterable
Description copied from interface:IPAddressRange
Useful for using an instance in a "for-each loop", as infor(addr : address.getIterable()) { ... }
Otherwise just call
IPAddressRange.iterator()
directly.- Specified by:
getIterable
in interfaceAddressComponentRange
- Specified by:
getIterable
in interfaceIPAddressRange
- Returns:
-
prefixBlockIterator
Iterates through the range of prefix blocks in this range instance using the given prefix length.- Specified by:
prefixBlockIterator
in interfaceIPAddressRange
- Parameters:
prefLength
-- Returns:
-
prefixBlockSpliterator
public abstract AddressComponentRangeSpliterator<? extends IPAddressSeqRange,? extends IPAddress> prefixBlockSpliterator(int prefLength) Description copied from interface:IPAddressRange
Partitions and traverses through the individual prefix blocks for the given prefix length.- Specified by:
prefixBlockSpliterator
in interfaceIPAddressRange
- Returns:
-
prefixBlockStream
Description copied from interface:IPAddressRange
Returns a sequential stream of the prefix blocks for the given prefix length. For a parallel stream, callBaseStream.parallel()
on the returned stream.- Specified by:
prefixBlockStream
in interfaceIPAddressRange
- Returns:
-
prefixIterator
Iterates through the range of prefixes in this range instance using the given prefix length.Since a range between two arbitrary addresses cannot always be represented with a single IPAddress instance, the returned iterator iterates through IPAddressRange 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.
- Specified by:
prefixIterator
in interfaceIPAddressRange
- Parameters:
prefixLength
-- Returns:
-
prefixSpliterator
public abstract AddressComponentSpliterator<? extends IPAddressSeqRange> prefixSpliterator(int prefLength) Description copied from interface:IPAddressRange
Partitions and traverses through the individual prefixes for the given prefix length.- Specified by:
prefixSpliterator
in interfaceIPAddressRange
- Returns:
-
prefixStream
Description copied from interface:IPAddressRange
Returns a sequential stream of the individual prefixes for the given prefix length. For a parallel stream, callBaseStream.parallel()
on the returned stream.- Specified by:
prefixStream
in interfaceIPAddressRange
- Returns:
-
iterator
Description copied from interface:IPAddressRange
Iterates through the individual addresses of this address or subnet.Call
AddressItem.isMultiple()
to determine if this instance represents multiple, orAddressItem.getCount()
for the count.- Specified by:
iterator
in interfaceAddressComponentRange
- Specified by:
iterator
in interfaceIPAddressRange
- Returns:
-
spliterator
public abstract AddressComponentRangeSpliterator<? extends IPAddressSeqRange,? extends IPAddress> spliterator()Description copied from interface:IPAddressRange
Partitions and traverses through the individual addresses.- Specified by:
spliterator
in interfaceAddressComponentRange
- Specified by:
spliterator
in interfaceIPAddressRange
- Returns:
-
stream
Description copied from interface:AddressComponentRange
Returns a sequential stream of the individual address components. For a parallel stream, callBaseStream.parallel()
on the returned stream.- Specified by:
stream
in interfaceAddressComponentRange
- Returns:
-
getLower
Description copied from interface:IPAddressRange
Returns the address in the range with the lowest numeric value.- Specified by:
getLower
in interfaceAddressComponentRange
- Specified by:
getLower
in interfaceIPAddressRange
- Returns:
-
getUpper
Description copied from interface:IPAddressRange
Returns the address in the range with the highest numeric value.- Specified by:
getUpper
in interfaceAddressComponentRange
- Specified by:
getUpper
in interfaceIPAddressRange
- Returns:
-
toNormalizedString
-
toNormalizedString
Description copied from interface:IPAddressRange
Produces a string that is unique and consistent for all instances.- Specified by:
toNormalizedString
in interfaceIPAddressRange
- Returns:
-
toCanonicalString
-
toCanonicalString
Description copied from interface:IPAddressRange
Produces a string that is unique and uses the canonical representation for all instances.- Specified by:
toCanonicalString
in interfaceIPAddressRange
- Returns:
-
toString
-
toString
-
coverWithPrefixBlock
Description copied from interface:IPAddressRange
Returns the minimal-size prefix block that covers all the addresses in this range. The resulting block will have a larger address count than this range, unless this range is already a prefix block.- Specified by:
coverWithPrefixBlock
in interfaceIPAddressRange
-
spanWithPrefixBlocks
Description copied from interface:IPAddressRange
Produces an array of prefix blocks that spans the same set of addresses.- Specified by:
spanWithPrefixBlocks
in interfaceIPAddressRange
-
spanWithSequentialBlocks
Description copied from interface:IPAddressRange
Produces an array of blocks that are sequential that cover the same set of addresses. This array can be shorter than that produced byIPAddressRange.spanWithPrefixBlocks()
and is never longer.- Specified by:
spanWithSequentialBlocks
in interfaceIPAddressRange
-
join
Joins the given ranges into the fewest number of ranges. The returned array will be sorted by ascending lowest range value.- Parameters:
ranges
-- Returns:
-
overlaps
-
contains
Description copied from interface:IPAddressRange
Returns whether this range contains all addresses in the given address or subnet- Specified by:
contains
in interfaceIPAddressRange
- Parameters:
other
-- Returns:
-
contains
Description copied from interface:IPAddressRange
Returns whether this range contains all addresses in the given sequential range- Specified by:
contains
in interfaceIPAddressRange
- Parameters:
other
-- Returns:
-
isSequential
public boolean isSequential()Description copied from interface:IPAddressRange
Returns whether this range represents a range of values that are sequential.- Specified by:
isSequential
in interfaceIPAddressRange
- Returns:
-
hashCode
public int hashCode() -
equals
-
intersect
Returns the intersection of this range with the given range, a range which includes those addresses in both this and the given range.- Parameters:
other
-- Returns:
-
join
If this range overlaps with the given range, or if the highest value of the lower range is one below the lowest value of the higher range, then the two are joined into a new larger range that is returned.Otherwise null is returned.
- Parameters:
other
-- Returns:
-
extend
Extend this sequential range to include all address in the given range, which can be an IPAddress or IPAddressSeqRange. If the argument has a different IP version than this, null is returned. Otherwise, this method returns the range that includes this range, the given range, and all addresses in-between.- Parameters:
other
-- Returns:
-
subtract
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. If the result has length 2, the two ranges are ordered by ascending lowest range value.- Parameters:
other
-- Returns:
-
containsPrefixBlock
public boolean containsPrefixBlock(int prefixLen) Description copied from interface:AddressItem
Returns whether the values of this series contains the prefix block for the given prefix length.Use
AddressItem.getMinPrefixLengthForBlock()
to determine the smallest prefix length for which this method returns true.- Specified by:
containsPrefixBlock
in interfaceAddressItem
- Parameters:
prefixLen
-- Returns:
-
containsSinglePrefixBlock
public boolean containsSinglePrefixBlock(int prefixLen) Description copied from interface:AddressItem
Returns whether the values of this series contains a single prefix block for the given prefix length.Use
AddressItem.getPrefixLengthForSingleBlock()
to determine whether there is a prefix length for which this method returns true.- Specified by:
containsSinglePrefixBlock
in interfaceAddressItem
- Parameters:
prefixLen
-- Returns:
-
getBitCount
public int getBitCount()Description copied from interface:AddressItem
Provides the number of bits comprising this address item- Specified by:
getBitCount
in interfaceAddressItem
- Returns:
- the number of bits
-
getBytes
public byte[] getBytes()- Specified by:
getBytes
in interfaceAddressItem
- Returns:
- the bytes of the lowest address item represented by this address item
-
getBytes
public byte[] getBytes(byte[] bytes) Description copied from interface:AddressItem
Copies the bytes of the lowest address item represented by this address item into the supplied array, and returns that array. If the supplied array is null or of insufficient size, a new array is created and returned.- Specified by:
getBytes
in interfaceAddressItem
- Returns:
- the bytes of the lowest address represented by this address item.
-
getBytes
public byte[] getBytes(byte[] bytes, int index) Description copied from interface:AddressItem
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. If the supplied array is null or of insufficient size, a new array is created and returned, with the rest of the array contents the same as the original.- Specified by:
getBytes
in interfaceAddressItem
- Returns:
- the bytes of the lowest address represented by this address item.
-
getUpperBytes
public byte[] getUpperBytes()- Specified by:
getUpperBytes
in interfaceAddressItem
- Returns:
- the bytes of the largest address item represented by this address item
-
getUpperBytes
public byte[] getUpperBytes(byte[] bytes) Description copied from interface:AddressItem
Copies the bytes of the largest address item represented by this address item into the supplied array, and returns that array. If the supplied array is null or of insufficient size, a new array is created and returned, with the rest of the array contents the same as the original.- Specified by:
getUpperBytes
in interfaceAddressItem
- Returns:
- the bytes of the largest address represented by this address item.
-
getUpperBytes
public byte[] getUpperBytes(byte[] bytes, int index) Description copied from interface:AddressItem
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. If the supplied array is null or of insufficient size, a new array is created and returned.- Specified by:
getUpperBytes
in interfaceAddressItem
- Returns:
- the bytes of the largest address represented by this address item.
-
getValue
Description copied from interface:AddressItem
Returns the lowest value represented by this address item, the lowest value included in the range of values- Specified by:
getValue
in interfaceAddressItem
- Returns:
- the lowest value represented by this address item
-
getUpperValue
Description copied from interface:AddressItem
Returns the highest value represented by this address item, the highest value included in the range of values- Specified by:
getUpperValue
in interfaceAddressItem
- Returns:
- the highest value represented by this address item
-
isZero
public boolean isZero()Description copied from interface:AddressItem
Returns whether this item matches the value of zero- Specified by:
isZero
in interfaceAddressItem
- Returns:
- whether this item matches the value of zero
-
includesZero
public boolean includesZero()Description copied from interface:AddressItem
Returns whether this item includes the value of zero within its range- Specified by:
includesZero
in interfaceAddressItem
- Returns:
- whether this item includes the value of zero within its range
-
isMax
public boolean isMax()Description copied from interface:AddressItem
Returns whether this item matches the maximum possible value for the address type or version- Specified by:
isMax
in interfaceAddressItem
- Returns:
- whether this item matches the maximum possible value
-
includesMax
public boolean includesMax()Description copied from interface:AddressItem
Returns whether this item includes the maximum possible value for the address type or version within its range- Specified by:
includesMax
in interfaceAddressItem
- Returns:
- whether this item includes the maximum possible value within its range
-