- 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. SeeIPAddressSeqRangefor 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 IPv4AddresscoverWithPrefixBlock()Returns the minimal-size prefix block that covers all the addresses in this range.longgetIPv4Count()Equivalent toIPAddressSeqRange.getCount()but returns a longlonggetIPv4PrefixCount(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()) { ...IPv4AddressgetLower()Returns the lowest address in the sequential range, the one with the lowest numeric valueintgetMinPrefixLengthForBlock()Returns the smallest prefix length possible such that this item includes the block of all values for that prefix length.java.math.BigIntegergetPrefixCount(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.IntegergetPrefixLengthForSingleBlock()Returns a prefix length for which the range of this item matches the block of all values for that prefix length.IPv4AddressgetUpper()Returns the highest address in the sequential range, the one with the highest numeric valueIPv4AddressSeqRangeintersect(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.IPv4AddressSeqRangejoin(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.StringtoIPv4String(java.util.function.Function<IPv4Address,java.lang.String> lowerStringer, java.lang.String separator, java.util.function.Function<IPv4Address,java.lang.String> upperStringer)IPv4AddressSeqRangetoSequentialRange()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:IPAddressSeqRangeReturns the lowest address in the sequential range, the one with the lowest numeric value- Specified by:
getLowerin interfaceAddressComponentRange- Specified by:
getLowerin interfaceIPAddressRange- Overrides:
getLowerin classIPAddressSeqRange- Returns:
-
getUpper
public IPv4Address getUpper()
Description copied from class:IPAddressSeqRangeReturns the highest address in the sequential range, the one with the highest numeric value- Specified by:
getUpperin interfaceAddressComponentRange- Specified by:
getUpperin interfaceIPAddressRange- Overrides:
getUpperin 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:AddressItemThe 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:
getPrefixCountin interfaceAddressItem- Returns:
-
getIterable
public java.lang.Iterable<IPv4Address> getIterable()
Description copied from interface:IPAddressRangeUseful for using an instance in a "for-each loop", as infor(addr : address.getIterable()) { ... }Otherwise just call
IPAddressRange.iterator()directly.- Specified by:
getIterablein interfaceAddressComponentRange- Specified by:
getIterablein interfaceIPAddressRange- Specified by:
getIterablein classIPAddressSeqRange- Returns:
-
iterator
public java.util.Iterator<IPv4Address> iterator()
Description copied from interface:IPAddressRangeIterates 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:
iteratorin interfaceAddressComponentRange- Specified by:
iteratorin interfaceIPAddressRange- Specified by:
iteratorin interfacejava.lang.Iterable<IPv4Address>- Specified by:
iteratorin classIPAddressSeqRange- Returns:
-
spliterator
public AddressComponentRangeSpliterator<IPv4AddressSeqRange,IPv4Address> spliterator()
Description copied from interface:IPAddressRangePartitions and traverses through the individual addresses.- Specified by:
spliteratorin interfaceAddressComponentRange- Specified by:
spliteratorin interfaceIPAddressRange- Specified by:
spliteratorin interfacejava.lang.Iterable<IPv4Address>- Specified by:
spliteratorin classIPAddressSeqRange- Returns:
-
stream
public java.util.stream.Stream<IPv4Address> stream()
Description copied from interface:AddressComponentRangeReturns a sequential stream of the individual address components. For a parallel stream, callBaseStream.parallel()on the returned stream.- Specified by:
streamin interfaceAddressComponentRange- Specified by:
streamin classIPAddressSeqRange- Returns:
-
prefixBlockIterator
public java.util.Iterator<IPv4Address> prefixBlockIterator(int prefLength)
Description copied from class:IPAddressSeqRangeIterates through the range of prefix blocks in this range instance using the given prefix length.- Specified by:
prefixBlockIteratorin interfaceIPAddressRange- Specified by:
prefixBlockIteratorin classIPAddressSeqRange- Returns:
-
prefixBlockSpliterator
public AddressComponentRangeSpliterator<IPv4AddressSeqRange,IPv4Address> prefixBlockSpliterator(int prefLength)
Description copied from interface:IPAddressRangePartitions and traverses through the individual prefix blocks for the given prefix length.- Specified by:
prefixBlockSpliteratorin interfaceIPAddressRange- Specified by:
prefixBlockSpliteratorin classIPAddressSeqRange- Returns:
-
prefixBlockStream
public java.util.stream.Stream<IPv4Address> prefixBlockStream(int prefLength)
Description copied from interface:IPAddressRangeReturns a sequential stream of the prefix blocks for the given prefix length. For a parallel stream, callBaseStream.parallel()on the returned stream.- Specified by:
prefixBlockStreamin interfaceIPAddressRange- Specified by:
prefixBlockStreamin classIPAddressSeqRange- Returns:
-
prefixIterator
public java.util.Iterator<IPv4AddressSeqRange> prefixIterator(int prefixLength)
Description copied from class:IPAddressSeqRangeIterates 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
IPAddressSeqRangeinstances.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:
prefixIteratorin interfaceIPAddressRange- Overrides:
prefixIteratorin classIPAddressSeqRange- Returns:
-
prefixStream
public java.util.stream.Stream<IPv4AddressSeqRange> prefixStream(int prefLength)
Description copied from interface:IPAddressRangeReturns a sequential stream of the individual prefixes for the given prefix length. For a parallel stream, callBaseStream.parallel()on the returned stream.- Specified by:
prefixStreamin interfaceIPAddressRange- Specified by:
prefixStreamin classIPAddressSeqRange- Returns:
-
prefixSpliterator
public AddressComponentSpliterator<IPv4AddressSeqRange> prefixSpliterator(int prefLength)
Description copied from interface:IPAddressRangePartitions and traverses through the individual prefixes for the given prefix length.- Specified by:
prefixSpliteratorin interfaceIPAddressRange- Specified by:
prefixSpliteratorin classIPAddressSeqRange- Returns:
-
coverWithPrefixBlock
public IPv4Address coverWithPrefixBlock()
Description copied from class:IPAddressSeqRangeReturns 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:
coverWithPrefixBlockin interfaceIPAddressRange- Specified by:
coverWithPrefixBlockin classIPAddressSeqRange
-
spanWithPrefixBlocks
public IPv4Address[] spanWithPrefixBlocks()
Description copied from interface:IPAddressRangeProduces an array of prefix blocks that spans the same set of addresses.- Specified by:
spanWithPrefixBlocksin interfaceIPAddressRange- Specified by:
spanWithPrefixBlocksin classIPAddressSeqRange
-
spanWithSequentialBlocks
public IPv4Address[] spanWithSequentialBlocks()
Description copied from interface:IPAddressRangeProduces 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:
spanWithSequentialBlocksin interfaceIPAddressRange- Specified by:
spanWithSequentialBlocksin classIPAddressSeqRange
-
getMinPrefixLengthForBlock
public int getMinPrefixLengthForBlock()
Description copied from interface:AddressItemReturns 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:
getMinPrefixLengthForBlockin interfaceAddressItem- Returns:
- the prefix length
-
getPrefixLengthForSingleBlock
public java.lang.Integer getPrefixLengthForSingleBlock()
Description copied from interface:AddressItemReturns 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:
getPrefixLengthForSingleBlockin 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:IPAddressSeqRangeReturns the intersection of this range with the given range, a range which includes those addresses in both this and the given range.- Overrides:
intersectin classIPAddressSeqRange- Returns:
-
join
public IPv4AddressSeqRange join(IPAddressSeqRange other)
Description copied from class:IPAddressSeqRangeJoins 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:
joinin classIPAddressSeqRange- Returns:
-
subtract
public IPv4AddressSeqRange[] subtract(IPAddressSeqRange other)
Description copied from class:IPAddressSeqRangeSubtracts 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:
subtractin classIPAddressSeqRange- Returns:
-
toSequentialRange
public IPv4AddressSeqRange toSequentialRange()
Description copied from interface:IPAddressRangeConverts 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:
toSequentialRangein interfaceIPAddressRange
-
-