- All Implemented Interfaces:
AddressComponent
,AddressSegmentSeries
,AddressComponentRange
,AddressDivisionSeries
,AddressItem
,AddressItemRange
,IPAddressDivisionSeries
,IPAddressRange
,AddressStringDivisionSeries
,IPAddressStringDivisionSeries
,IPAddressSegmentSeries
,Serializable
,Comparable<AddressItem>
,Iterable<IPv4Address>
You can construct an IPv4 address from a byte array, from an int, from a Address.SegmentValueProvider
,
from Inet4Address, from an IPv4AddressSection
of 4 segments, or from an array of 4 IPv4AddressSegment
objects.
To construct one from a String
use
IPAddressString.toAddress()
or IPAddressString.getAddress()
, IPAddressString.toHostAddress()
or IPAddressString.getHostAddress()
- Author:
- sfoley
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
static interface
Nested classes/interfaces inherited from class inet.ipaddr.IPAddress
IPAddress.IPAddressValueProvider, IPAddress.IPVersion
Nested classes/interfaces inherited from class inet.ipaddr.Address
Address.AddressValueProvider, Address.SegmentValueProvider
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final String
static final int
static final char
Fields inherited from class inet.ipaddr.IPAddress
BINARY_STR_PREFIX, DEFAULT_ADDRESS_CONVERTER, PREFIX_LEN_SEPARATOR
Fields inherited from class inet.ipaddr.Address
ADDRESS_HIGH_VALUE_COMPARATOR, ADDRESS_LOW_VALUE_COMPARATOR, ALTERNATIVE_RANGE_SEPARATOR, ALTERNATIVE_RANGE_SEPARATOR_STR, ALTERNATIVE_SEGMENT_WILDCARD_STR, DEFAULT_ADDRESS_COMPARATOR, HEX_PREFIX, OCTAL_PREFIX, RANGE_SEPARATOR, RANGE_SEPARATOR_STR, SEGMENT_SQL_SINGLE_WILDCARD, SEGMENT_SQL_SINGLE_WILDCARD_STR, SEGMENT_SQL_WILDCARD, SEGMENT_SQL_WILDCARD_STR, SEGMENT_WILDCARD, SEGMENT_WILDCARD_STR
-
Constructor Summary
ConstructorsConstructorDescriptionIPv4Address
(byte[] bytes) Constructs an IPv4 address.IPv4Address
(byte[] bytes, int byteStartIndex, int byteEndIndex) Constructs an IPv4 address or subnet.IPv4Address
(byte[] bytes, int byteStartIndex, int byteEndIndex, Integer networkPrefixLength) Constructs an IPv4 address or subnet.IPv4Address
(byte[] bytes, Integer networkPrefixLength) Constructs an IPv4 address or subnet.IPv4Address
(int address) Constructs an IPv4 address.IPv4Address
(int address, Integer networkPrefixLength) Constructs an IPv4 address or subnet.IPv4Address
(Address.SegmentValueProvider valueProvider) Constructs an IPv4 address.IPv4Address
(Address.SegmentValueProvider lowerValueProvider, Address.SegmentValueProvider upperValueProvider) Constructs an IPv4 address or subnet.IPv4Address
(Address.SegmentValueProvider lowerValueProvider, Address.SegmentValueProvider upperValueProvider, Integer networkPrefixLength) Constructs an IPv4 address or subnet.IPv4Address
(Address.SegmentValueProvider valueProvider, Integer networkPrefixLength) Constructs an IPv4 address.IPv4Address
(IPv4AddressSection section) Constructs an IPv4 address or subnet.IPv4Address
(IPv4AddressSegment[] segments) Constructs an IPv4 address or subnet.IPv4Address
(IPv4AddressSegment[] segments, Integer networkPrefixLength) Constructs an IPv4 address or subnet.IPv4Address
(Inet4Address inet4Address) Constructs an IPv4 address.IPv4Address
(Inet4Address inet4Address, Integer networkPrefixLength) Constructs an IPv4 address. -
Method Summary
Modifier and TypeMethodDescriptionadjustPrefixBySegment
(boolean nextSegment) Increases or decreases prefix length to the next segment boundary.adjustPrefixBySegment
(boolean nextSegment, boolean zeroed) Increases or decreases prefix length to the next segment boundary.adjustPrefixLength
(int adjustment) Increases or decreases prefix length by the given increment.adjustPrefixLength
(int adjustment, boolean zeroed) Increases or decreases prefix length by the given increment.applyPrefixLength
(int networkPrefixLength) Deprecated.Constructs an equivalent address with the smallest CIDR prefix possible (largest network), such that the range of values are a set of subnet blocks for that prefix.Returns the equivalent CIDR address with a prefix length for which the address subnet block matches the range of values in this address.Equivalent to callingIPAddress.bitwiseOr(IPAddress, boolean)
with the second argument as false.Does the bitwise disjunction with this address.bitwiseOrNetwork
(IPAddress mask, int networkPrefixLength) Does the bitwise disjunction with this address.blockIterator
(int segmentCount) Iterates through series that can be obtained by iterating through all the upper segments up to the given segment count.blockSpliterator
(int segmentCount) Partitions and traverses through the individual sequential blocks created from each of the individual values up to the given segment count.blockStream
(int segmentCount) Returns a sequential stream of the individual blocks created from each of the individual values up to the given segment count.Returns the minimal-size prefix block that covers all the values in this series.coverWithPrefixBlock
(IPAddress other) Returns the minimal-size prefix block that covers all the addresses spanning from this subnet to the given subnet.int
Provides the number of bits comprising this address itemint
Provides the number of bytes required for this address item, rounding up if the bit count is not a multiple of 8getDivision
(int index) Returns the host mask associated with the CIDR network prefix length of this series.Returns the host section of the series.getHostSection
(int networkPrefixLength) Returns the host section of the address as indicated by the network prefix length provided.getIPv6Address
(IPv6AddressSegment[] segs) Create an IPv6 mixed address using the given ipv6 segments and using this address for the embedded IPv4 segmentsReturns the IPv6 network used bygetIPv4MappedAddress()
andgetIPv6Address(IPv6AddressSegment[])
Useful for using an instance in a "for-each loop".getLower()
If this represents a series with ranging values, returns a series representing the lower values of the range.Similar toIPAddressSegmentSeries.getLower()
, but will not return a series that has a prefix length and whose host value is zero.Returns the network object for components of the same version (eg IPv4, IPv6 and MAC each have their own network object)Returns the network mask associated with the CIDR network prefix length of this series.Returns the network section of the series if the series has a CIDR network prefix length, otherwise it returns the entire series as a prefixed series with prefix matching the address bit length.getNetworkSection
(int networkPrefixLength) Returns the network section of the series.getNetworkSection
(int networkPrefixLength, boolean withPrefixLength) Returns the network section of the series.Returns all the ways of breaking this address down into segments, as selected.Returns the address as an address section comprising all segments in the address.getSection
(int index) Gets the subsection from the series starting from the given index The first segment is at index 0.getSection
(int index, int endIndex) Gets the subsection from the series starting from the given index and ending just before the give endIndex The first segment is at index 0.getSegment
(int index) Returns the segment from this series at the given index.int
Returns the number of segments in this series.Returns the segments of this series of segments as an array.getUpper()
If this represents a series with ranging values, returns a series representing the upper values of the range If this represents a series with a single value in each segment, returns this.increment
(long increment) Returns the series from the subnet that is the given increment upwards into the subnet range, with the increment of 0 returning the first address in the range.incrementBoundary
(long increment) If the given increment is positive, adds the value to the upper series (AddressSegmentSeries.getUpper()
) in the subnet range to produce a new series.Produces the subnet whose addresses are found in both this and the given subnet argument, or null if no such addresses.int
intValue()
Returns the address (or lowest value of the address if a subnet) as a signed integerboolean
Determines whether this address can be converted to IPv4, if not IPv4 already.boolean
Override this method to convert in your own way.boolean
Returns whether the address is link local, whether unicast or multicast.boolean
isLocal()
Returns true if the address is link local, site local, organization local, administered locally, or unspecified.boolean
boolean
Whether the MAC address or IP address or other form of address is multicast.boolean
Unicast addresses allocated for private useiterator()
Iterates through the individual address components.long
Returns the address (or lowest value of the address if a subnet) as a positive integerEquivalent to callingIPAddress.mask(IPAddress, boolean)
with the second argument as false.Applies the given mask to all addresses represented by this IPAddress.maskNetwork
(IPAddress mask, int networkPrefixLength) Applies the given mask to all addresses represented by this IPAddress while also applying the given prefix length at the same time.mergeToPrefixBlocks
(IPAddress... addresses) Merges this with the list of addresses to produce the smallest list of prefix blocks.mergeToSequentialBlocks
(IPAddress... addresses) Merges this with the list of subnets to produce the smallest list of block subnets that are sequential.Similar to the iterator, but series with a host of zero are skipped.Iterates through the individual prefix blocks.prefixBlockIterator
(int prefixLength) Iterates through the range of prefix blocks in this range instance using the given prefix length.Partitions and traverses through the individual prefix blocks for the prefix length of this series.prefixBlockSpliterator
(int prefixLength) Partitions and traverses through the individual prefix blocks for the given prefix length.Returns a sequential stream of the individual prefix blocks for the prefix length of this series.prefixBlockStream
(int prefixLength) Returns a sequential stream of the prefix blocks for the given prefix length.Iterates through the individual prefixes.prefixIterator
(int prefixLength) Iterates through the range of prefixes in this range instance using the given prefix length.Partitions and traverses through the individual prefixes for the prefix length of this series.prefixSpliterator
(int prefixLength) Partitions and traverses through the individual prefixes for the given prefix length.Returns a sequential stream of the individual prefixes for the prefix length of this series.prefixStream
(int prefixLength) Returns a sequential stream of the individual prefixes for the given prefix length.Deprecated.removePrefixLength
(boolean zeroed) Deprecated.replace
(int startIndex, int endIndex, IPv4Address replacement, int replacementIndex) Replaces segments starting from startIndex and ending before endIndex with the same number of segments starting at replacementStartIndex from the replacement sectionreverseBits
(boolean perByte) Returns a new segment series with the bits reversed.Returns a new segment series with the bytes reversed.Returns a new segment series with the bytes reversed within each segment.Returns a new segment series with the segments reversed.Iterates through the individual segments.Similar to the segments iterator, but series with a host of zero are skipped.Partitions and traverses through the individual segment arrays.Returns a sequential stream of the individual segment arrays.Iterates through the sequential series that make up this series.Partitions and traverses through the individual sequential blocks.Returns a sequential stream of the individual sequential blocks.setPrefixLength
(int prefixLength) Sets the prefix length.setPrefixLength
(int prefixLength, boolean zeroed) Sets the prefix length.setPrefixLength
(int prefixLength, boolean zeroed, boolean zeroHostIsBlock) Sets the prefix length while allowing the caller to control whether bits moved in or out of the prefix become zero, and whether a zero host for the new prefix bits can be translated into a prefix block.Produces an array of prefix blocks that cover the same set of addresses as this.spanWithPrefixBlocks
(IPAddress other) Produces the list of prefix block subnets that span from this subnet to the given subnet.spanWithRange
(IPAddress other) Deprecated.Produces an array of blocks that are sequential that cover the same set of addresses as this.Produces a list of sequential block subnets that span all values from this subnet to the given subnet.Partitions and traverses through the individual address components.stream()
Returns a sequential stream of the individual address components.Subtract the given subnet from this subnet, returning an array of subnets for the result (the subnets will not be contiguous so an array is required).The broadcast address has the same prefix but a host that is all 1 bits.Converts the lowest value of this address to an InetAddressReturns a string like the inet_aton style stringtoInetAtonString
(IPv4Address.inet_aton_radix radix, int joinedCount) toIPv4()
If this address is IPv4, or can be converted to IPv4, returns thatIPv4Address
.toIPv6()
Returns this address converted to IPv6.Returns the segment series with a host of all ones.toMaxHost
(int prefixLength) Produces the series with host values of all one bits for the given prefix length.The network address has the same prefix but a zero host.static String
toNormalizedString
(IPv4AddressNetwork network, Address.SegmentValueProvider lowerValueProvider, Address.SegmentValueProvider upperValueProvider, Integer prefixLength) Creates the normalized string for an address without having to create the address objects first.Returns the subnet associated with the prefix length of this address.toPrefixBlock
(int networkPrefixLength) Returns the segment series of the same length that spans all hosts.Writes this IP address segment series as a segments of binary values preceded by the "0b" prefix.Creates a sequential range instance from the lowest and highest addresses in this subnettoSequentialRange
(IPAddress other) Creates a sequential range instance from this and the given address, spanning from the lowest to the highest addresses in the two subnetsGenerates the Microsoft UNC path component for this addressConverts the highest value of this address to an InetAddress.Returns the segment series with a host of zero, the host being the bits following the prefix length.toZeroHost
(int prefixLength) Produces the series with host values of 0 for the given prefix length.Returns the segment series with a network of zero, the network being the bits within the prefix length.int
Returns the address (or highest value of the address if a subnet) as a signed integerlong
Returns the address (or highest value of the address if a subnet) as a positive integerProvides the same address with no prefix.Methods inherited from class inet.ipaddr.IPAddress
applyToBounds, contains, contains, containsNonZeroHosts, getBitCount, getBitsPerSegment, getBlockMaskPrefixLength, getByteCount, getBytesPerSegment, getIPVersion, getLeadingBitCount, getMatchesSQLClause, getMatchesSQLClause, getMaxSegmentValue, getNetworkPrefixLength, getNonZeroHostCount, getSegmentCount, getSequentialBlockCount, getTrailingBitCount, includesMaxHost, includesMaxHost, includesZeroHost, includesZeroHost, isAnyLocal, isIPv4, isIPv6, isSingleNetwork, isUnspecified, isZeroHost, isZeroHost, matches, matchesWithMask, prefixContains, removeBitCountPrefixLength, toAddressString, toAllStrings, toBinaryString, toCanonicalHostName, toCanonicalWildcardString, toCompressedWildcardString, toConvertedString, toDelimitedSQLStrs, toFullString, toHostName, toNormalizedString, toNormalizedString, toNormalizedString, toNormalizedWildcardString, toOctalString, toPrefixLengthString, toReverseDNSLookupString, toSQLWildcardString, toStandardStrings, toStrings, toSubnetString
Methods inherited from class inet.ipaddr.Address
contains, containsPrefixBlock, containsSinglePrefixBlock, defaultIpv4Network, defaultIpv6Network, defaultMACNetwork, equals, getBlockCount, getBytes, getBytes, getBytes, getCount, getDivisionCount, getDivisionStrings, getMinPrefixLengthForBlock, getPrefixCount, getPrefixCount, getPrefixLength, getPrefixLengthForSingleBlock, getSegments, getSegments, getSegmentStrings, getUpperBytes, getUpperBytes, getUpperBytes, getUpperValue, getValue, hashCode, includesMax, includesZero, isFullRange, isMax, isMore, isMultiple, isPrefixBlock, isPrefixed, isSameAddress, isSequential, isSinglePrefixBlock, isZero, prefixEquals, toCanonicalString, toCompressedString, toHexString, toNormalizedString, toString
Methods inherited from interface inet.ipaddr.AddressComponent
toHexString, toNormalizedString
Methods inherited from interface inet.ipaddr.format.AddressDivisionSeries
getBlockCount, getCount, getDivisionStrings, getPrefixCount, getPrefixCount, getPrefixLength, getSequentialBlockIndex, isMore, isPrefixBlock, isPrefixed, isSequential, isSinglePrefixBlock
Methods inherited from interface inet.ipaddr.format.AddressItem
compareTo, containsPrefixBlock, containsSinglePrefixBlock, getBytes, getBytes, getBytes, getMinPrefixLengthForBlock, getPrefixLengthForSingleBlock, getUpperBytes, getUpperBytes, getUpperBytes, getUpperValue, getValue, includesMax, includesZero, isFullRange, isMax, isMultiple, isZero
Methods inherited from interface inet.ipaddr.AddressSegmentSeries
getSegments, getSegments, getSegmentStrings, isOneBit, testBit, toCanonicalString, toCompressedString
Methods inherited from interface inet.ipaddr.format.string.AddressStringDivisionSeries
getDivisionCount
Methods inherited from interface inet.ipaddr.format.IPAddressRange
isSequential, toCanonicalString, toNormalizedString
Methods inherited from interface inet.ipaddr.format.string.IPAddressStringDivisionSeries
getPrefixLength, isPrefixBlock, isPrefixed
-
Field Details
-
SEGMENT_SEPARATOR
public static final char SEGMENT_SEPARATOR- See Also:
-
BITS_PER_SEGMENT
public static final int BITS_PER_SEGMENT- See Also:
-
BYTES_PER_SEGMENT
public static final int BYTES_PER_SEGMENT- See Also:
-
SEGMENT_COUNT
public static final int SEGMENT_COUNT- See Also:
-
BYTE_COUNT
public static final int BYTE_COUNT- See Also:
-
BIT_COUNT
public static final int BIT_COUNT- See Also:
-
DEFAULT_TEXTUAL_RADIX
public static final int DEFAULT_TEXTUAL_RADIX- See Also:
-
MAX_VALUE_PER_SEGMENT
public static final int MAX_VALUE_PER_SEGMENT- See Also:
-
MAX_VALUE
public static final int MAX_VALUE- See Also:
-
REVERSE_DNS_SUFFIX
- See Also:
-
-
Constructor Details
-
IPv4Address
Constructs an IPv4 address or subnet.- Parameters:
segments
- the address segments- Throws:
AddressValueException
- if segments is not length 4
-
IPv4Address
public IPv4Address(IPv4AddressSegment[] segments, Integer networkPrefixLength) throws AddressValueException Constructs an IPv4 address or subnet.When networkPrefixLength is non-null, depending on the prefix configuration (see
AddressNetwork.getPrefixConfiguration()
, this object may represent either a single address with that network prefix length, or the prefix subnet block containing all addresses with the same network prefix.- Parameters:
segments
- the address segmentsnetworkPrefixLength
-- Throws:
AddressValueException
- if segments is not length 4
-
IPv4Address
Constructs an IPv4 address or subnet.- Parameters:
section
- the address segments- Throws:
AddressValueException
- if section does not have 4 segments
-
IPv4Address
public IPv4Address(int address) Constructs an IPv4 address.- Parameters:
address
- the 4 byte IPv4 address
-
IPv4Address
Constructs an IPv4 address or subnet.When networkPrefixLength is non-null, depending on the prefix configuration (see
AddressNetwork.getPrefixConfiguration()
, this object may represent either a single address with that network prefix length, or the prefix subnet block containing all addresses with the same network prefix.- Parameters:
address
- the 4 byte IPv4 addressnetworkPrefixLength
- the CIDR network prefix length, which can be null for no prefix- Throws:
AddressValueException
-
IPv4Address
Constructs an IPv4 address.- Parameters:
inet4Address
- the java.net address object
-
IPv4Address
Constructs an IPv4 address.- Parameters:
inet4Address
- the java.net address object
-
IPv4Address
Constructs an IPv4 address.- Parameters:
bytes
- the 4 byte IPv4 address in network byte order - if longer than 4 bytes the additional bytes must be zero, if shorter than 4 bytes then then the bytes are sign-extended to 4 bytes.- Throws:
AddressValueException
- if bytes not equivalent to a 4 byte address
-
IPv4Address
Constructs an IPv4 address or subnet.Similar to
IPv4Address(byte[])
except that you can specify the start and end of the address in the given byte array.- Parameters:
bytes
-- Throws:
AddressValueException
-
IPv4Address
Constructs an IPv4 address or subnet.When networkPrefixLength is non-null, depending on the prefix configuration (see
AddressNetwork.getPrefixConfiguration()
, this object may represent either a single address with that network prefix length, or the prefix subnet block containing all addresses with the same network prefix.- Parameters:
bytes
- the 4 byte IPv4 address in network byte order - if longer than 4 bytes the additional bytes must be zero, if shorter than 4 bytes then the bytes are sign-extended to 4 bytes.networkPrefixLength
- the CIDR network prefix length, which can be null for no prefix- Throws:
AddressValueException
- if bytes not equivalent to a 4 byte address
-
IPv4Address
public IPv4Address(byte[] bytes, int byteStartIndex, int byteEndIndex, Integer networkPrefixLength) throws AddressValueException Constructs an IPv4 address or subnet.Similar to
IPv4Address(byte[],Integer)
except that you can specify the start and end of the address in the given byte array.When networkPrefixLength is non-null, depending on the prefix configuration (see
AddressNetwork.getPrefixConfiguration()
, this object may represent either a single address with that network prefix length, or the prefix subnet block containing all addresses with the same network prefix.- Parameters:
bytes
- the 4 byte IPv4 address - if longer than 4 bytes the additional bytes must be zero, if shorter than 4 bytes then the bytes are sign-extended to 4 bytes.networkPrefixLength
- the CIDR network prefix length, which can be null for no prefix- Throws:
AddressValueException
- if bytes not equivalent to a 4 byte address
-
IPv4Address
public IPv4Address(Address.SegmentValueProvider lowerValueProvider, Address.SegmentValueProvider upperValueProvider, Integer networkPrefixLength) throws AddressValueException Constructs an IPv4 address or subnet.When networkPrefixLength is non-null, depending on the prefix configuration (see
AddressNetwork.getPrefixConfiguration()
, this object may represent either a single address with that network prefix length, or the prefix subnet block containing all addresses with the same network prefix.- Parameters:
lowerValueProvider
- supplies the 1 byte lower values for each segmentupperValueProvider
- supplies the 1 byte upper values for each segmentnetworkPrefixLength
- the CIDR network prefix length, which can be null for no prefix- Throws:
AddressValueException
-
IPv4Address
public IPv4Address(Address.SegmentValueProvider lowerValueProvider, Address.SegmentValueProvider upperValueProvider) Constructs an IPv4 address or subnet.- Parameters:
lowerValueProvider
- supplies the 1 byte lower values for each segmentupperValueProvider
- supplies the 1 byte upper values for each segment
-
IPv4Address
public IPv4Address(Address.SegmentValueProvider valueProvider, Integer networkPrefixLength) throws AddressValueException Constructs an IPv4 address.When networkPrefixLength is non-null, depending on the prefix configuration (see
AddressNetwork.getPrefixConfiguration()
, this object may represent either a single address with that network prefix length, or the prefix subnet block containing all addresses with the same network prefix.- Parameters:
valueProvider
- supplies the 1 byte value for each segmentnetworkPrefixLength
- the CIDR network prefix length, which can be null for no prefix- Throws:
AddressValueException
-
IPv4Address
Constructs an IPv4 address.- Parameters:
valueProvider
- supplies the 1 byte value for each segment
-
-
Method Details
-
getSection
Description copied from class:IPAddress
Returns the address as an address section comprising all segments in the address.- Specified by:
getSection
in interfaceAddressSegmentSeries
- Specified by:
getSection
in interfaceIPAddressSegmentSeries
- Overrides:
getSection
in classIPAddress
- Returns:
-
getSection
Description copied from interface:AddressSegmentSeries
Gets the subsection from the series starting from the given index The first segment is at index 0.- Specified by:
getSection
in interfaceAddressSegmentSeries
- Specified by:
getSection
in interfaceIPAddressSegmentSeries
- Overrides:
getSection
in classIPAddress
- Parameters:
index
-- Returns:
-
getSection
Description copied from interface:AddressSegmentSeries
Gets the subsection from the series starting from the given index and ending just before the give endIndex The first segment is at index 0.- Specified by:
getSection
in interfaceAddressSegmentSeries
- Specified by:
getSection
in interfaceIPAddressSegmentSeries
- Overrides:
getSection
in classIPAddress
- Parameters:
index
-endIndex
-- Returns:
-
getDivision
- Specified by:
getDivision
in interfaceAddressDivisionSeries
- Specified by:
getDivision
in interfaceAddressStringDivisionSeries
- Specified by:
getDivision
in interfaceIPAddressDivisionSeries
- Specified by:
getDivision
in interfaceIPAddressStringDivisionSeries
- Returns:
- the given division in this series. The first is at index 0.
-
getSegment
Description copied from interface:AddressSegmentSeries
Returns the segment from this series at the given index. The first segment is at index 0. A segment is an address division, seeAddressDivisionSeries.getDivision(int)
, the difference being that all segments in a given series are the same bit count, while divisions can have variable length.- Specified by:
getSegment
in interfaceAddressSegmentSeries
- Specified by:
getSegment
in interfaceIPAddressSegmentSeries
- Returns:
-
getSegments
Description copied from interface:AddressSegmentSeries
Returns the segments of this series of segments as an array. This must create a new array, so for efficiency useAddressSegmentSeries.getSegment(int)
andAddressSegmentSeries.getSegmentCount()
instead when feasible.- Specified by:
getSegments
in interfaceAddressSegmentSeries
- Specified by:
getSegments
in interfaceIPAddressSegmentSeries
- Returns:
-
getParts
Description copied from class:IPAddress
Returns all the ways of breaking this address down into segments, as selected. -
getParts
public IPAddressStringDivisionSeries[] getParts(IPv4AddressSection.IPv4StringBuilderOptions options) -
getSegmentCount
public int getSegmentCount()Description copied from interface:AddressSegmentSeries
Returns the number of segments in this series.- Specified by:
getSegmentCount
in interfaceAddressSegmentSeries
- Overrides:
getSegmentCount
in classAddress
- Returns:
-
getByteCount
public int getByteCount()Description copied from interface:AddressItem
Provides the number of bytes required for this address item, rounding up if the bit count is not a multiple of 8- Specified by:
getByteCount
in interfaceAddressItem
- Overrides:
getByteCount
in classIPAddress
- Returns:
- the number of bytes
-
getBitCount
public int getBitCount()Description copied from interface:AddressItem
Provides the number of bits comprising this address item- Specified by:
getBitCount
in interfaceAddressDivisionSeries
- Specified by:
getBitCount
in interfaceAddressItem
- Overrides:
getBitCount
in classAddress
- Returns:
- the number of bits
-
toIPv4
Description copied from class:IPAddress
If this address is IPv4, or can be converted to IPv4, returns thatIPv4Address
. Otherwise, returns null. -
isIPv4Convertible
public boolean isIPv4Convertible()Description copied from class:IPAddress
Determines whether this address can be converted to IPv4, if not IPv4 already. Override this method to convert in your own way. If IPv6, the default behaviour is to convert by IPv4 mapping, seeIPv6Address.isIPv4Mapped()
You should also overrideIPAddress.toIPv4()
to match the conversion. This method returns true for all IPv4 addresses.- Specified by:
isIPv4Convertible
in classIPAddress
- Returns:
-
getIPv6Address
Create an IPv6 mixed address using the given ipv6 segments and using this address for the embedded IPv4 segments- Parameters:
segs
-- Returns:
-
getIPv4MappedAddress
-
isIPv6Convertible
public boolean isIPv6Convertible()Override this method to convert in your own way. The default behaviour uses IPv4-mapped conversion. You should also overridetoIPv6()
to match the conversion.- Specified by:
isIPv6Convertible
in classIPAddress
- Returns:
- See Also:
-
toIPv6
Returns this address converted to IPv6.You can also use
isIPv6Convertible()
to determine convertibility. Both use an instance ofIPAddressConverter.DefaultAddressConverter
which uses IPv4-mapped address mappings from rfc 4038.Override this method and
IPv6Address.isIPv6Convertible()
if you wish to map IPv4 to IPv6 according to the mappings defined by inIPv6Address.isIPv4Compatible()
,IPv6Address.isIPv4Mapped()
,IPv6Address.is6To4()
or some other mapping.If you override this method, you should also override the
isIPv6Convertible()
method to match this behaviour, and potentially also override the reverse conversionIPv6Address.toIPv4()
in yourIPv6Address
subclass.- Overrides:
toIPv6
in classIPAddress
- Returns:
- If this address is IPv6, or can be converted to IPv6, returns that
IPv6Address
. Otherwise, returns null. - See Also:
-
toBroadcastAddress
The broadcast address has the same prefix but a host that is all 1 bits. If this address or subnet is not prefixed, this returns the address of all 1 bits, the "max" address.- Returns:
-
toNetworkAddress
The network address has the same prefix but a zero host. If this address or subnet is not prefixed, this returns the zero "any" address.- Returns:
-
getLowerNonZeroHost
Description copied from interface:IPAddressSegmentSeries
Similar toIPAddressSegmentSeries.getLower()
, but will not return a series that has a prefix length and whose host value is zero. If this series has no prefix length, returns the same series asIPAddressSegmentSeries.getLower()
.- Specified by:
getLowerNonZeroHost
in interfaceIPAddressSegmentSeries
- Specified by:
getLowerNonZeroHost
in classIPAddress
- Returns:
- the lowest IP address series whose host is non-zero, or null if no such address section exists.
-
getLower
Description copied from interface:AddressSegmentSeries
If this represents a series with ranging values, returns a series representing the lower values of the range. If this represents an series with a single value in each segment, returns this.- Specified by:
getLower
in interfaceAddressComponentRange
- Specified by:
getLower
in interfaceAddressSegmentSeries
- Specified by:
getLower
in interfaceIPAddressRange
- Specified by:
getLower
in interfaceIPAddressSegmentSeries
- Specified by:
getLower
in classIPAddress
- Returns:
-
getUpper
Description copied from interface:AddressSegmentSeries
If this represents a series with ranging values, returns a series representing the upper values of the range If this represents a series with a single value in each segment, returns this.- Specified by:
getUpper
in interfaceAddressComponentRange
- Specified by:
getUpper
in interfaceAddressSegmentSeries
- Specified by:
getUpper
in interfaceIPAddressRange
- Specified by:
getUpper
in interfaceIPAddressSegmentSeries
- Specified by:
getUpper
in classIPAddress
- Returns:
-
intValue
public int intValue()Returns the address (or lowest value of the address if a subnet) as a signed integer- Returns:
- the signed integer lower address value
-
upperIntValue
public int upperIntValue()Returns the address (or highest value of the address if a subnet) as a signed integer- Returns:
- the signed integer upper address value
-
longValue
public long longValue()Returns the address (or lowest value of the address if a subnet) as a positive integer- Returns:
- the positive integer lower address value
-
upperLongValue
public long upperLongValue()Returns the address (or highest value of the address if a subnet) as a positive integer- Returns:
- the positive integer upper address value
-
replace
public IPv4Address replace(int startIndex, int endIndex, IPv4Address replacement, int replacementIndex) Replaces segments starting from startIndex and ending before endIndex with the same number of segments starting at replacementStartIndex from the replacement section- Parameters:
startIndex
-endIndex
-replacement
-replacementIndex
-- Returns:
- Throws:
IndexOutOfBoundsException
-
reverseBits
Description copied from interface:AddressSegmentSeries
Returns a new segment series with the bits reversed.- Specified by:
reverseBits
in interfaceAddressComponent
- Specified by:
reverseBits
in interfaceAddressSegmentSeries
- Specified by:
reverseBits
in interfaceIPAddressSegmentSeries
- Specified by:
reverseBits
in classIPAddress
- Parameters:
perByte
- if true, only the bits in each byte are reversed, if false, then all bits in the component are reversed- Returns:
-
reverseBytes
Description copied from interface:AddressSegmentSeries
Returns a new segment series with the bytes reversed.- Specified by:
reverseBytes
in interfaceAddressComponent
- Specified by:
reverseBytes
in interfaceAddressSegmentSeries
- Specified by:
reverseBytes
in interfaceIPAddressSegmentSeries
- Specified by:
reverseBytes
in classIPAddress
- Returns:
-
reverseBytesPerSegment
Description copied from interface:AddressSegmentSeries
Returns a new segment series with the bytes reversed within each segment.- Specified by:
reverseBytesPerSegment
in interfaceAddressSegmentSeries
- Specified by:
reverseBytesPerSegment
in interfaceIPAddressSegmentSeries
- Specified by:
reverseBytesPerSegment
in classIPAddress
- Returns:
-
reverseSegments
Description copied from interface:AddressSegmentSeries
Returns a new segment series with the segments reversed. This does not throwIncompatibleAddressException
since all address series can reverse their segments.- Specified by:
reverseSegments
in interfaceAddressSegmentSeries
- Specified by:
reverseSegments
in interfaceIPAddressSegmentSeries
- Specified by:
reverseSegments
in classIPAddress
- Returns:
-
adjustPrefixBySegment
Description copied from interface:AddressSegmentSeries
Increases or decreases prefix length to the next segment boundary.Follows the same rules as
AddressSegmentSeries.adjustPrefixLength(int)
:
When prefix length is increased, the bits moved within the prefix become zero. When a prefix length is decreased, the bits moved outside the prefix become zero. To avoid the zeroing behaviour, useAddressSegmentSeries.adjustPrefixBySegment(boolean, boolean)
with second arg false.- Specified by:
adjustPrefixBySegment
in interfaceAddressSegmentSeries
- Specified by:
adjustPrefixBySegment
in interfaceIPAddressSegmentSeries
- Specified by:
adjustPrefixBySegment
in classIPAddress
- Parameters:
nextSegment
- whether to move prefix to previous or following segment boundary- Returns:
-
adjustPrefixBySegment
Description copied from interface:AddressSegmentSeries
Increases or decreases prefix length to the next segment boundary.- Specified by:
adjustPrefixBySegment
in interfaceAddressSegmentSeries
- Specified by:
adjustPrefixBySegment
in interfaceIPAddressSegmentSeries
- Specified by:
adjustPrefixBySegment
in classIPAddress
- Parameters:
nextSegment
- whether to move prefix to previous or following segment boundaryzeroed
- whether the bits that move from one side of the prefix to the other become zero or retain their original values- Returns:
-
adjustPrefixLength
Description copied from class:IPAddress
Increases or decreases prefix length by the given increment.When prefix length is increased, the bits moved within the prefix become zero. When the prefix is extended beyond the segment series boundary, it is removed. When a prefix length is decreased, the bits moved outside the prefix become zero, and if the entire host address contains the zero address, then the resulting address is determined
AddressNetwork.getPrefixConfiguration()
.For example, 1.2.0.0/16 adjusted by -8 becomes 1.0.0.0/8.
1.2.0.0/16 adjusted by 8 becomes 1.2.0.0/24- Specified by:
adjustPrefixLength
in interfaceAddressSegmentSeries
- Specified by:
adjustPrefixLength
in interfaceIPAddressSegmentSeries
- Specified by:
adjustPrefixLength
in classIPAddress
- Parameters:
adjustment
-- Returns:
-
adjustPrefixLength
Description copied from interface:AddressSegmentSeries
Increases or decreases prefix length by the given increment.- Specified by:
adjustPrefixLength
in interfaceAddressSegmentSeries
- Specified by:
adjustPrefixLength
in interfaceIPAddressSegmentSeries
- Specified by:
adjustPrefixLength
in classIPAddress
- Parameters:
adjustment
- the incrementzeroed
- whether the bits that move from one side of the prefix to the other become zero or retain their original values- Returns:
-
setPrefixLength
Description copied from interface:AddressSegmentSeries
Sets the prefix length.If this series has a prefix length, and the prefix length is increased, the bits moved within the prefix become zero. For an alternative that does not set bits to zero, use
AddressSegmentSeries.setPrefixLength(int, boolean)
with the second argument as false.When the prefix is extended beyond the segment series boundary, it is removed.
The bits that move from one side of the prefix length to the other (ie bits moved into the prefix or outside the prefix) are zeroed.
- Specified by:
setPrefixLength
in interfaceAddressSegmentSeries
- Specified by:
setPrefixLength
in interfaceIPAddressSegmentSeries
- Specified by:
setPrefixLength
in classIPAddress
- Parameters:
prefixLength
-- Returns:
-
setPrefixLength
Description copied from interface:AddressSegmentSeries
Sets the prefix length.When the prefix is extended beyond the segment series boundary, it is removed.
- Specified by:
setPrefixLength
in interfaceAddressSegmentSeries
- Specified by:
setPrefixLength
in interfaceIPAddressSegmentSeries
- Specified by:
setPrefixLength
in classIPAddress
- Parameters:
zeroed
- whether the bits that move from one side of the prefix length to the other (ie bits moved into the prefix or outside the prefix) are zeroed.- Returns:
-
setPrefixLength
public IPv4Address setPrefixLength(int prefixLength, boolean zeroed, boolean zeroHostIsBlock) throws PrefixLenException Description copied from class:IPAddress
Sets the prefix length while allowing the caller to control whether bits moved in or out of the prefix become zero, and whether a zero host for the new prefix bits can be translated into a prefix block. The latter behaviour only applies to the default prefix handling configuration, PREFIXED_ZERO_HOSTS_ARE_SUBNETS. The methodsIPAddress.setPrefixLength(int, boolean)
andIPAddress.setPrefixLength(int)
use a value of true for zeroed and for zeroHostIsBlock.For example, when zeroHostIsBlock is true, applying to 1.2.0.0 the prefix length 16 results in 1.2.*.*/16
Or if you start with 1.2.0.0/24, setting the prefix length to 16 results in a zero host followed by the existing prefix block, which is then converted to a full prefix block, 1.2.*.*/16
When both zeroed and zeroHostIsBlock are true, applying the prefiix length of 16 to 1.2.4.0/24 also results in a zero host followed by the existing prefix block, which is then converted to a full prefix block, 1.2.*.*/16.
When both zeroed and zeroHostIsBlock are false, the resulting address always encompasses the same set of addresses as the original, albeit with a different prefix length.
- Specified by:
setPrefixLength
in classIPAddress
- Parameters:
prefixLength
-zeroed
-zeroHostIsBlock
-- Returns:
- Throws:
PrefixLenException
-
applyPrefixLength
Deprecated.Description copied from interface:AddressSegmentSeries
Applies the given prefix length to create a new segment series.Similar to
AddressSegmentSeries.setPrefixLength(int)
except that prefix lengths are never increased. When this series already has a prefix length that is less than or equal to the requested prefix length, this series is returned.Otherwise the returned series has the given prefix length.
The bits moved outside the prefix will become zero in the returned series.
- Specified by:
applyPrefixLength
in interfaceAddressSegmentSeries
- Specified by:
applyPrefixLength
in interfaceIPAddressSegmentSeries
- Specified by:
applyPrefixLength
in classIPAddress
- Parameters:
networkPrefixLength
-- Returns:
- Throws:
PrefixLenException
- See Also:
-
removePrefixLength
Deprecated.Description copied from interface:AddressSegmentSeries
Removes the prefix length. If zeroed is false, the bits that were host bits do not become zero, unlikeAddressSegmentSeries.removePrefixLength()
- Specified by:
removePrefixLength
in interfaceAddressSegmentSeries
- Specified by:
removePrefixLength
in interfaceIPAddressSegmentSeries
- Specified by:
removePrefixLength
in classIPAddress
- Parameters:
zeroed
- whether the bits outside the prefix become zero- Returns:
-
withoutPrefixLength
Description copied from interface:AddressSegmentSeries
Provides the same address with no prefix. The values remain unchanged.Use
AddressSegmentSeries.removePrefixLength()
as an alternative that deletes the host at the same time by zeroing the host values.- Specified by:
withoutPrefixLength
in interfaceAddressSegmentSeries
- Specified by:
withoutPrefixLength
in interfaceIPAddressSegmentSeries
- Specified by:
withoutPrefixLength
in classIPAddress
-
removePrefixLength
Deprecated.Description copied from interface:AddressSegmentSeries
Removes the prefix length while zeroing out the bits beyond the prefix.If the series already has a prefix length, the bits outside the prefix become zero. Use
AddressSegmentSeries.withoutPrefixLength()
to remove the prefix length without changing the series values.Equivalent to calling removePrefixLength(true)
- Specified by:
removePrefixLength
in interfaceAddressSegmentSeries
- Specified by:
removePrefixLength
in interfaceIPAddressSegmentSeries
- Specified by:
removePrefixLength
in classIPAddress
- Returns:
- See Also:
-
segmentsNonZeroHostIterator
Description copied from interface:IPAddressSegmentSeries
Similar to the segments iterator, but series with a host of zero are skipped.- Specified by:
segmentsNonZeroHostIterator
in interfaceIPAddressSegmentSeries
- Returns:
-
segmentsIterator
Description copied from interface:AddressSegmentSeries
Iterates through the individual segments.- Specified by:
segmentsIterator
in interfaceAddressSegmentSeries
- Specified by:
segmentsIterator
in interfaceIPAddressSegmentSeries
-
segmentsSpliterator
Description copied from interface:AddressSegmentSeries
Partitions and traverses through the individual segment arrays.- Specified by:
segmentsSpliterator
in interfaceAddressSegmentSeries
- Specified by:
segmentsSpliterator
in interfaceIPAddressSegmentSeries
- Returns:
-
segmentsStream
Description copied from interface:AddressSegmentSeries
Returns a sequential stream of the individual segment arrays. For a parallel stream, callBaseStream.parallel()
on the returned stream.- Specified by:
segmentsStream
in interfaceAddressSegmentSeries
- Specified by:
segmentsStream
in interfaceIPAddressSegmentSeries
- Returns:
-
iterator
Description copied from interface:AddressComponentRange
Iterates through the individual address components.An address component can represent an individual segment, address, or section, or it can represent multiple, typically a subnet of addresses or a range of segment or section values.
Call
AddressItem.isMultiple()
to determine if this instance represents multiple, orAddressItem.getCount()
for the count.- Specified by:
iterator
in interfaceAddressComponentRange
- Specified by:
iterator
in interfaceAddressSegmentSeries
- Specified by:
iterator
in interfaceIPAddressRange
- Specified by:
iterator
in interfaceIPAddressSegmentSeries
- Specified by:
iterator
in interfaceIterable<IPv4Address>
- Specified by:
iterator
in classIPAddress
- Returns:
-
spliterator
Description copied from interface:AddressComponentRange
Partitions and traverses through the individual address components.- Specified by:
spliterator
in interfaceAddressComponent
- Specified by:
spliterator
in interfaceAddressComponentRange
- Specified by:
spliterator
in interfaceAddressSegmentSeries
- Specified by:
spliterator
in interfaceIPAddressRange
- Specified by:
spliterator
in interfaceIPAddressSegmentSeries
- Specified by:
spliterator
in interfaceIterable<IPv4Address>
- Specified by:
spliterator
in classIPAddress
- 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
- Specified by:
stream
in interfaceAddressSegmentSeries
- Specified by:
stream
in interfaceIPAddressSegmentSeries
- Specified by:
stream
in classIPAddress
- Returns:
-
nonZeroHostIterator
Description copied from interface:IPAddressSegmentSeries
Similar to the iterator, but series with a host of zero are skipped.- Specified by:
nonZeroHostIterator
in interfaceIPAddressSegmentSeries
- Specified by:
nonZeroHostIterator
in classIPAddress
- Returns:
-
prefixBlockIterator
Description copied from interface:AddressSegmentSeries
Iterates through the individual prefix blocks.If the series has no prefix length, then this is equivalent to
AddressSegmentSeries.iterator()
- Specified by:
prefixBlockIterator
in interfaceAddressSegmentSeries
- Specified by:
prefixBlockIterator
in interfaceIPAddressSegmentSeries
- Specified by:
prefixBlockIterator
in classIPAddress
-
prefixBlockSpliterator
Description copied from interface:AddressSegmentSeries
Partitions and traverses through the individual prefix blocks for the prefix length of this series.- Specified by:
prefixBlockSpliterator
in interfaceAddressSegmentSeries
- Specified by:
prefixBlockSpliterator
in interfaceIPAddressSegmentSeries
- Specified by:
prefixBlockSpliterator
in classIPAddress
- Returns:
-
prefixBlockStream
Description copied from interface:AddressSegmentSeries
Returns a sequential stream of the individual prefix blocks for the prefix length of this series. For a parallel stream, callBaseStream.parallel()
on the returned stream.- Specified by:
prefixBlockStream
in interfaceAddressSegmentSeries
- Specified by:
prefixBlockStream
in interfaceIPAddressSegmentSeries
- Specified by:
prefixBlockStream
in classIPAddress
- Returns:
-
prefixBlockIterator
Description copied from interface:IPAddressRange
Iterates through the range of prefix blocks in this range instance using the given prefix length.- Specified by:
prefixBlockIterator
in interfaceIPAddressRange
- Parameters:
prefixLength
-- Returns:
-
prefixBlockSpliterator
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
Description copied from interface:AddressSegmentSeries
Iterates through the individual prefixes.If the series has no prefix length, then this is equivalent to
AddressSegmentSeries.iterator()
- Specified by:
prefixIterator
in interfaceAddressSegmentSeries
- Specified by:
prefixIterator
in interfaceIPAddressSegmentSeries
- Specified by:
prefixIterator
in classIPAddress
-
prefixSpliterator
Description copied from interface:AddressSegmentSeries
Partitions and traverses through the individual prefixes for the prefix length of this series.- Specified by:
prefixSpliterator
in interfaceAddressSegmentSeries
- Specified by:
prefixSpliterator
in interfaceIPAddressSegmentSeries
- Specified by:
prefixSpliterator
in classIPAddress
- Returns:
-
prefixStream
Description copied from interface:AddressSegmentSeries
Returns a sequential stream of the individual prefixes for the prefix length of this series. For a parallel stream, callBaseStream.parallel()
on the returned stream.- Specified by:
prefixStream
in interfaceAddressSegmentSeries
- Specified by:
prefixStream
in interfaceIPAddressSegmentSeries
- Specified by:
prefixStream
in classIPAddress
- Returns:
-
prefixIterator
Description copied from interface:IPAddressRange
Iterates through the range of prefixes in this range instance using the given prefix length.- Specified by:
prefixIterator
in interfaceIPAddressRange
- Parameters:
prefixLength
-- Returns:
-
prefixSpliterator
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:
-
blockIterator
Description copied from interface:IPAddressSegmentSeries
Iterates through series that can be obtained by iterating through all the upper segments up to the given segment count. Segments following remain the same in all iterated series.For instance, given the IPv4 subnet 1-2.3-4.5-6.7, given the count argument 2, it will iterate through 1.3.5-6.7, 1.4.5-6.7, 2.3.5-6.7, 2.4.5-6.7
- Specified by:
blockIterator
in interfaceIPAddressSegmentSeries
- Specified by:
blockIterator
in classIPAddress
- Parameters:
segmentCount
-- Returns:
-
blockSpliterator
Description copied from interface:IPAddressSegmentSeries
Partitions and traverses through the individual sequential blocks created from each of the individual values up to the given segment count.- Specified by:
blockSpliterator
in interfaceIPAddressSegmentSeries
- Specified by:
blockSpliterator
in classIPAddress
- Returns:
-
blockStream
Description copied from interface:IPAddressSegmentSeries
Returns a sequential stream of the individual blocks created from each of the individual values up to the given segment count. For a parallel stream, callBaseStream.parallel()
on the returned stream.- Specified by:
blockStream
in interfaceIPAddressSegmentSeries
- Specified by:
blockStream
in classIPAddress
- Returns:
-
sequentialBlockIterator
Description copied from interface:IPAddressSegmentSeries
Iterates through the sequential series that make up this series. Generally this means finding the count of segments for which the segments that follow are not full range, and then usingIPAddressSegmentSeries.blockIterator(int)
with that segment count.For instance, given the IPv4 subnet 1-2.3-4.5-6.7-8, it will iterate through 1.3.5.7-8, 1.3.6.7-8, 1.4.5.7-8, 1.4.6.7-8, 2.3.5.7-8, 2.3.6.7-8, 2.4.6.7-8, 2.4.6.7-8.
Use
IPAddressSegmentSeries.getSequentialBlockCount()
to get the count of iterated elements.- Specified by:
sequentialBlockIterator
in interfaceIPAddressSegmentSeries
- Overrides:
sequentialBlockIterator
in classIPAddress
- Returns:
-
sequentialBlockSpliterator
Description copied from interface:IPAddressSegmentSeries
Partitions and traverses through the individual sequential blocks.- Specified by:
sequentialBlockSpliterator
in interfaceIPAddressSegmentSeries
- Overrides:
sequentialBlockSpliterator
in classIPAddress
- Returns:
-
sequentialBlockStream
Description copied from interface:IPAddressSegmentSeries
Returns a sequential stream of the individual sequential blocks. For a parallel stream, callBaseStream.parallel()
on the returned stream.Use
IPAddressSegmentSeries.getSequentialBlockCount()
to get the count of streamed elements.- Specified by:
sequentialBlockStream
in interfaceIPAddressSegmentSeries
- Overrides:
sequentialBlockStream
in classIPAddress
- Returns:
-
getIterable
Description copied from interface:AddressComponentRange
Useful for using an instance in a "for-each loop". Otherwise just callAddressComponentRange.iterator()
directly.- Specified by:
getIterable
in interfaceAddressComponentRange
- Specified by:
getIterable
in interfaceAddressSegmentSeries
- Specified by:
getIterable
in interfaceIPAddressRange
- Specified by:
getIterable
in interfaceIPAddressSegmentSeries
- Specified by:
getIterable
in classIPAddress
- Returns:
- an object to iterate over the individual addresses represented by this object.
-
increment
Description copied from interface:AddressSegmentSeries
Returns the series from the subnet that is the given increment upwards into the subnet range, with the increment of 0 returning the first address in the range.If the subnet has multiple values and the increment exceeds the subnet size, then the amount by which it exceeds the size - 1 is added to the upper series of the range (the final iterator value).
If the increment is negative, it is added to the lower series of the range (the first iterator value).
If the subnet is just a single address values, the series is simply incremented by the given value, positive or negative.
If a subnet has multiple values, a positive increment value is equivalent to the same number of values from the
AddressSegmentSeries.iterator()
For instance, a increment of 0 is the first value from the iterator, an increment of 1 is the second value from the iterator, and so on. A negative increment added to the subnet count is equivalent to the same number of values preceding the upper bound of the iterator. For instance, an increment of count - 1 is the last value from the iterator, an increment of count - 2 is the second last value, and so on.An increment of size count gives you the series just above the highest series of the subnet. To get the series just below the lowest series of the subnet, use the increment -1.
- Specified by:
increment
in interfaceAddressSegmentSeries
- Specified by:
increment
in interfaceIPAddressSegmentSeries
- Specified by:
increment
in classIPAddress
- Parameters:
increment
-- Returns:
-
incrementBoundary
Description copied from interface:AddressSegmentSeries
If the given increment is positive, adds the value to the upper series (AddressSegmentSeries.getUpper()
) in the subnet range to produce a new series. If the given increment is negative, adds the value to the lower series (AddressSegmentSeries.getLower()
) in the subnet range to produce a new series. If the increment is zero, returns this.In the case where the series is a single value, this simply returns the address produced by adding the given increment to this address series.
- Specified by:
incrementBoundary
in interfaceAddressSegmentSeries
- Specified by:
incrementBoundary
in interfaceIPAddressSegmentSeries
- Specified by:
incrementBoundary
in classIPAddress
- Parameters:
increment
-- Returns:
-
getNetwork
Description copied from interface:AddressComponent
Returns the network object for components of the same version (eg IPv4, IPv6 and MAC each have their own network object)- Specified by:
getNetwork
in interfaceAddressComponent
- Specified by:
getNetwork
in interfaceIPAddressSegmentSeries
- Specified by:
getNetwork
in interfaceIPAddressStringDivisionSeries
- Specified by:
getNetwork
in classIPAddress
- Returns:
-
getIPv6Network
Returns the IPv6 network used bygetIPv4MappedAddress()
andgetIPv6Address(IPv6AddressSegment[])
- Returns:
-
intersect
Description copied from class:IPAddress
Produces the subnet whose addresses are found in both this and the given subnet argument, or null if no such addresses.This is also known as the conjunction of the two sets of addresses.
If the address is not the same version, the default conversion will be applied using
IPAddress.toIPv4()
orIPAddress.toIPv6()
, and it that fails,AddressConversionException
will be thrown.- Specified by:
intersect
in classIPAddress
- Parameters:
other
-- Returns:
- the subnet containing the addresses found in both this and the given subnet
- Throws:
AddressConversionException
- if the address argument could not be converted to the same address version as this
-
subtract
Description copied from class:IPAddress
Subtract the given subnet from this subnet, returning an array of subnets for the result (the subnets will not be contiguous so an array is required).Computes the subnet difference, the set of addresses in this address subnet but not in the provided subnet. This is also known as the relative complement of the given argument in this subnet.
If the address is not the same version, the default conversion will be applied using
IPAddress.toIPv4()
orIPAddress.toIPv6()
, and it that fails,AddressConversionException
will be thrown.- Specified by:
subtract
in classIPAddress
- Parameters:
other
-- Returns:
- the difference
- Throws:
AddressConversionException
- if the address argument could not be converted to the same address version as this
-
toZeroHost
Description copied from interface:IPAddressSegmentSeries
Returns the segment series with a host of zero, the host being the bits following the prefix length. If the series has no prefix length, then it returns an all-zero series.The default behaviour is that the resultant series will have the same prefix length. The resultant series will not have a prefix length if
AddressNetwork.getPrefixConfiguration()
isAddressNetwork.PrefixConfiguration.ALL_PREFIXED_ADDRESSES_ARE_SUBNETS
.For instance, you can get the network address for a subnet as follows:
String addrStr = "1.2.3.4/16"; IPAddress address = new IPAddressString(addrStr).getAddress(); IPAddress networkAddress = address.toZeroHost(); //1.2.0.0
- Specified by:
toZeroHost
in interfaceIPAddressSegmentSeries
- Specified by:
toZeroHost
in classIPAddress
- Returns:
- See Also:
-
toZeroHost
Description copied from interface:IPAddressSegmentSeries
Produces the series with host values of 0 for the given prefix length.If this series has the same prefix length, then the resulting series will too, otherwise the resulting series will have no prefix length.
This is nearly equivalent to doing the mask (bitwise conjunction) of this address series with the network mask for the given prefix length, but without the possibility of IncompatibleAddressException that can occur when applying a mask to a range of values. Instead, in this case, if the resulting series has a range of values, then the resulting series range boundaries will have host values of 0, but not necessarily the intervening values.
For instance, you can get the network address for a subnet of prefix length 16 as follows:
String addrStr = "1.2.3.4"; IPAddress address = new IPAddressString(addrStr).getAddress(); IPAddress networkAddress = address.toZeroHost(16); //1.2.0.0
- Specified by:
toZeroHost
in interfaceIPAddressSegmentSeries
- Specified by:
toZeroHost
in classIPAddress
- Parameters:
prefixLength
-- Returns:
-
toZeroNetwork
Description copied from interface:IPAddressSegmentSeries
Returns the segment series with a network of zero, the network being the bits within the prefix length. If the series has no prefix length, then it returns an all-zero series.The default behaviour is that the resultant series will have the same prefix length. The resultant series will not have a prefix length if
AddressNetwork.getPrefixConfiguration()
isAddressNetwork.PrefixConfiguration.ALL_PREFIXED_ADDRESSES_ARE_SUBNETS
.- Specified by:
toZeroNetwork
in interfaceIPAddressSegmentSeries
- Specified by:
toZeroNetwork
in classIPAddress
- Returns:
- See Also:
-
toMaxHost
Description copied from interface:IPAddressSegmentSeries
Returns the segment series with a host of all ones. If the series has no prefix length, then it returns an all-ones series.The resultant series will have the same prefix length if
AddressNetwork.getPrefixConfiguration()
is notAddressNetwork.PrefixConfiguration.ALL_PREFIXED_ADDRESSES_ARE_SUBNETS
, otherwise it will no longer have a prefix length.For instance, you can get the broadcast address for a subnet as follows:
String addrStr = "1.2.3.4/16"; IPAddress address = new IPAddressString(addrStr).getAddress(); IPAddress broadcastAddress = address.toMaxHost(); //1.2.255.255
- Specified by:
toMaxHost
in interfaceIPAddressSegmentSeries
- Specified by:
toMaxHost
in classIPAddress
- Returns:
-
toMaxHost
Description copied from interface:IPAddressSegmentSeries
Produces the series with host values of all one bits for the given prefix length.If this series has the same prefix length, then the resulting series will too, otherwise the resulting series will have no prefix length.
This is nearly equivalent to doing the bitwise or (bitwise disjunction) of this address series with the network mask for the given prefix length, but without the possibility of IncompatibleAddressException that can occur when applying a mask to a range of values. Instead, in this case, if the resulting series has a range of values, then the resulting series range boundaries will have host values of all ones, but not necessarily the intervening values.
For instance, you can get the broadcast address for a subnet of prefix length 16 as follows:
String addrStr = "1.2.3.4"; IPAddress address = new IPAddressString(addrStr).getAddress(); IPAddress broadcastAddress = address.toMaxHost(16); //1.2.255.255
- Specified by:
toMaxHost
in interfaceIPAddressSegmentSeries
- Specified by:
toMaxHost
in classIPAddress
- Parameters:
prefixLength
-- Returns:
-
mask
public IPv4Address mask(IPAddress mask, boolean retainPrefix) throws IncompatibleAddressException, AddressConversionException Description copied from class:IPAddress
Applies the given mask to all addresses represented by this IPAddress. The mask is applied to all individual addresses. Any existing prefix length is removed beforehand. If the retainPrefix argument is true, then the existing prefix length will be applied to the result.If the mask is a different version than this, then the default conversion is applied to the other address first using
IPAddress.toIPv4()
orIPAddress.toIPv6()
If this represents multiple addresses, and applying the mask to all addresses creates a set of addresses that cannot be represented as a contiguous range within each segment, then
IncompatibleAddressException
is thrown.- Specified by:
mask
in classIPAddress
- Parameters:
mask
-- Returns:
- Throws:
IncompatibleAddressException
- if this is a range of addresses and applying the mask results in an address that cannot be represented as a contiguous range within each segmentAddressConversionException
- if the address argument could not be converted to the same address version as this
-
mask
public IPv4Address mask(IPAddress mask) throws IncompatibleAddressException, AddressConversionException Description copied from class:IPAddress
Equivalent to callingIPAddress.mask(IPAddress, boolean)
with the second argument as false.If the mask is a different version than this, then the default conversion is applied to the other address first using
IPAddress.toIPv4()
orIPAddress.toIPv6()
- Specified by:
mask
in classIPAddress
- Parameters:
mask
-- Returns:
- Throws:
IncompatibleAddressException
- if this is a range of addresses and applying the mask results in an address that cannot be represented as a contiguous range within each segmentAddressConversionException
- if the address argument could not be converted to the same address version as this
-
maskNetwork
public IPv4Address maskNetwork(IPAddress mask, int networkPrefixLength) throws IncompatibleAddressException, PrefixLenException, AddressConversionException Description copied from class:IPAddress
Applies the given mask to all addresses represented by this IPAddress while also applying the given prefix length at the same time.Any existing prefix length is removed as the mask and new prefix length is applied to all individual addresses.
If the mask is a different version than this, then the default conversion is applied to the other address first using
IPAddress.toIPv4()
orIPAddress.toIPv6()
If this represents multiple addresses, and applying the mask to all addresses creates a set of addresses that cannot be represented as a contiguous range within each segment, then
IncompatibleAddressException
is thrown.- Specified by:
maskNetwork
in classIPAddress
- Throws:
IncompatibleAddressException
- if this is a range of addresses and applying the mask results in an address that cannot be represented as a contiguous range within each segmentAddressConversionException
- if the address argument could not be converted to the same address version as thisPrefixLenException
-
bitwiseOr
public IPv4Address bitwiseOr(IPAddress mask, boolean retainPrefix) throws IncompatibleAddressException, AddressConversionException Description copied from class:IPAddress
Does the bitwise disjunction with this address. Useful when subnetting.The mask is applied to all individual addresses, similar to how the method
IPAddress.mask(IPAddress, boolean)
applies the bitwise conjunction. Any existing prefix length is removed beforehand. If the retainPrefix argument is true, then the existing prefix length will be applied to the result.If the mask is a different version than this, then the default conversion is applied to the other address first using
IPAddress.toIPv4()
orIPAddress.toIPv6()
If you wish to mask a section of the network, use
IPAddress.bitwiseOrNetwork(IPAddress, int)
For instance, you can get the broadcast address for a subnet as follows:
String addrStr = "1.2.3.4/16"; IPAddress address = new IPAddressString(addrStr).getAddress(); IPAddress hostMask = address.getNetwork().getHostMask(address.getNetworkPrefixLength());//0.0.255.255 IPAddress broadcastAddress = address.bitwiseOr(hostMask); //1.2.255.255
- Specified by:
bitwiseOr
in classIPAddress
- Parameters:
mask
-retainPrefix
-- Returns:
- Throws:
IncompatibleAddressException
- if this is a range of addresses and applying the mask results in an address that cannot be represented as a contiguous range within each segmentAddressConversionException
- if the address argument could not be converted to the same address version as this
-
bitwiseOr
public IPv4Address bitwiseOr(IPAddress mask) throws IncompatibleAddressException, AddressConversionException Description copied from class:IPAddress
Equivalent to callingIPAddress.bitwiseOr(IPAddress, boolean)
with the second argument as false.If the mask is a different version than this, then the default conversion is applied to the other address first using
IPAddress.toIPv4()
orIPAddress.toIPv6()
- Specified by:
bitwiseOr
in classIPAddress
- Parameters:
mask
-- Returns:
- Throws:
IncompatibleAddressException
- if this is a range of addresses and applying the mask results in an address that cannot be represented as a contiguous range within each segmentAddressConversionException
- if the address argument could not be converted to the same address version as this
-
bitwiseOrNetwork
public IPv4Address bitwiseOrNetwork(IPAddress mask, int networkPrefixLength) throws IncompatibleAddressException, PrefixLenException, AddressConversionException Description copied from class:IPAddress
Does the bitwise disjunction with this address. Useful when subnetting.If the mask is a different version than this, then the default conversion is applied to the other address first using
IPAddress.toIPv4()
orIPAddress.toIPv6()
Any existing prefix length is dropped for the new prefix length and the mask is applied up to the end the new prefix length. It is similar to how the
IPAddress.maskNetwork(IPAddress, int)
method does the bitwise conjunction.- Specified by:
bitwiseOrNetwork
in classIPAddress
- Parameters:
mask
-networkPrefixLength
- the new prefix length for the address- Returns:
- Throws:
IncompatibleAddressException
- if this is a range of addresses and applying the mask results in an address that cannot be represented as a contiguous range within each segmentAddressConversionException
- if the address argument could not be converted to the same address version as thisPrefixLenException
-
getHostMask
Description copied from interface:IPAddressSegmentSeries
Returns the host mask associated with the CIDR network prefix length of this series. If this series has no prefix length, then the whole series is considered a host and the all ones host mask is returned.- Specified by:
getHostMask
in interfaceIPAddressSegmentSeries
- Overrides:
getHostMask
in classIPAddress
- Returns:
-
getNetworkMask
Description copied from interface:IPAddressSegmentSeries
Returns the network mask associated with the CIDR network prefix length of this series. If this series has no prefix length, then the whole series is considered network and the all ones network mask is returned.- Specified by:
getNetworkMask
in interfaceIPAddressSegmentSeries
- Overrides:
getNetworkMask
in classIPAddress
- Returns:
-
getNetworkSection
Description copied from interface:IPAddressSegmentSeries
Returns the network section of the series if the series has a CIDR network prefix length, otherwise it returns the entire series as a prefixed series with prefix matching the address bit length.- Specified by:
getNetworkSection
in interfaceIPAddressSegmentSeries
- Returns:
-
getNetworkSection
Description copied from interface:IPAddressSegmentSeries
Returns the network section of the series. The returned section will have only as many segments as needed as indicated by networkPrefixLength. It will have networkPrefixLength as its associated prefix length, unless this address already has a smaller prefix length, in which case the existing prefix length is retained.- Specified by:
getNetworkSection
in interfaceIPAddressSegmentSeries
- Parameters:
networkPrefixLength
-- Returns:
- Throws:
PrefixLenException
-
getNetworkSection
public IPv4AddressSection getNetworkSection(int networkPrefixLength, boolean withPrefixLength) throws PrefixLenException Description copied from interface:IPAddressSegmentSeries
Returns the network section of the series. The returned section will have only as many segments as needed as indicated by networkPrefixLength. If withPrefixLength is true, it will have networkPrefixLength as its associated prefix length, unless this series already has a smaller prefix length, in which case the existing prefix length is retained.- Specified by:
getNetworkSection
in interfaceIPAddressSegmentSeries
- Parameters:
networkPrefixLength
-withPrefixLength
- whether the resulting section will have networkPrefixLength as the associated prefix length or not- Returns:
- Throws:
PrefixLenException
-
getHostSection
Description copied from interface:IPAddressSegmentSeries
Returns the host section of the series. The returned section will have only as many segments as needed as determined by the existing CIDR network prefix length. If this series has no CIDR prefix length, the returned host section will be the full section associated with a prefix length of 0.- Specified by:
getHostSection
in interfaceIPAddressSegmentSeries
- Returns:
-
getHostSection
Description copied from interface:IPAddressSegmentSeries
Returns the host section of the address as indicated by the network prefix length provided. The returned section will have only as many segments as needed to hold the host as indicated by the provided network prefix length.- Specified by:
getHostSection
in interfaceIPAddressSegmentSeries
- Parameters:
networkPrefixLength
-- Returns:
- Throws:
PrefixLenException
-
toPrefixBlock
Description copied from class:IPAddress
Returns the subnet associated with the prefix length of this address. If this address has no prefix length, this address is returned.For example, if the address is 1.2.3.4/16 it returns the subnet 1.2.*.* /16
- Specified by:
toPrefixBlock
in interfaceAddressSegmentSeries
- Specified by:
toPrefixBlock
in interfaceIPAddressSegmentSeries
- Specified by:
toPrefixBlock
in classIPAddress
- Returns:
- the block of address series for the prefix length
-
toPrefixBlock
Description copied from interface:IPAddressSegmentSeries
Returns the segment series of the same length that spans all hosts. The network prefix length will be the one provided, and the network values will match the same of this series.- Specified by:
toPrefixBlock
in interfaceIPAddressSegmentSeries
- Specified by:
toPrefixBlock
in classIPAddress
- Parameters:
networkPrefixLength
-- Returns:
- Throws:
PrefixLenException
-
assignPrefixForSingleBlock
Description copied from class:IPAddress
Returns the equivalent CIDR address with a prefix length for which the address subnet block matches the range of values in this address.If no such prefix length exists, returns null.
Examples:
1.2.3.4 returns 1.2.3.4/32
1.2.*.* returns 1.2.0.0/16
1.2.*.0/24 returns 1.2.0.0/16
1.2.*.4 returns null
1.2.252-255.* returns 1.2.252.0/22
1.2.3.4/x returns the same address- Specified by:
assignPrefixForSingleBlock
in interfaceIPAddressSegmentSeries
- Overrides:
assignPrefixForSingleBlock
in classIPAddress
- Returns:
- See Also:
-
assignMinPrefixForBlock
Description copied from class:IPAddress
Constructs an equivalent address with the smallest CIDR prefix possible (largest network), such that the range of values are a set of subnet blocks for that prefix.- Specified by:
assignMinPrefixForBlock
in interfaceIPAddressSegmentSeries
- Overrides:
assignMinPrefixForBlock
in classIPAddress
- Returns:
- See Also:
-
coverWithPrefixBlock
Description copied from interface:IPAddressSegmentSeries
Returns the minimal-size prefix block that covers all the values in this series. The resulting block will have a larger series count than this, unless this series is already a prefix block.- Specified by:
coverWithPrefixBlock
in interfaceIPAddressRange
- Specified by:
coverWithPrefixBlock
in interfaceIPAddressSegmentSeries
-
coverWithPrefixBlock
Description copied from class:IPAddress
Returns the minimal-size prefix block that covers all the addresses spanning from this subnet to the given subnet.If the other address is a different version than this, then the default conversion is applied to the other address first using
IPAddress.toIPv4()
orIPAddress.toIPv6()
When you have multiple subnets, cover with:
IPAddress block = subnet0.applyToBounds(IPAddress::coverWithPrefixBlock, subnet1, subnet2, ...);
See
IPAddress.applyToBounds(java.util.function.BiFunction, IPAddress...)
- Specified by:
coverWithPrefixBlock
in classIPAddress
- Throws:
AddressConversionException
-
spanWithPrefixBlocks
Produces an array of prefix blocks that cover the same set of addresses as this.Unlike
spanWithPrefixBlocks(IPAddress)
this method only includes addresses that are a part of this subnet.- Specified by:
spanWithPrefixBlocks
in interfaceIPAddressRange
- Specified by:
spanWithPrefixBlocks
in interfaceIPAddressSegmentSeries
-
spanWithPrefixBlocks
Description copied from class:IPAddress
Produces the list of prefix block subnets that span from this subnet to the given subnet.If the other address is a different version than this, then the default conversion is applied to the other address first using
IPAddress.toIPv4()
orIPAddress.toIPv6()
The resulting array is sorted from lowest address value to highest, regardless of the size of each prefix block.
From the list of returned subnets you can recover the original range (this to other) by converting each to IPAddressRange with
IPAddress.toSequentialRange()
and them joining them into a single range withIPAddressSeqRange.join(IPAddressSeqRange...)
When you have multiple subnets, span with:
IPAddress blocks[] = subnet0.applyToBounds(IPAddress::spanWithPrefixBlocks, subnet1, subnet2, ...);
See
IPAddress.applyToBounds(java.util.function.BiFunction, IPAddress...)
- Specified by:
spanWithPrefixBlocks
in classIPAddress
- Parameters:
other
-- Returns:
- Throws:
AddressConversionException
-
spanWithSequentialBlocks
Produces an array of blocks that are sequential that cover the same set of addresses as this.This array can be shorter than that produced by
spanWithPrefixBlocks()
and is never longer.Unlike
spanWithSequentialBlocks(IPAddress)
this method only includes addresses that are a part of this subnet.- Specified by:
spanWithSequentialBlocks
in interfaceIPAddressRange
- Specified by:
spanWithSequentialBlocks
in interfaceIPAddressSegmentSeries
- Throws:
AddressConversionException
-
spanWithSequentialBlocks
Description copied from class:IPAddress
Produces a list of sequential block subnets that span all values from this subnet to the given subnet. The span will cover the sequence of all addresses from the lowest address in both subnets to the highest address in both subnets.Individual block subnets come in the form 1-3.1-4.5.6-8, however that particular subnet is not sequential since address 1.1.5.8 is in the subnet, the next sequential address 1.1.5.9 is not in the subnet, and a higher address 1.2.5.6 is in the subnet. Blocks are sequential when the first segment with a range of values is followed by segments that span all values.
If the other address is a different version than this, then the default conversion is applied to the other address first using
IPAddress.toIPv4()
orIPAddress.toIPv6()
The resulting array is sorted from lowest address value to highest, regardless of the size of each prefix block.
From the list of returned subnets you can recover the original range (this and other) by converting each to IPAddressRange with
IPAddress.toSequentialRange()
and them joining them into a single range withIPAddressSeqRange.join(IPAddressSeqRange...)
When you have multiple subnets, span with:
IPAddress blocks[] = subnet0.applyToBounds(IPAddress::spanWithSequentialBlocks, subnet1, subnet2, ...);
See
IPAddress.applyToBounds(java.util.function.BiFunction, IPAddress...)
- Specified by:
spanWithSequentialBlocks
in classIPAddress
- Parameters:
other
-- Returns:
- Throws:
AddressConversionException
-
spanWithRange
@Deprecated public IPv4AddressSeqRange spanWithRange(IPAddress other) throws AddressConversionException Deprecated.Description copied from class:IPAddress
Produces an IPAddressRange instance that spans this subnet to the given subnet.If the other address is a different version than this, then the default conversion is applied to the other address first using
IPAddress.toIPv4()
orIPAddress.toIPv6()
When you have multiple subnets, span with:
IPAddressSeqRange range = subnet0.applyToBounds(IPAddress::spanWithRange, subnet1, subnet2, ...);
See
IPAddress.applyToBounds(java.util.function.BiFunction, IPAddress...)
- Specified by:
spanWithRange
in classIPAddress
- Parameters:
other
-- Returns:
- Throws:
AddressConversionException
-
mergeToPrefixBlocks
Description copied from class:IPAddress
Merges this with the list of addresses to produce the smallest list of prefix blocks.For the smallest list of subnets use
IPAddress.mergeToSequentialBlocks(IPAddress...)
.If any other address in the list is a different version than this, then the default conversion is applied to the other address first using
IPAddress.toIPv4()
orIPAddress.toIPv6()
, which can result in AddressConversionExceptionThe resulting array is sorted from lowest address value to highest, regardless of the size of each prefix block.
In version 5.3.1 and earlier, the result was sorted from single address to smallest blocks to largest blocks. For that ordering, sort with
IPAddressSegmentSeries.getPrefixLenComparator()
:
Arrays.sort(result, IPAddressSegmentSeries.getPrefixLenComparator());
The merging process works with sequential blocks. CIDR prefix subnets have just a single sequential block, as does individual addresses. So this method works efficiently for most conventionally-used subnets.
For example, the subnet ::*:*:*:1-ffff has 281474976710656 sequential blocks. Just like you should avoid iterating through such a large number of blocks, you should avoid using this method to merge such a subnet, rather than a subnet like ::1-ffff:*:*:*:* which has 1 sequential block, or the subnet ::1-ffff:1-ffff:*:*:*:* which has 65535 sequential blocks. You can use
IPAddress.getSequentialBlockCount()
to get the sequential block count.There are alternatives ways to merge into prefix blocks available in this library. Typically this method is most efficient when merging CIDR prefix blocks and/or individual addresses, which is likely to be the case for most users most of the time. It converts to CIDR prefix blocks prior to merging, if not CIDR prefix blocks or individual addresses already.
When merging a large number of blocks that are not prefix blocks nor individual addresses, it may be more efficient to merge first and then convert to CIDR prefix blocks afterwards. You can use
IPAddress.mergeToSequentialBlocks(IPAddress...)
to merge, and then span each merged element in the result withIPAddressSegmentSeries.spanWithPrefixBlocks()
, giving the same result as this method.Sequential ranges provide another option. You can convert to sequential blocks first with
IPAddress.sequentialBlockIterator()
, then convert each sequential block toIPAddressSeqRange
withIPAddress.toSequentialRange()
, then join those sequential ranges withIPAddressSeqRange.join(IPAddressSeqRange...)
, then convert them to CIDR prefix blocks withIPAddressSeqRange.spanWithPrefixBlocks()
, giving the same result as this method.- Specified by:
mergeToPrefixBlocks
in classIPAddress
- Parameters:
addresses
- the addresses to merge with this- Returns:
- Throws:
AddressConversionException
-
mergeToSequentialBlocks
public IPv4Address[] mergeToSequentialBlocks(IPAddress... addresses) throws AddressConversionException Description copied from class:IPAddress
Merges this with the list of subnets to produce the smallest list of block subnets that are sequential.Block subnets come in the form 1-3.1-4.5.6-8, however that subnet is not sequential since address 1.1.5.8 is in the subnet, the next sequential address 1.1.5.9 is not in the subnet, and a higher address 1.2.5.6 is in the subnet. Blocks are sequential when the first segment with a range of values is followed by segments that span all values.
This list will eliminate overlaps to produce the smallest list of sequential block subnets, which is the same size or smaller than the list of prefix blocks produced by
IPAddress.mergeToPrefixBlocks(IPAddress...)
If the incoming blocks are not sequential, the result could be a longer list, since the list is divided into sequential blocks before merging.
If any other address in the list is a different version than this, then the default conversion is applied to the other address first using
IPAddress.toIPv4()
orIPAddress.toIPv6()
, which can result in AddressConversionExceptionThe resulting array is sorted by lower address, regardless of the size of each prefix block.
In version 5.3.1 and earlier, the result was sorted from single address to smallest blocks to largest blocks. For that ordering, sort with
IPAddressSegmentSeries.getPrefixLenComparator()
:
Arrays.sort(result, IPAddressSegmentSeries.getPrefixLenComparator());
See the javadoc for
IPAddress.mergeToPrefixBlocks(IPAddress...)
for some alternatives for merging subnets.- Specified by:
mergeToSequentialBlocks
in classIPAddress
- Parameters:
addresses
- the addresses to merge with this- Returns:
- Throws:
AddressConversionException
-
toUpperInetAddress
Description copied from class:IPAddress
Converts the highest value of this address to an InetAddress. If this consists of just a single address and not a subnet, this is equivalent toIPAddress.toInetAddress()
- Overrides:
toUpperInetAddress
in classIPAddress
-
toInetAddress
Description copied from class:IPAddress
Converts the lowest value of this address to an InetAddress- Overrides:
toInetAddress
in classIPAddress
-
toSequentialRange
Description copied from class:IPAddress
Creates a sequential range instance from this and the given address, spanning from the lowest to the highest addresses in the two subnetsIf the other address is a different version than this, then the default conversion is applied to the other address first using
IPAddress.toIPv4()
orIPAddress.toIPv6()
When you have multiple subnets, create a range from lowest to highest with:
IPAddressSeqRange range = subnet0.applyToBounds(IPAddress::toSequentialRange, subnet1, subnet2, ...);
See
IPAddress.applyToBounds(java.util.function.BiFunction, IPAddress...)
- Specified by:
toSequentialRange
in classIPAddress
- Parameters:
other
-- Returns:
-
toSequentialRange
Description copied from class:IPAddress
Creates a sequential range instance from the lowest and highest addresses in this subnetThe two will represent the same set of individual addresses if and only if
Address.isSequential()
is true. To get a series of ranges that represent the same set of individual addresses use theIPAddress.sequentialBlockIterator()
(orIPAddress.prefixIterator()
), and apply this method to each iterated subnet.If this represents just a single address then the returned instance covers just that single address as well.
- Specified by:
toSequentialRange
in interfaceIPAddressRange
- Specified by:
toSequentialRange
in classIPAddress
- Returns:
-
isLocal
public boolean isLocal()Description copied from class:IPAddress
Returns true if the address is link local, site local, organization local, administered locally, or unspecified. This includes both unicast and multicast. -
isLinkLocal
public boolean isLinkLocal()Description copied from class:IPAddress
Returns whether the address is link local, whether unicast or multicast.- Specified by:
isLinkLocal
in classIPAddress
- See Also:
-
isPrivate
public boolean isPrivate()Unicast addresses allocated for private use- See Also:
-
isMulticast
public boolean isMulticast()Description copied from class:Address
Whether the MAC address or IP address or other form of address is multicast.- Specified by:
isMulticast
in classAddress
- See Also:
-
isLoopback
public boolean isLoopback()- Specified by:
isLoopback
in classIPAddress
- See Also:
-
toNormalizedString
public static String toNormalizedString(IPv4AddressNetwork network, Address.SegmentValueProvider lowerValueProvider, Address.SegmentValueProvider upperValueProvider, Integer prefixLength) Creates the normalized string for an address without having to create the address objects first.- Parameters:
network
- useAddress.defaultIpv4Network()
if there is no custom network in uselowerValueProvider
-upperValueProvider
-prefixLength
-- Returns:
-
toInetAtonString
Returns a string like the inet_aton style string- Returns:
-
toInetAtonString
public String toInetAtonString(IPv4Address.inet_aton_radix radix, int joinedCount) throws IncompatibleAddressException - Throws:
IncompatibleAddressException
-
toSegmentedBinaryString
Description copied from interface:IPAddressSegmentSeries
Writes this IP address segment series as a segments of binary values preceded by the "0b" prefix.- Specified by:
toSegmentedBinaryString
in interfaceIPAddressSegmentSeries
-
toUNCHostName
Description copied from class:IPAddress
Generates the Microsoft UNC path component for this address- Specified by:
toUNCHostName
in classIPAddress
- Returns:
-
toStandardStringCollection
- Overrides:
toStandardStringCollection
in classIPAddress
-
toAllStringCollection
- Overrides:
toAllStringCollection
in classIPAddress
-
toStringCollection
public IPAddressPartStringCollection toStringCollection(IPAddressSection.IPStringBuilderOptions opts) - Specified by:
toStringCollection
in interfaceIPAddressSegmentSeries
- Overrides:
toStringCollection
in classIPAddress
-
toStringCollection
public IPAddressPartStringCollection toStringCollection(IPv4AddressSection.IPv4StringBuilderOptions opts)
-