- java.lang.Object
-
- inet.ipaddr.IPAddressSeqRange
-
- inet.ipaddr.ipv4.IPv4AddressSeqRange
-
- All Implemented Interfaces:
AddressComponentRange
,AddressItem
,AddressItemRange
,IPAddressRange
,java.io.Serializable
,java.lang.Comparable<AddressItem>
,java.lang.Iterable<IPv4Address>
public class IPv4AddressSeqRange extends IPAddressSeqRange implements java.lang.Iterable<IPv4Address>
Represents an arbitrary range of IPv4 addresses. SeeIPAddressSeqRange
for more details.- Author:
- sfoley
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class inet.ipaddr.IPAddressSeqRange
DEFAULT_RANGE_SEPARATOR
-
-
Constructor Summary
Constructors Constructor Description IPv4AddressSeqRange(IPv4Address first, IPv4Address second)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IPv4Address
coverWithPrefixBlock()
Returns the minimal-size prefix block that covers all the addresses in this range.long
getIPv4Count()
Equivalent toIPAddressSeqRange.getCount()
but returns a longlong
getIPv4PrefixCount(int prefixLength)
Equivalent togetPrefixCount(int)
but returns a longjava.lang.Iterable<IPv4Address>
getIterable()
Useful for using an instance in a "for-each loop", as infor(addr : address.getIterable()) { ...
IPv4Address
getLower()
Returns the lowest address in the sequential range, the one with the lowest numeric valueint
getMinPrefixLengthForBlock()
Returns the smallest prefix length possible such that this item includes the block of all values for that prefix length.java.math.BigInteger
getPrefixCount(int prefixLength)
The count of the number of distinct values within the prefix part of the address item, the bits that appear within the prefix length.java.lang.Integer
getPrefixLengthForSingleBlock()
Returns a prefix length for which the range of this item matches the block of all values for that prefix length.IPv4Address
getUpper()
Returns the highest address in the sequential range, the one with the highest numeric valueIPv4AddressSeqRange
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.java.util.Iterator<IPv4Address>
iterator()
Iterates through the individual addresses of this address or subnet.IPv4AddressSeqRange
join(IPAddressSeqRange other)
Joins two ranges if they are contiguous ranges.java.util.Iterator<IPv4Address>
prefixBlockIterator(int prefLength)
Iterates through the range of prefix blocks in this range instance using the given prefix length.AddressComponentRangeSpliterator<IPv4AddressSeqRange,IPv4Address>
prefixBlockSpliterator(int prefLength)
Partitions and traverses through the individual prefix blocks for the given prefix length.java.util.stream.Stream<IPv4Address>
prefixBlockStream(int prefLength)
Returns a sequential stream of the prefix blocks for the given prefix length.java.util.Iterator<IPv4AddressSeqRange>
prefixIterator(int prefixLength)
Iterates through the range of prefixes in this range instance using the given prefix length.AddressComponentSpliterator<IPv4AddressSeqRange>
prefixSpliterator(int prefLength)
Partitions and traverses through the individual prefixes for the given prefix length.java.util.stream.Stream<IPv4AddressSeqRange>
prefixStream(int prefLength)
Returns a sequential stream of the individual prefixes for the given prefix length.IPv4Address[]
spanWithPrefixBlocks()
Produces an array of prefix blocks that spans the same set of addresses.IPv4Address[]
spanWithSequentialBlocks()
Produces an array of blocks that are sequential that cover the same set of addresses.AddressComponentRangeSpliterator<IPv4AddressSeqRange,IPv4Address>
spliterator()
Partitions and traverses through the individual addresses.java.util.stream.Stream<IPv4Address>
stream()
Returns a sequential stream of the individual address components.IPv4AddressSeqRange[]
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.java.lang.String
toIPv4String(java.util.function.Function<IPv4Address,java.lang.String> lowerStringer, java.lang.String separator, java.util.function.Function<IPv4Address,java.lang.String> upperStringer)
IPv4AddressSeqRange
toSequentialRange()
Converts to a sequential range from the lowest and highest addresses in this range, returns "this" if one already-
Methods inherited from class inet.ipaddr.IPAddressSeqRange
contains, contains, containsPrefixBlock, containsSinglePrefixBlock, enumerate, equals, extend, getBitCount, getBytes, getBytes, getBytes, getCount, getUpperBytes, getUpperBytes, getUpperBytes, getUpperValue, getValue, hashCode, includesMax, includesZero, isMax, isMore, isMultiple, isSequential, isZero, join, overlaps, overlaps, toCanonicalString, toCanonicalString, toNormalizedString, toNormalizedString, toString, toString
-
Methods inherited from interface inet.ipaddr.format.AddressItem
compareTo, getByteCount, isFullRange
-
-
-
-
Constructor Detail
-
IPv4AddressSeqRange
public IPv4AddressSeqRange(IPv4Address first, IPv4Address second)
-
-
Method Detail
-
getLower
public IPv4Address getLower()
Description copied from class:IPAddressSeqRange
Returns the lowest address in the sequential range, the one with the lowest numeric value- Specified by:
getLower
in interfaceAddressComponentRange
- Specified by:
getLower
in interfaceIPAddressRange
- Overrides:
getLower
in classIPAddressSeqRange
- Returns:
-
getUpper
public IPv4Address getUpper()
Description copied from class:IPAddressSeqRange
Returns the highest address in the sequential range, the one with the highest numeric value- Specified by:
getUpper
in interfaceAddressComponentRange
- Specified by:
getUpper
in interfaceIPAddressRange
- Overrides:
getUpper
in classIPAddressSeqRange
- Returns:
-
getIPv4Count
public long getIPv4Count()
Equivalent toIPAddressSeqRange.getCount()
but returns a long- Returns:
-
getIPv4PrefixCount
public long getIPv4PrefixCount(int prefixLength)
Equivalent togetPrefixCount(int)
but returns a long- Returns:
-
getPrefixCount
public java.math.BigInteger getPrefixCount(int prefixLength)
Description copied from interface:AddressItem
The count of the number of distinct values within the prefix part of the address item, the bits that appear within the prefix length.- Specified by:
getPrefixCount
in interfaceAddressItem
- Returns:
-
getIterable
public java.lang.Iterable<IPv4Address> 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
- Specified by:
getIterable
in classIPAddressSeqRange
- Returns:
-
iterator
public java.util.Iterator<IPv4Address> 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
- Specified by:
iterator
in interfacejava.lang.Iterable<IPv4Address>
- Specified by:
iterator
in classIPAddressSeqRange
- Returns:
-
spliterator
public AddressComponentRangeSpliterator<IPv4AddressSeqRange,IPv4Address> spliterator()
Description copied from interface:IPAddressRange
Partitions and traverses through the individual addresses.- Specified by:
spliterator
in interfaceAddressComponentRange
- Specified by:
spliterator
in interfaceIPAddressRange
- Specified by:
spliterator
in interfacejava.lang.Iterable<IPv4Address>
- Specified by:
spliterator
in classIPAddressSeqRange
- Returns:
-
stream
public java.util.stream.Stream<IPv4Address> 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
- Specified by:
stream
in classIPAddressSeqRange
- Returns:
-
prefixBlockIterator
public java.util.Iterator<IPv4Address> prefixBlockIterator(int prefLength)
Description copied from class:IPAddressSeqRange
Iterates through the range of prefix blocks in this range instance using the given prefix length.- Specified by:
prefixBlockIterator
in interfaceIPAddressRange
- Specified by:
prefixBlockIterator
in classIPAddressSeqRange
- Returns:
-
prefixBlockSpliterator
public AddressComponentRangeSpliterator<IPv4AddressSeqRange,IPv4Address> 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
- Specified by:
prefixBlockSpliterator
in classIPAddressSeqRange
- Returns:
-
prefixBlockStream
public java.util.stream.Stream<IPv4Address> prefixBlockStream(int prefLength)
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
- Specified by:
prefixBlockStream
in classIPAddressSeqRange
- Returns:
-
prefixIterator
public java.util.Iterator<IPv4AddressSeqRange> prefixIterator(int prefixLength)
Description copied from class:IPAddressSeqRange
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
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.
- Specified by:
prefixIterator
in interfaceIPAddressRange
- Overrides:
prefixIterator
in classIPAddressSeqRange
- Returns:
-
prefixStream
public java.util.stream.Stream<IPv4AddressSeqRange> prefixStream(int prefLength)
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
- Specified by:
prefixStream
in classIPAddressSeqRange
- Returns:
-
prefixSpliterator
public AddressComponentSpliterator<IPv4AddressSeqRange> 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
- Specified by:
prefixSpliterator
in classIPAddressSeqRange
- Returns:
-
coverWithPrefixBlock
public IPv4Address coverWithPrefixBlock()
Description copied from class:IPAddressSeqRange
Returns the minimal-size prefix block that covers all the addresses in this range. The resulting block will have a larger count than this, unless this range already directly corresponds to a prefix block.- Specified by:
coverWithPrefixBlock
in interfaceIPAddressRange
- Specified by:
coverWithPrefixBlock
in classIPAddressSeqRange
-
spanWithPrefixBlocks
public IPv4Address[] spanWithPrefixBlocks()
Description copied from interface:IPAddressRange
Produces an array of prefix blocks that spans the same set of addresses.- Specified by:
spanWithPrefixBlocks
in interfaceIPAddressRange
- Specified by:
spanWithPrefixBlocks
in classIPAddressSeqRange
-
spanWithSequentialBlocks
public IPv4Address[] 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
- Specified by:
spanWithSequentialBlocks
in classIPAddressSeqRange
-
getMinPrefixLengthForBlock
public int getMinPrefixLengthForBlock()
Description copied from interface:AddressItem
Returns the smallest prefix length possible such that this item includes the block of all values for that prefix length.If the entire range can be dictated this way, then this method returns the same value as
AddressItem.getPrefixLengthForSingleBlock()
. Otherwise, this method will return the minimal possible prefix that can be paired with this address, whileAddressItem.getPrefixLengthForSingleBlock()
will return null.In cases where the final bit is constant so there is no such block, this returns the bit count.
- Specified by:
getMinPrefixLengthForBlock
in interfaceAddressItem
- Returns:
- the prefix length
-
getPrefixLengthForSingleBlock
public java.lang.Integer getPrefixLengthForSingleBlock()
Description copied from interface:AddressItem
Returns a prefix length for which the range of this item matches the block of all values for that prefix length.If the range can be dictated this way, then this method returns the same value as
AddressItem.getMinPrefixLengthForBlock()
.If no such prefix length exists, returns null.
If this item represents a single value, this returns the bit count.
- Specified by:
getPrefixLengthForSingleBlock
in interfaceAddressItem
- Returns:
- the prefix length or null
-
toIPv4String
public java.lang.String toIPv4String(java.util.function.Function<IPv4Address,java.lang.String> lowerStringer, java.lang.String separator, java.util.function.Function<IPv4Address,java.lang.String> upperStringer)
-
intersect
public IPv4AddressSeqRange intersect(IPAddressSeqRange other)
Description copied from class:IPAddressSeqRange
Returns the intersection of this range with the given range, a range which includes those addresses in both this and the given range.- Overrides:
intersect
in classIPAddressSeqRange
- Returns:
-
join
public IPv4AddressSeqRange join(IPAddressSeqRange other)
Description copied from class:IPAddressSeqRange
Joins two ranges if they are contiguous ranges. If this range overlaps 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.
- Overrides:
join
in classIPAddressSeqRange
- Returns:
-
subtract
public IPv4AddressSeqRange[] subtract(IPAddressSeqRange other)
Description copied from class:IPAddressSeqRange
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.- Overrides:
subtract
in classIPAddressSeqRange
- Returns:
-
toSequentialRange
public IPv4AddressSeqRange toSequentialRange()
Description copied from interface:IPAddressRange
Converts to a sequential range from the lowest and highest addresses in this range, returns "this" if one alreadyThe result will represent the same set of addresses if and only if
IPAddressRange.isSequential()
is true- Specified by:
toSequentialRange
in interfaceIPAddressRange
-
-