Class IPAddress
- All Implemented Interfaces:
AddressComponent, AddressSegmentSeries, AddressComponentRange, AddressDivisionSeries, AddressItem, AddressItemRange, IPAddressDivisionSeries, IPAddressRange, AddressStringDivisionSeries, IPAddressStringDivisionSeries, IPAddressSegmentSeries, Serializable, Comparable<AddressItem>
- Direct Known Subclasses:
IPv4Address, IPv6Address
IPAddress objects are immutable and cannot change values. This also makes them thread-safe.
String creation:
There are various methods used to construct standard address string such as Address.toCanonicalString() or Address.toNormalizedString()
There are also several public classes used to create customized IP address strings.
For single strings from an address or address section, you use IPAddressSection.IPStringOptions or IPv6AddressSection.IPv6StringOptions along with toNormalizedString(IPAddressSection.IPStringOptions).
Or you use one of the methods like Address.toCanonicalString() which does the same.
For string collections from an address or address section, use IPv4AddressSection.IPv4StringBuilderOptions, IPv6AddressSection.IPv6StringBuilderOptions, IPAddressSection.IPStringBuilderOptions along with toStringCollection(IPAddressSection.IPStringBuilderOptions) or toStrings(IPAddressSection.IPStringBuilderOptions).
Or you use one of the methods toStandardStringCollection(), toAllStringCollection(), toStandardStrings(), toAllStrings() which does the same.
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 classstatic interfacestatic enumNested classes/interfaces inherited from class Address
Address.AddressValueProvider, Address.SegmentValueProvider -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final IPAddressConverterThe default way by which addresses are converted, initialized to an instance ofIPAddressConverter.DefaultAddressConverterstatic final charFields inherited from class 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 -
Method Summary
Modifier and TypeMethodDescriptionabstract IPAddressadjustPrefixBySegment(boolean nextSegment) Increases or decreases prefix length to the next segment boundary.abstract IPAddressadjustPrefixBySegment(boolean nextSegment, boolean zeroed) Increases or decreases prefix length to the next segment boundary.abstract IPAddressadjustPrefixLength(int adjustment) Increases or decreases prefix length by the given increment.abstract IPAddressadjustPrefixLength(int adjustment, boolean zeroed) Increases or decreases prefix length by the given increment.abstract IPAddressapplyPrefixLength(int networkPrefixLength) Deprecated.<V> VapplyToBounds(BiFunction<? super IPAddress, ? super IPAddress, V> func, IPAddress... series) Finds the lowest and highest single-valued address from the given addresses and subnets and this one, calling the given BiFunction with the lowest as first argument and the highest as second.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.abstract IPAddressEquivalent to callingbitwiseOr(IPAddress, boolean)with the second argument as false.abstract IPAddressDoes the bitwise disjunction with this address.abstract IPAddressbitwiseOrNetwork(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.abstract AddressComponentSpliterator<? extends IPAddress> 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.booleanReturns whether this contains all values of the given address or subnetbooleancontains(IPAddressSeqRange otherRange) Returns whether this range contains all addresses in the given sequential rangebooleancontainsNonZeroHosts(IPAddress other) Returns whether this address contains the non-zero host addresses in the other address or subnetabstract IPAddresscoverWithPrefixBlock(IPAddress other) Returns the minimal-size prefix block that covers all the addresses spanning from this subnet to the given subnet.abstract BigIntegerIndicates where an address sits relative to the subnet ordering.static intgetBitCount(IPAddress.IPVersion version) intReturns the number of bits comprising each segment in this series.getBlockMaskPrefixLength(boolean network) If this address is equivalent to the mask for a CIDR prefix block, it returns that prefix length.intProvides the number of bytes required for this address item, rounding up if the bit count is not a multiple of 8static intgetByteCount(IPAddress.IPVersion version) intReturns the number of bytes comprising each segment in this series.Returns the host mask associated with the CIDR network prefix length of this series.Returns the version of this segment seriesUseful for using an instance in a "for-each loop".intgetLeadingBitCount(boolean network) Returns the number of consecutive leading one or zero bits.abstract IPAddressgetLower()If this represents a series with ranging values, returns a series representing the lower values of the range.abstract IPAddressSimilar toIPAddressSegmentSeries.getLower(), but will not return a series that has a prefix length and whose host value is zero.voidgetMatchesSQLClause(StringBuilder builder, String sqlExpression) Returns a clause for matching this address.voidgetMatchesSQLClause(StringBuilder builder, String sqlExpression, IPAddressSQLTranslator translator) Returns a clause for matching this address.intReturns the maximum possible segment value for this type of address.abstract IPAddressNetwork<?, ?, ?, ?, ?> 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.////////////////// masks and subnets below ///////////////////////Gets the count of single value series that this series may represent, but excluding series whose host is zero.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.static intgetSegmentCount(IPAddress.IPVersion version) provides the count of elements from theIPAddressSegmentSeries.sequentialBlockIterator(), the minimal number of sequential sub-series that comprise this seriesintgetTrailingBitCount(boolean network) Returns the number of consecutive trailing one or zero bits.abstract IPAddressgetUpper()If this represents a series with ranging values, returns a series representing the upper values of the range.booleanReturns whether the series has a host of all ones.booleanincludesMaxHost(int networkPrefixLength) Returns whether all bits past the given prefix length are all ones.booleanReturns whether the series has a host of zero.booleanincludesZeroHost(int networkPrefixLength) Returns whether all bits past the given prefix length are zero.abstract IPAddressincrement(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.abstract IPAddressincrementBoundary(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.abstract IPAddressProduces the subnet whose addresses are found in both this and the given subnet argument, or null if no such addresses.booleanReturns whether this address is the address which binds to any address on the local host.booleanReturns whether this address is an IP addressbooleanisIPv4()abstract booleanDetermines whether this address can be converted to IPv4, if not IPv4 already.booleanisIPv6()abstract booleanDetermines whether an address can be converted to IPv6, if not IPv6 already.abstract booleanReturns whether the address is link local, whether unicast or multicast.abstract booleanisLocal()Returns true if the address is link local, site local, organization local, administered locally, or unspecified.abstract booleanbooleanReturns true if the network section of the address spans just a single valuebooleanThe unspecified address is the address that is all zeros.booleanReturns whether this address has a prefix length and if so, whether the host section is zero for this address or all addresses in this subnet.booleanisZeroHost(int networkPrefixLength) Returns whether the host is zero for the given prefix length for this address or all addresses in this subnet.iterator()Iterates through the individual address components.abstract IPAddressEquivalent to callingmask(IPAddress, boolean)with the second argument as false.abstract IPAddressApplies the given mask to all addresses represented by this IPAddress.abstract IPAddressmaskNetwork(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.booleanmatches(IPAddressString otherString) booleanmatchesWithMask(IPAddress other, IPAddress mask) Applies the mask to this address and then compares values with the given addressstatic IPAddress.DualIPv4Pv6ArraysmergeToDualPrefixBlocks(IPAddress... addresses) merges the given set of IP addresses and subnets into a minimal number of prefix blocks.static IPAddress.DualIPv4Pv6ArraysmergeToDualSequentialBlocks(IPAddress... addresses) merges the given set of IP addresses and subnets into a minimal number of prefix blocks.abstract IPAddress[]mergeToPrefixBlocks(IPAddress... addresses) Merges this with the list of addresses to produce the smallest list of prefix blocks.abstract IPAddress[]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.booleanReturns true if this address overlaps the given address or subnetbooleanoverlaps(IPAddressSeqRange other) Returns true if this address overlaps the given sequential rangeIterates through the individual prefix blocks.abstract AddressComponentSpliterator<? extends IPAddress> Partitions and traverses through the individual prefix blocks for the prefix length of this series.Returns a sequential stream of the individual prefix blocks for the prefix length of this series.booleanprefixContains(IPAddress other) Returns whether the prefix of this address contains all values of the same bits in the given address or subnetIterates through the individual prefixes.abstract AddressComponentSpliterator<? extends IPAddress> Partitions and traverses through the individual prefixes for the prefix length of this series.Returns a sequential stream of the individual prefixes for the prefix length of this series.Removes the prefix length from addresses with a prefix length extending to the end of the address.abstract IPAddressDeprecated.abstract IPAddressremovePrefixLength(boolean zeroed) Deprecated.abstract IPAddressreverseBits(boolean perByte) Returns a new segment series with the bits reversed.abstract IPAddressReturns a new segment series with the bytes reversed.abstract IPAddressReturns a new segment series with the bytes reversed within each segment.abstract IPAddressReturns a new segment series with the segments reversed.Iterates through the sequential series that make up this series.AddressComponentSpliterator<? extends IPAddress> Partitions and traverses through the individual sequential blocks.Returns a sequential stream of the individual sequential blocks.abstract IPAddresssetPrefixLength(int prefixLength) Sets the prefix length.abstract IPAddresssetPrefixLength(int prefixLength, boolean zeroed) Sets the prefix length.abstract IPAddresssetPrefixLength(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.abstract IPAddress[]spanWithPrefixBlocks(IPAddress other) Produces the list of prefix block subnets that span from this subnet to the given subnet.abstract IPAddressSeqRangespanWithRange(IPAddress other) Produces an IPAddressRange instance that spans this subnet to the given subnet.abstract IPAddress[]Produces a list of sequential block subnets that span all values from this subnet to the given subnet.abstract AddressComponentSpliterator<? extends IPAddress> Partitions and traverses through the individual address components.stream()Returns a sequential stream of the individual address components.abstract 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).Generates an IPAddressString object for this IPAddress object.String[]Produces almost all possible string variationsWrites this address as a single binary value with always the exact same number of charactersDoes a reverse name lookup to get the canonical host name.This produces a string similar to the canonical string but avoids the CIDR prefix.This is similar to toNormalizedWildcardString, avoiding the CIDR prefix, but with compression as well.Returns a mixed string if it represents a convertible IPv4 address, returns the normalized string otherwise.static StringtoDelimitedSQLStrs(String[] strs) This produces a string with no compressed segments and all segments of full length, which is 4 characters for IPv6 segments and 3 characters for IPv4 segments.If this address was resolved from a host, returns that host.Converts the lowest value of this address to an InetAddressIf this address is an IP address, returns thatIPAddress.toIPv4()If this address is IPv4, or can be converted to IPv4, returns thatIPv4Address.toIPv6()abstract IPAddressReturns the segment series with a host of all ones.abstract IPAddresstoMaxHost(int prefixLength) Produces the series with host values of all one bits for the given prefix length.static StringAllows for the creation of a normalized string without creating a full IP address object first.static voidtoNormalizedString(IPAddress.IPAddressValueProvider provider, StringBuilder builder) Allows for the creation of a normalized string without creating a full IP address object first.Constructs a string representing this address according to the given parametersThis produces a string similar to the normalized string but avoids the CIDR prefix.toOctalString(boolean with0Prefix) Writes this address as a single octal value with always the exact same number of characters, with or without a preceding 0 prefix.abstract IPAddressReturns the subnet associated with the prefix length of this address.abstract IPAddresstoPrefixBlock(int networkPrefixLength) Returns the segment series of the same length that spans all hosts.Returns a string with a CIDR network prefix length if this address has a network prefix length.Generates the reverse DNS lookup stringabstract IPAddressSeqRangeCreates a sequential range instance from the lowest and highest addresses in this subnetabstract IPAddressSeqRangetoSequentialRange(IPAddress other) Deprecated.This is the same as the string from toNormalizedWildcardString except that it usesAddress.SEGMENT_SQL_WILDCARDinstead ofAddress.SEGMENT_WILDCARDand also usesAddress.SEGMENT_SQL_SINGLE_WILDCARDString[]Returns at most a few dozen string representations: -mixed (1:2:3:4:5:6:1.2.3.4) -full compressions (a:0:b:c:d:0:e:f or a::b:c:d:0:e:f or a:0:b:c:d::e:f) -full leading zeros (000a:0000:000b:000c:000d:0000:000e:000f) -all uppercase and all lowercase (a::a can be A::A) -combinations thereofString[]Rather than using toAllStrings or StandardStrings, you can use this method to customize the list of strings produced for this addressProduces a consistent subnet string that looks like 1.2.*.* or 1:2::/16 In the case of IPv4, this means that wildcards are used instead of a network prefix when a network prefix has been supplied.abstract StringGenerates the Microsoft UNC path component for this addressConverts the highest value of this address to an InetAddress.abstract IPAddressReturns the segment series with a host of zero, the host being the bits following the prefix length.abstract IPAddresstoZeroHost(int prefixLength) Produces the series with host values of 0 for the given prefix length.abstract IPAddressReturns the segment series with a network of zero, the network being the bits within the prefix length.abstract IPAddressProvides the same address with no prefix.Methods inherited from class Address
contains, containsPrefixBlock, containsSinglePrefixBlock, defaultIpv4Network, defaultIpv6Network, defaultMACNetwork, enumerate, equals, getBitCount, getBlockCount, getBytes, getBytes, getBytes, getCount, getDivisionCount, getDivisionStrings, getMinPrefixLengthForBlock, getPrefixCount, getPrefixCount, getPrefixLength, getPrefixLengthForSingleBlock, getSegmentCount, getSegments, getSegments, getSegmentStrings, getUpperBytes, getUpperBytes, getUpperBytes, getUpperValue, getValue, hashCode, includesMax, includesZero, isFullRange, isMACAddress, isMax, isMulticast, isMultiple, isPrefixBlock, isPrefixed, isSameAddress, isSequential, isSinglePrefixBlock, isZero, matchOrdered, matchUnordered, overlaps, prefixEquals, toCanonicalString, toCompressedString, toHexString, toMACAddress, toNormalizedString, toStringMethods inherited from interface AddressComponent
toHexString, toNormalizedStringMethods inherited from interface AddressDivisionSeries
getBitCount, getBlockCount, getCount, getDivisionStrings, getPrefixCount, getPrefixCount, getPrefixLength, getSequentialBlockIndex, isMore, isPrefixBlock, isPrefixed, isSequential, isSinglePrefixBlockMethods inherited from interface AddressItem
compareTo, containsPrefixBlock, containsSinglePrefixBlock, getBytes, getBytes, getBytes, getMinPrefixLengthForBlock, getPrefixLengthForSingleBlock, getUpperBytes, getUpperBytes, getUpperBytes, getUpperValue, getValue, includesMax, includesZero, isFullRange, isMax, isMultiple, isZeroMethods inherited from interface AddressSegmentSeries
getSegmentCount, getSegments, getSegments, getSegmentStrings, isOneBit, testBit, toCanonicalString, toCompressedStringMethods inherited from interface AddressStringDivisionSeries
getDivisionCountMethods inherited from interface IPAddressDivisionSeries
getDivisionMethods inherited from interface IPAddressRange
coverWithPrefixBlock, isSequential, prefixBlockIterator, prefixBlockSpliterator, prefixBlockStream, prefixIterator, prefixSpliterator, prefixStream, spanWithPrefixBlocks, spanWithSequentialBlocks, toCanonicalString, toNormalizedStringMethods inherited from interface IPAddressSegmentSeries
coverWithPrefixBlock, getHostSection, getHostSection, getNetworkSection, getNetworkSection, getNetworkSection, getSegment, getSegments, segmentsIterator, segmentsNonZeroHostIterator, segmentsSpliterator, segmentsStream, spanWithPrefixBlocks, spanWithSequentialBlocks, toSegmentedBinaryStringMethods inherited from interface IPAddressStringDivisionSeries
getPrefixLength, isPrefixBlock, isPrefixed
-
Field Details
-
PREFIX_LEN_SEPARATOR
public static final char PREFIX_LEN_SEPARATOR- See Also:
-
BINARY_STR_PREFIX
- See Also:
-
DEFAULT_ADDRESS_CONVERTER
The default way by which addresses are converted, initialized to an instance ofIPAddressConverter.DefaultAddressConverter
-
-
Method Details
-
toAddressString
Generates an IPAddressString object for this IPAddress object.This same IPAddress object can be retrieved from the resulting IPAddressString object using
IPAddressString.getAddress()In general, users are intended to create IPAddress objects from IPAddressString objects, while the reverse direction is generally not all that useful.
However, the reverse direction can be useful under certain circumstances.
Not all IPAddressString objects can be converted to IPAddress objects, as is the case with IPAddressString objects corresponding to the types IPType.INVALID and IPType.EMPTY.
Not all IPAddressString objects can be converted to IPAddress objects without specifying the IP version, as is the case with IPAddressString objects corresponding to the types IPType.PREFIX and IPType.ALL.
So in the event you wish to store a collection of IPAddress objects with a collection of IPAddressString objects, and not all the IPAddressString objects can be converted to IPAddress objects, then you may wish to use a collection of only IPAddressString objects, in which case this method is useful.
- Overrides:
toAddressStringin classAddress- Returns:
- an IPAddressString object for this IPAddress.
-
toHostName
If this address was resolved from a host, returns that host. Otherwise, does a reverse name lookup. -
toCanonicalHostName
Does a reverse name lookup to get the canonical host name. Note that the canonical host name may differ on different systems, as it aligns withInetAddress.getCanonicalHostName()In particular, on some systems the loopback address has canonical host localhost and on others the canonical host is the same loopback address. -
getNetwork
Description copied from interface:AddressComponentReturns the network object for components of the same version (eg IPv4, IPv6 and MAC each have their own network object)- Specified by:
getNetworkin interfaceAddressComponent- Specified by:
getNetworkin interfaceIPAddressSegmentSeries- Specified by:
getNetworkin interfaceIPAddressStringDivisionSeries- Returns:
-
getSection
Returns the address as an address section comprising all segments in the address.- Specified by:
getSectionin interfaceAddressSegmentSeries- Specified by:
getSectionin interfaceIPAddressSegmentSeries- Overrides:
getSectionin classAddress- Returns:
-
getSection
Description copied from interface:AddressSegmentSeriesGets the subsection from the series starting from the given index The first segment is at index 0.- Specified by:
getSectionin interfaceAddressSegmentSeries- Specified by:
getSectionin interfaceIPAddressSegmentSeries- Parameters:
index-- Returns:
-
getSection
Description copied from interface:AddressSegmentSeriesGets 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:
getSectionin interfaceAddressSegmentSeries- Specified by:
getSectionin interfaceIPAddressSegmentSeries- Parameters:
index-endIndex-- Returns:
-
getParts
Returns all the ways of breaking this address down into segments, as selected.- Returns:
-
getMaxSegmentValue
public int getMaxSegmentValue()Description copied from interface:AddressSegmentSeriesReturns the maximum possible segment value for this type of address. Note this is not the maximum value of the range of segment values in this specific address, this is the maximum value of any segment for this address type, and is usually determined by the number of bits per segment.- Specified by:
getMaxSegmentValuein interfaceAddressSegmentSeries- Returns:
- the maximum possible segment value for a series of the same type
-
getNonZeroHostCount
Description copied from interface:IPAddressSegmentSeriesGets the count of single value series that this series may represent, but excluding series whose host is zero. The host is determined by the CIDR prefix length, if there is one.If this address series has no range of values, then there is only one such address, or none if it has a zero host.
If this has no CIDR network prefix length, then it is equivalent to
AddressDivisionSeries.getCount().- Specified by:
getNonZeroHostCountin interfaceIPAddressSegmentSeries- Returns:
-
getBytesPerSegment
public int getBytesPerSegment()Description copied from interface:AddressSegmentSeriesReturns the number of bytes comprising each segment in this series. Segments in the same series are equal length.- Specified by:
getBytesPerSegmentin interfaceAddressSegmentSeries- Returns:
-
getBitsPerSegment
public int getBitsPerSegment()Description copied from interface:AddressSegmentSeriesReturns the number of bits comprising each segment in this series. Segments in the same series are equal length.- Specified by:
getBitsPerSegmentin interfaceAddressSegmentSeries- Returns:
-
getByteCount
public int getByteCount()Description copied from interface:AddressItemProvides the number of bytes required for this address item, rounding up if the bit count is not a multiple of 8- Specified by:
getByteCountin interfaceAddressItem- Overrides:
getByteCountin classAddress- Returns:
- the number of bytes
-
getByteCount
-
getSegmentCount
-
getBitCount
-
applyToBounds
public <V> V applyToBounds(BiFunction<? super IPAddress, ? super IPAddress, V> func, IPAddress... series) Finds the lowest and highest single-valued address from the given addresses and subnets and this one, calling the given BiFunction with the lowest as first argument and the highest as second. It returns the result returned from the call to the BiFunction.For instance, given the IPv4 addresses 1.2.0.0/16 and 1.3.4.5, the lowest is 1.2.0.0 and the highest is 1.3.4.5. Given the addresses 1.2.0.0/16 and 1.1.4.5, the lowest is 1.1.4.5 and the highest is 1.2.255.255.
If one of the given addresses or subnets is a different version than this, then the default conversion is applied to the other address first using
toIPv4()ortoIPv6()This can be useful for methods that require a range as input, like
spanWithPrefixBlocks(IPAddress),spanWithSequentialBlocks(IPAddress),coverWithPrefixBlock(IPAddress), ortoSequentialRange(IPAddress).For instance, to cover multiple addresses with a prefix block:
IPAddress coveringAddress = address0.applyToBounds(IPAddress::coverWithPrefixBlock, address1, address2, address3, ...); -
getLowerNonZeroHost
Description copied from interface:IPAddressSegmentSeriesSimilar 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:
getLowerNonZeroHostin interfaceIPAddressSegmentSeries- Returns:
- the lowest IP address series whose host is non-zero, or null if no such address section exists.
-
getLower
Description copied from interface:AddressSegmentSeriesIf 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:
getLowerin interfaceAddressComponentRange- Specified by:
getLowerin interfaceAddressSegmentSeries- Specified by:
getLowerin interfaceIPAddressRange- Specified by:
getLowerin interfaceIPAddressSegmentSeries- Specified by:
getLowerin classAddress- Returns:
-
getUpper
Description copied from interface:AddressSegmentSeriesIf 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:
getUpperin interfaceAddressComponentRange- Specified by:
getUpperin interfaceAddressSegmentSeries- Specified by:
getUpperin interfaceIPAddressRange- Specified by:
getUpperin interfaceIPAddressSegmentSeries- Specified by:
getUpperin classAddress- Returns:
-
reverseBits
Description copied from interface:AddressSegmentSeriesReturns a new segment series with the bits reversed.- Specified by:
reverseBitsin interfaceAddressComponent- Specified by:
reverseBitsin interfaceAddressSegmentSeries- Specified by:
reverseBitsin interfaceIPAddressSegmentSeries- Specified by:
reverseBitsin classAddress- 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:AddressSegmentSeriesReturns a new segment series with the bytes reversed.- Specified by:
reverseBytesin interfaceAddressComponent- Specified by:
reverseBytesin interfaceAddressSegmentSeries- Specified by:
reverseBytesin interfaceIPAddressSegmentSeries- Specified by:
reverseBytesin classAddress- Returns:
-
reverseBytesPerSegment
Description copied from interface:AddressSegmentSeriesReturns a new segment series with the bytes reversed within each segment.- Specified by:
reverseBytesPerSegmentin interfaceAddressSegmentSeries- Specified by:
reverseBytesPerSegmentin interfaceIPAddressSegmentSeries- Specified by:
reverseBytesPerSegmentin classAddress- Returns:
-
reverseSegments
Description copied from interface:AddressSegmentSeriesReturns a new segment series with the segments reversed. This does not throwIncompatibleAddressExceptionsince all address series can reverse their segments.- Specified by:
reverseSegmentsin interfaceAddressSegmentSeries- Specified by:
reverseSegmentsin interfaceIPAddressSegmentSeries- Specified by:
reverseSegmentsin classAddress- Returns:
-
iterator
Description copied from interface:AddressComponentRangeIterates 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:
iteratorin interfaceAddressComponentRange- Specified by:
iteratorin interfaceAddressSegmentSeries- Specified by:
iteratorin interfaceIPAddressRange- Specified by:
iteratorin interfaceIPAddressSegmentSeries- Specified by:
iteratorin classAddress- Returns:
-
spliterator
Description copied from interface:AddressComponentRangePartitions and traverses through the individual address components.- Specified by:
spliteratorin interfaceAddressComponent- Specified by:
spliteratorin interfaceAddressComponentRange- Specified by:
spliteratorin interfaceAddressSegmentSeries- Specified by:
spliteratorin interfaceIPAddressRange- Specified by:
spliteratorin interfaceIPAddressSegmentSeries- Specified by:
spliteratorin classAddress- Returns:
-
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 interfaceAddressSegmentSeries- Specified by:
streamin interfaceIPAddressSegmentSeries- Specified by:
streamin classAddress- Returns:
-
nonZeroHostIterator
Description copied from interface:IPAddressSegmentSeriesSimilar to the iterator, but series with a host of zero are skipped.- Specified by:
nonZeroHostIteratorin interfaceIPAddressSegmentSeries- Returns:
-
prefixIterator
Description copied from interface:AddressSegmentSeriesIterates through the individual prefixes.If the series has no prefix length, then this is equivalent to
AddressSegmentSeries.iterator()- Specified by:
prefixIteratorin interfaceAddressSegmentSeries- Specified by:
prefixIteratorin interfaceIPAddressSegmentSeries- Specified by:
prefixIteratorin classAddress
-
prefixSpliterator
Description copied from interface:AddressSegmentSeriesPartitions and traverses through the individual prefixes for the prefix length of this series.- Specified by:
prefixSpliteratorin interfaceAddressSegmentSeries- Specified by:
prefixSpliteratorin interfaceIPAddressSegmentSeries- Specified by:
prefixSpliteratorin classAddress- Returns:
-
prefixStream
Description copied from interface:AddressSegmentSeriesReturns 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:
prefixStreamin interfaceAddressSegmentSeries- Specified by:
prefixStreamin interfaceIPAddressSegmentSeries- Specified by:
prefixStreamin classAddress- Returns:
-
prefixBlockIterator
Description copied from interface:AddressSegmentSeriesIterates through the individual prefix blocks.If the series has no prefix length, then this is equivalent to
AddressSegmentSeries.iterator()- Specified by:
prefixBlockIteratorin interfaceAddressSegmentSeries- Specified by:
prefixBlockIteratorin interfaceIPAddressSegmentSeries- Specified by:
prefixBlockIteratorin classAddress
-
prefixBlockSpliterator
Description copied from interface:AddressSegmentSeriesPartitions and traverses through the individual prefix blocks for the prefix length of this series.- Specified by:
prefixBlockSpliteratorin interfaceAddressSegmentSeries- Specified by:
prefixBlockSpliteratorin interfaceIPAddressSegmentSeries- Specified by:
prefixBlockSpliteratorin classAddress- Returns:
-
prefixBlockStream
Description copied from interface:AddressSegmentSeriesReturns 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:
prefixBlockStreamin interfaceAddressSegmentSeries- Specified by:
prefixBlockStreamin interfaceIPAddressSegmentSeries- Specified by:
prefixBlockStreamin classAddress- Returns:
-
blockIterator
Description copied from interface:IPAddressSegmentSeriesIterates 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:
blockIteratorin interfaceIPAddressSegmentSeries- Parameters:
segmentCount-- Returns:
-
blockSpliterator
Description copied from interface:IPAddressSegmentSeriesPartitions and traverses through the individual sequential blocks created from each of the individual values up to the given segment count.- Specified by:
blockSpliteratorin interfaceIPAddressSegmentSeries- Returns:
-
blockStream
Description copied from interface:IPAddressSegmentSeriesReturns 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:
blockStreamin interfaceIPAddressSegmentSeries- Returns:
-
sequentialBlockIterator
Description copied from interface:IPAddressSegmentSeriesIterates 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:
sequentialBlockIteratorin interfaceIPAddressSegmentSeries- Returns:
-
sequentialBlockSpliterator
Description copied from interface:IPAddressSegmentSeriesPartitions and traverses through the individual sequential blocks.- Specified by:
sequentialBlockSpliteratorin interfaceIPAddressSegmentSeries- Returns:
-
sequentialBlockStream
Description copied from interface:IPAddressSegmentSeriesReturns 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:
sequentialBlockStreamin interfaceIPAddressSegmentSeries- Returns:
-
getSequentialBlockCount
Description copied from interface:IPAddressSegmentSeriesprovides the count of elements from theIPAddressSegmentSeries.sequentialBlockIterator(), the minimal number of sequential sub-series that comprise this series- Specified by:
getSequentialBlockCountin interfaceIPAddressSegmentSeries- Returns:
-
getIterable
Description copied from interface:AddressComponentRangeUseful for using an instance in a "for-each loop". Otherwise just callAddressComponentRange.iterator()directly.- Specified by:
getIterablein interfaceAddressComponentRange- Specified by:
getIterablein interfaceAddressSegmentSeries- Specified by:
getIterablein interfaceIPAddressRange- Specified by:
getIterablein interfaceIPAddressSegmentSeries- Specified by:
getIterablein classAddress- Returns:
- an object to iterate over the individual addresses represented by this object.
-
increment
Description copied from interface:AddressSegmentSeriesReturns 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:
incrementin interfaceAddressSegmentSeries- Specified by:
incrementin interfaceIPAddressSegmentSeries- Specified by:
incrementin classAddress- Parameters:
increment-- Returns:
- Throws:
AddressValueException- in case of underflow or overflow
-
incrementBoundary
Description copied from interface:AddressSegmentSeriesIf 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:
incrementBoundaryin interfaceAddressSegmentSeries- Specified by:
incrementBoundaryin interfaceIPAddressSegmentSeries- Specified by:
incrementBoundaryin classAddress- Parameters:
increment-- Returns:
- Throws:
AddressValueException- in case of underflow or overflow
-
isIPAddress
public boolean isIPAddress()Description copied from class:AddressReturns whether this address is an IP address- Overrides:
isIPAddressin classAddress- Returns:
- whether this address is an IP address
-
toIPAddress
Description copied from class:AddressIf this address is an IP address, returns thatIPAddress. Otherwise, returns null.- Overrides:
toIPAddressin classAddress- Returns:
- the IP address
-
isIPv4
public boolean isIPv4() -
isIPv6
public boolean isIPv6() -
getIPVersion
Description copied from interface:IPAddressSegmentSeriesReturns the version of this segment series- Specified by:
getIPVersionin interfaceIPAddressSegmentSeries- Returns:
-
toIPv4
If this address is IPv4, or can be converted to IPv4, returns thatIPv4Address. Otherwise, returns null.- Returns:
- the address
- See Also:
-
toIPv6
- Returns:
- If this address is IPv6, or can be converted to IPv6, returns that
IPv6Address. Otherwise, returns null. - See Also:
-
isIPv4Convertible
public abstract boolean isIPv4Convertible()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 overridetoIPv4()to match the conversion. This method returns true for all IPv4 addresses.- Returns:
-
isIPv6Convertible
public abstract boolean isIPv6Convertible()Determines whether an address can be converted to IPv6, if not IPv6 already. Override this method to convert in your own way. The default behaviour is to convert by IPv4 mapping, seeIPv4Address.getIPv4MappedAddress()You should also overridetoIPv6()to match the conversion. This method returns true for all IPv6 addresses.- Returns:
-
isLinkLocal
public abstract boolean isLinkLocal()Returns whether the address is link local, whether unicast or multicast.- See Also:
-
isLocal
-
isUnspecified
public boolean isUnspecified()The unspecified address is the address that is all zeros.- Returns:
-
isAnyLocal
public boolean isAnyLocal()Returns whether this address is the address which binds to any address on the local host. This is the address that has the value of 0, aka the unspecified address.- See Also:
-
isLoopback
public abstract boolean isLoopback()- See Also:
-
toUpperInetAddress
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 totoInetAddress() -
toInetAddress
Converts the lowest value of this address to an InetAddress -
toSequentialRange
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 thesequentialBlockIterator()(orprefixIterator()), 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:
toSequentialRangein interfaceIPAddressRange- Returns:
-
toSequentialRange
@Deprecated public abstract IPAddressSeqRange toSequentialRange(IPAddress other) throws AddressConversionException Deprecated.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
toIPv4()ortoIPv6()When you have multiple subnets, create a range from lowest to highest with:
IPAddressSeqRange range = subnet0.applyToBounds(IPAddress::toSequentialRange, subnet1, subnet2, ...);See
applyToBounds(java.util.function.BiFunction, IPAddress...)- Parameters:
other-- Returns:
- Throws:
AddressConversionException
-
matches
-
overlaps
Returns true if this address overlaps the given address or subnet- Specified by:
overlapsin interfaceIPAddressRange- Parameters:
other-- Returns:
-
overlaps
Returns true if this address overlaps the given sequential range- Specified by:
overlapsin interfaceIPAddressRange- Parameters:
other-- Returns:
-
contains
Returns whether this contains all values of the given address or subnetImplements the same method in
IPAddressRange.- Specified by:
containsin interfaceIPAddressRange- Parameters:
other-- Returns:
-
containsNonZeroHosts
Returns whether this address contains the non-zero host addresses in the other address or subnet- Parameters:
other-- Returns:
-
enumerate
Indicates where an address sits relative to the subnet ordering.For more details, see the equivalent method
Address.enumerate(Address). This method satisfies the implementation ofIPAddressRange.- Specified by:
enumeratein interfaceIPAddressRange- Parameters:
other-- Returns:
-
prefixContains
Returns whether the prefix of this address contains all values of the same bits in the given address or subnet- Parameters:
other-- Returns:
-
isZeroHost
public boolean isZeroHost()Returns whether this address has a prefix length and if so, whether the host section is zero for this address or all addresses in this subnet. If the host section is zero length (there are no host bits at all), returns false.- Returns:
-
isZeroHost
public boolean isZeroHost(int networkPrefixLength) Returns whether the host is zero for the given prefix length for this address or all addresses in this subnet. If this address already has a prefix length, then that prefix length is ignored. If the host section is zero length (there are no host bits at all), returns false.- Returns:
-
contains
Description copied from interface:IPAddressRangeReturns whether this range contains all addresses in the given sequential range- Specified by:
containsin interfaceIPAddressRange- Parameters:
otherRange-- Returns:
-
matchesWithMask
-
toNormalizedString
public static void toNormalizedString(IPAddress.IPAddressValueProvider provider, StringBuilder builder) Allows for the creation of a normalized string without creating a full IP address object first. Instead you can implement theIPAddress.IPAddressValueProviderinterface in whatever way is most efficient. The string is appended to the providedStringBuilderinstance.- Parameters:
provider-builder-
-
toNormalizedString
Allows for the creation of a normalized string without creating a full IP address object first. Instead you can implement theIPAddress.IPAddressValueProviderinterface in whatever way is most efficient.- Parameters:
provider-
-
toFullString
This produces a string with no compressed segments and all segments of full length, which is 4 characters for IPv6 segments and 3 characters for IPv4 segments. Each address has a unique full string, not counting CIDR the prefix, which can give two equal addresses different strings.- Specified by:
toFullStringin interfaceIPAddressSegmentSeries
-
toSubnetString
Produces a consistent subnet string that looks like 1.2.*.* or 1:2::/16 In the case of IPv4, this means that wildcards are used instead of a network prefix when a network prefix has been supplied. In the case of IPv6, when a network prefix has been supplied, the prefix will be shown and the host section will be compressed with ::.- Specified by:
toSubnetStringin interfaceIPAddressSegmentSeries
-
toNormalizedWildcardString
This produces a string similar to the normalized string but avoids the CIDR prefix. CIDR addresses will be shown with wildcards and ranges instead of using the CIDR prefix notation.- Specified by:
toNormalizedWildcardStringin interfaceIPAddressSegmentSeries
-
toCanonicalWildcardString
This produces a string similar to the canonical string but avoids the CIDR prefix. Addresses with a network prefix length will be shown with wildcards and ranges instead of using the CIDR prefix length notation. IPv6 addresses will be compressed according to the canonical representation.- Specified by:
toCanonicalWildcardStringin interfaceIPAddressSegmentSeries
-
toCompressedWildcardString
This is similar to toNormalizedWildcardString, avoiding the CIDR prefix, but with compression as well.- Specified by:
toCompressedWildcardStringin interfaceIPAddressSegmentSeries
-
toSQLWildcardString
This is the same as the string from toNormalizedWildcardString except that it usesAddress.SEGMENT_SQL_WILDCARDinstead ofAddress.SEGMENT_WILDCARDand also usesAddress.SEGMENT_SQL_SINGLE_WILDCARD- Specified by:
toSQLWildcardStringin interfaceIPAddressSegmentSeries
-
toPrefixLengthString
Returns a string with a CIDR network prefix length if this address has a network prefix length. For IPv6, the host section will be compressed with ::, for IPv4 the host section will be zeros.- Specified by:
toPrefixLengthStringin interfaceIPAddressSegmentSeries- Returns:
-
toConvertedString
Returns a mixed string if it represents a convertible IPv4 address, returns the normalized string otherwise.- Returns:
-
toUNCHostName
Generates the Microsoft UNC path component for this address- Returns:
-
toReverseDNSLookupString
Generates the reverse DNS lookup stringFor 8.255.4.4 it is 4.4.255.8.in-addr.arpa
For 2001:db8::567:89ab it is b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa- Specified by:
toReverseDNSLookupStringin interfaceIPAddressSegmentSeries- Returns:
- Throws:
IncompatibleAddressException- if this address is a subnet
-
toBinaryString
Writes this address as a single binary value with always the exact same number of charactersIf this section represents a range of values not corresponding to a prefix, then this is printed as a range of two hex values.
- Specified by:
toBinaryStringin interfaceIPAddressSegmentSeries- Throws:
IncompatibleAddressException
-
toOctalString
Writes this address as a single octal value with always the exact same number of characters, with or without a preceding 0 prefix.If this section represents a range of values not corresponding to a prefix, then this is printed as a range of two hex values.
- Specified by:
toOctalStringin interfaceIPAddressSegmentSeries- Throws:
IncompatibleAddressException
-
toNormalizedString
Constructs a string representing this address according to the given parameters- Specified by:
toNormalizedStringin interfaceIPAddressSegmentSeries- Parameters:
params- the parameters for the address string- Returns:
- Throws:
IncompatibleAddressException- for cases in which the requested string cannot be produced, which can generally only occur with specific strings from specific subnets.
-
toStandardStrings
Returns at most a few dozen string representations: -mixed (1:2:3:4:5:6:1.2.3.4) -full compressions (a:0:b:c:d:0:e:f or a::b:c:d:0:e:f or a:0:b:c:d::e:f) -full leading zeros (000a:0000:000b:000c:000d:0000:000e:000f) -all uppercase and all lowercase (a::a can be A::A) -combinations thereof- Returns:
-
toAllStrings
Produces almost all possible string variationsUse this method with care... a single IPv6 address can have thousands of string representations.
Examples:
- "::" has 1297 such variations, but only 9 are considered standard
- "a:b:c:0:d:e:f:1" has 1920 variations, but only 12 are standard
Variations included in this method:
- all standard variations from
toStandardStrings() - adding a variable number of leading zeros (::a can be ::0a, ::00a, ::000a)
- choosing any number of zero-segments to compress (:: can be 0:0:0::0:0)
- mixed representation of all variations (1:2:3:4:5:6:1.2.3.4)
- all uppercase and all lowercase (a::a can be A::A)
- all combinations of such variations
- Returns:
- the strings
-
toStrings
Rather than using toAllStrings or StandardStrings, you can use this method to customize the list of strings produced for this address -
toStandardStringCollection
-
toAllStringCollection
-
toStringCollection
public IPAddressPartStringCollection toStringCollection(IPAddressSection.IPStringBuilderOptions options) - Specified by:
toStringCollectionin interfaceIPAddressSegmentSeries
-
toDelimitedSQLStrs
-
getNetworkPrefixLength
////////////////// masks and subnets below ///////////////////////- Specified by:
getNetworkPrefixLengthin interfaceIPAddressDivisionSeries- Returns:
-
getHostMask
Description copied from interface:IPAddressSegmentSeriesReturns 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:
getHostMaskin interfaceIPAddressSegmentSeries- Returns:
-
getNetworkMask
Description copied from interface:IPAddressSegmentSeriesReturns 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:
getNetworkMaskin interfaceIPAddressSegmentSeries- Returns:
-
includesZeroHost
public boolean includesZeroHost()Description copied from interface:IPAddressSegmentSeriesReturns whether the series has a host of zero. If the series has no prefix length, or the prefix length matches the bit count, then returns false. Otherwise, it checks whether all bits past the prefix are zero.- Specified by:
includesZeroHostin interfaceIPAddressSegmentSeries- Returns:
-
includesZeroHost
public boolean includesZeroHost(int networkPrefixLength) Description copied from interface:IPAddressSegmentSeriesReturns whether all bits past the given prefix length are zero.- Specified by:
includesZeroHostin interfaceIPAddressSegmentSeries- Returns:
-
toZeroHost
Description copied from interface:IPAddressSegmentSeriesProduces 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:
toZeroHostin interfaceIPAddressSegmentSeries- Parameters:
prefixLength-- Returns:
-
toZeroHost
Description copied from interface:IPAddressSegmentSeriesReturns 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:
toZeroHostin interfaceIPAddressSegmentSeries- Returns:
- See Also:
-
toZeroNetwork
Description copied from interface:IPAddressSegmentSeriesReturns 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:
toZeroNetworkin interfaceIPAddressSegmentSeries- Returns:
- See Also:
-
toMaxHost
Description copied from interface:IPAddressSegmentSeriesProduces 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:
toMaxHostin interfaceIPAddressSegmentSeries- Parameters:
prefixLength-- Returns:
-
toMaxHost
Description copied from interface:IPAddressSegmentSeriesReturns 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:
toMaxHostin interfaceIPAddressSegmentSeries- Returns:
-
includesMaxHost
public boolean includesMaxHost()Description copied from interface:IPAddressSegmentSeriesReturns whether the series has a host of all ones. If the series has no prefix length, or the prefix length matches the bit count, then returns false. Otherwise, it checks whether all bits past the prefix are ones.- Specified by:
includesMaxHostin interfaceIPAddressSegmentSeries- Returns:
-
includesMaxHost
public boolean includesMaxHost(int networkPrefixLength) Description copied from interface:IPAddressSegmentSeriesReturns whether all bits past the given prefix length are all ones.- Specified by:
includesMaxHostin interfaceIPAddressSegmentSeries- Returns:
-
isSingleNetwork
public boolean isSingleNetwork()Returns true if the network section of the address spans just a single valueFor example, return true for 1.2.3.4/16 and false for 1.2-3.3.4/16
-
toPrefixBlock
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:
toPrefixBlockin interfaceAddressSegmentSeries- Specified by:
toPrefixBlockin interfaceIPAddressSegmentSeries- Specified by:
toPrefixBlockin classAddress- Returns:
- the block of address series for the prefix length
-
toPrefixBlock
Description copied from interface:IPAddressSegmentSeriesReturns 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:
toPrefixBlockin interfaceIPAddressSegmentSeries- Parameters:
networkPrefixLength-- Returns:
- Throws:
PrefixLenException
-
assignPrefixForSingleBlock
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:
assignPrefixForSingleBlockin interfaceIPAddressSegmentSeries- Returns:
- See Also:
-
assignMinPrefixForBlock
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:
assignMinPrefixForBlockin interfaceIPAddressSegmentSeries- Returns:
- See Also:
-
getBlockMaskPrefixLength
If this address is equivalent to the mask for a CIDR prefix block, it returns that prefix length. Otherwise, it returns null. A CIDR network mask is all 1 bits in the network section and then all 0 bits in the host section. A CIDR host mask is all 0 bits in the network section and then all 1 bits in the host section. The prefix is the length of the network section.Also, keep in mind that the prefix length returned by this method is not equivalent to the prefix length used to construct this object. The prefix length used to construct indicates the network and host section of this address. The prefix length returned here indicates the whether the value of this address can be used as a mask for the network and host section of any other address. Therefore the two values can be different values, or one can be null while the other is not.
Just like the mask methods which use the lower value for masking, this method applies only to the lower value of the range if this address represents multiple values.
- Parameters:
network- whether to check if we are a network mask or a host mask- Returns:
- the prefix length corresponding to this mask, or null if there is no such prefix length
-
getTrailingBitCount
public int getTrailingBitCount(boolean network) Returns the number of consecutive trailing one or zero bits. If network is true, returns the number of consecutive trailing zero bits. Otherwise, returns the number of consecutive trailing one bits.This method applies only to the lower value of the range if this address represents multiple values.
- Parameters:
network-- Returns:
-
getLeadingBitCount
public int getLeadingBitCount(boolean network) Returns the number of consecutive leading one or zero bits. If network is true, returns the number of consecutive leading one bits. Otherwise, returns the number of consecutive leading zero bits.This method applies only to the lower value of the range if this address represents multiple values.
- Parameters:
network-- Returns:
-
coverWithPrefixBlock
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
toIPv4()ortoIPv6()When you have multiple subnets, cover with:
IPAddress block = subnet0.applyToBounds(IPAddress::coverWithPrefixBlock, subnet1, subnet2, ...);See
applyToBounds(java.util.function.BiFunction, IPAddress...)- Throws:
AddressConversionException
-
spanWithPrefixBlocks
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
toIPv4()ortoIPv6()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
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
applyToBounds(java.util.function.BiFunction, IPAddress...)- Parameters:
other-- Returns:
- Throws:
AddressConversionException
-
spanWithSequentialBlocks
public abstract IPAddress[] spanWithSequentialBlocks(IPAddress other) throws AddressConversionException 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
toIPv4()ortoIPv6()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
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
applyToBounds(java.util.function.BiFunction, IPAddress...)- Parameters:
other-- Returns:
- Throws:
AddressConversionException
-
spanWithRange
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
toIPv4()ortoIPv6()When you have multiple subnets, span with:
IPAddressSeqRange range = subnet0.applyToBounds(IPAddress::spanWithRange, subnet1, subnet2, ...);See
applyToBounds(java.util.function.BiFunction, IPAddress...)- Parameters:
other-- Returns:
- Throws:
AddressConversionException
-
mergeToPrefixBlocks
public abstract IPAddress[] mergeToPrefixBlocks(IPAddress... addresses) throws AddressConversionException Merges this with the list of addresses to produce the smallest list of prefix blocks.For the smallest list of subnets use
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
toIPv4()ortoIPv6(), 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
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
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
sequentialBlockIterator(), then convert each sequential block toIPAddressSeqRangewithtoSequentialRange(), then join those sequential ranges withIPAddressSeqRange.join(IPAddressSeqRange...), then convert them to CIDR prefix blocks withIPAddressSeqRange.spanWithPrefixBlocks(), giving the same result as this method.- Parameters:
addresses- the addresses to merge with this- Returns:
- Throws:
AddressConversionException
-
mergeToDualSequentialBlocks
merges the given set of IP addresses and subnets into a minimal number of prefix blocks. This function complements the MergeToPrefixBlock methods of each IP address type. Those instance methods attempt to convert arguments that do not match the IP version of the method receiver, while this function does not. This static method merges every non-null argument into one of the two returned slices.- Parameters:
addresses-- Returns:
-
mergeToDualPrefixBlocks
merges the given set of IP addresses and subnets into a minimal number of prefix blocks. This function complements the MergeToPrefixBlock methods of each IP address type. Those instance methods attempt to convert arguments that do not match the IP version of the method receiver, while this function does not. This static method merges every non-null argument into one of the two returned slices.- Parameters:
addresses-- Returns:
-
mergeToSequentialBlocks
public abstract IPAddress[] mergeToSequentialBlocks(IPAddress... addresses) throws AddressConversionException 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
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
toIPv4()ortoIPv6(), 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
mergeToPrefixBlocks(IPAddress...)for some alternatives for merging subnets.- Parameters:
addresses- the addresses to merge with this- Returns:
- Throws:
AddressConversionException
-
intersect
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
toIPv4()ortoIPv6(), and it that fails,AddressConversionExceptionwill be thrown.- 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
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
toIPv4()ortoIPv6(), and it that fails,AddressConversionExceptionwill be thrown.- Parameters:
other-- Returns:
- the difference
- Throws:
AddressConversionException- if the address argument could not be converted to the same address version as this
-
mask
public abstract IPAddress mask(IPAddress mask) throws AddressConversionException, IncompatibleAddressException Equivalent to callingmask(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
toIPv4()ortoIPv6()- 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 abstract IPAddress mask(IPAddress mask, boolean retainPrefix) throws AddressConversionException, IncompatibleAddressException 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
toIPv4()ortoIPv6()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
IncompatibleAddressExceptionis thrown.- 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 abstract IPAddress maskNetwork(IPAddress mask, int networkPrefixLength) throws AddressConversionException, IncompatibleAddressException 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
toIPv4()ortoIPv6()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
IncompatibleAddressExceptionis thrown.- 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 abstract IPAddress bitwiseOr(IPAddress mask) throws AddressConversionException, IncompatibleAddressException Equivalent to callingbitwiseOr(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
toIPv4()ortoIPv6()- Parameters:
mask-- Returns:
- Throws:
AddressConversionException- if the address argument could not be converted to the same address version as thisIncompatibleAddressException- 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 segment
-
bitwiseOr
public abstract IPAddress bitwiseOr(IPAddress mask, boolean retainPrefix) throws AddressConversionException, IncompatibleAddressException Does the bitwise disjunction with this address. Useful when subnetting.The mask is applied to all individual addresses, similar to how the method
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
toIPv4()ortoIPv6()If you wish to mask a section of the network, use
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- Parameters:
mask-retainPrefix-- Returns:
- Throws:
AddressConversionException- if the address argument could not be converted to the same address version as thisIncompatibleAddressException- 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 segment
-
bitwiseOrNetwork
public abstract IPAddress bitwiseOrNetwork(IPAddress mask, int networkPrefixLength) throws AddressConversionException, IncompatibleAddressException 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
toIPv4()ortoIPv6()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
maskNetwork(IPAddress, int)method does the bitwise conjunction.- 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 this
-
removePrefixLength
Deprecated.Description copied from interface:AddressSegmentSeriesRemoves 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:
removePrefixLengthin interfaceAddressSegmentSeries- Specified by:
removePrefixLengthin interfaceIPAddressSegmentSeries- Specified by:
removePrefixLengthin classAddress- Returns:
- See Also:
-
removePrefixLength
Deprecated.Description copied from interface:AddressSegmentSeriesRemoves the prefix length. If zeroed is false, the bits that were host bits do not become zero, unlikeAddressSegmentSeries.removePrefixLength()- Specified by:
removePrefixLengthin interfaceAddressSegmentSeries- Specified by:
removePrefixLengthin interfaceIPAddressSegmentSeries- Specified by:
removePrefixLengthin classAddress- Parameters:
zeroed- whether the bits outside the prefix become zero- Returns:
-
withoutPrefixLength
Description copied from interface:AddressSegmentSeriesProvides 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:
withoutPrefixLengthin interfaceAddressSegmentSeries- Specified by:
withoutPrefixLengthin interfaceIPAddressSegmentSeries- Specified by:
withoutPrefixLengthin classAddress
-
adjustPrefixBySegment
Description copied from interface:AddressSegmentSeriesIncreases 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:
adjustPrefixBySegmentin interfaceAddressSegmentSeries- Specified by:
adjustPrefixBySegmentin interfaceIPAddressSegmentSeries- Specified by:
adjustPrefixBySegmentin classAddress- Parameters:
nextSegment- whether to move prefix to previous or following segment boundary- Returns:
-
adjustPrefixBySegment
Description copied from interface:AddressSegmentSeriesIncreases or decreases prefix length to the next segment boundary.- Specified by:
adjustPrefixBySegmentin interfaceAddressSegmentSeries- Specified by:
adjustPrefixBySegmentin interfaceIPAddressSegmentSeries- Specified by:
adjustPrefixBySegmentin classAddress- 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
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:
adjustPrefixLengthin interfaceAddressSegmentSeries- Specified by:
adjustPrefixLengthin interfaceIPAddressSegmentSeries- Specified by:
adjustPrefixLengthin classAddress- Parameters:
adjustment-- Returns:
-
adjustPrefixLength
Description copied from interface:AddressSegmentSeriesIncreases or decreases prefix length by the given increment.- Specified by:
adjustPrefixLengthin interfaceAddressSegmentSeries- Specified by:
adjustPrefixLengthin interfaceIPAddressSegmentSeries- Specified by:
adjustPrefixLengthin classAddress- 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:AddressSegmentSeriesSets 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:
setPrefixLengthin interfaceAddressSegmentSeries- Specified by:
setPrefixLengthin interfaceIPAddressSegmentSeries- Specified by:
setPrefixLengthin classAddress- Parameters:
prefixLength-- Returns:
-
setPrefixLength
Description copied from interface:AddressSegmentSeriesSets the prefix length.When the prefix is extended beyond the segment series boundary, it is removed.
- Specified by:
setPrefixLengthin interfaceAddressSegmentSeries- Specified by:
setPrefixLengthin interfaceIPAddressSegmentSeries- Specified by:
setPrefixLengthin classAddress- 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 abstract IPAddress 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. The latter behaviour only applies to the default prefix handling configuration, PREFIXED_ZERO_HOSTS_ARE_SUBNETS. The methodssetPrefixLength(int, boolean)andsetPrefixLength(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.
- Parameters:
prefixLength-zeroed-zeroHostIsBlock-- Returns:
-
applyPrefixLength
Deprecated.Description copied from interface:AddressSegmentSeriesApplies 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:
applyPrefixLengthin interfaceAddressSegmentSeries- Specified by:
applyPrefixLengthin interfaceIPAddressSegmentSeries- Specified by:
applyPrefixLengthin classAddress- Parameters:
networkPrefixLength-- Returns:
- See Also:
-
getMatchesSQLClause
Returns a clause for matching this address.If this address is a subnet, this method will attempt to match every address in the subnet. Therefore it is much more efficient to use getNetworkSection().getStartsWithSQLClause() for a CIDR subnet.
- Parameters:
builder-sqlExpression-
-
getMatchesSQLClause
public void getMatchesSQLClause(StringBuilder builder, String sqlExpression, IPAddressSQLTranslator translator) Returns a clause for matching this address.Similar to getMatchesSQLClause(StringBuilder builder, String sqlExpression) but allows you to tailor the SQL produced.
- Parameters:
builder-sqlExpression-translator-
-
removeBitCountPrefixLength
Removes the prefix length from addresses with a prefix length extending to the end of the address.- Returns:
-
spanWithRange(IPAddress)