- All Implemented Interfaces:
AddressDivisionSeries
,AddressItem
,IPAddressDivisionSeries
,AddressStringDivisionSeries
,IPAddressStringDivisionSeries
,Serializable
,Comparable<AddressItem>
- Direct Known Subclasses:
IPAddressSection
,IPv6AddressSection.IPv6v4MixedAddressSection
With the IPAddressSection subclass, each division is one segment (eg either groupings of 4 like 1.2.3.4 or groupings of 8 like 1:2:3:4:5:6:7:8).
For IPv6, a compressed segment still counts as one of the groupings, it is simply not printed as part of the text representation.
Alternative groupings include ipv4 groupings define by inet_aton (eg groupings of 1, 2, or 3 divisions like 1, 1.2, and 1.2.3) and the mixed ipv6/ipv4 representation of ipv6 addresses (eg a grouping of 10 divisions like a:b:c:d:e:f:1.2.3.4)
IPAddressDivisionGrouping objects are immutable. Some of the derived state is created upon demand and cached. This also makes them thread-safe.
IPAddressDivisionGrouping objects may be associated with a prefix length, in which case that number of bits in the upper-most portion of the object represent a prefix, while the remaining bits assume all possible values.
IPAddressDivision objects use long to represent their values, so this places a cap on the size of the divisions in IPAddressDivisionGrouping.
- Author:
- sfoley
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
Nested classes/interfaces inherited from class inet.ipaddr.format.standard.AddressDivisionGrouping
AddressDivisionGrouping.DivisionLengthProvider, AddressDivisionGrouping.DivisionValueProvider, AddressDivisionGrouping.StringOptions
-
Constructor Summary
ConstructorsConstructorDescriptionIPAddressDivisionGrouping
(IPAddressDivision[] divisions, IPAddressNetwork<?, ?, ?, ?, ?> network) Constructs a grouping of IPAddress divisions. -
Method Summary
Modifier and TypeMethodDescriptionboolean
containsPrefixBlock
(int prefixLength) Returns whether the values of this division grouping contain the prefix block for the given prefix lengthboolean
containsSinglePrefixBlock
(int prefixLength) Returns whether the values of this division grouping match the prefix block for the given prefix lengthboolean
Two groupings are equal if: - they match type/version (ipv4, ipv6, mac, or a specific grouping class) - they match division counts - each division matches bit counts - each division matches their specific grouping class - each division matches values Prefix lengths, for those groupings and/or divisionsS that have them, are ignored.getDivision
(int index) int
getLeadingBitCount
(boolean network) Returns the number of consecutive leading one or zero bits.IPAddressNetwork
<?, ?, ?, ?, ?> Returns the CIDR network prefix length of the series, or null if the series has no associated prefix length.The bit-length of the portion of the address that is not specific to an individual address but common amongst a group of addresses.Returns a prefix length for which the range of this segment grouping matches the block of addresses for that prefix.int
getTrailingBitCount
(boolean network) Returns the number of consecutive trailing one or zero bits.boolean
int
isMore
(AddressDivisionSeries other) Use this method to compare the counts of two address series.boolean
Returns whether this address section represents a subnet block of addresses associated its prefix length.boolean
Returns whether the division grouping range matches the block of values for its prefix length.Methods inherited from class inet.ipaddr.format.standard.AddressDivisionGrouping
hashCode
Methods inherited from class inet.ipaddr.format.AddressDivisionGroupingBase
getBytes, getBytes, getBytes, getCount, getDivisionCount, getDivisionStrings, getMinPrefixLengthForBlock, getPrefixCount, getUpperBytes, getUpperBytes, getUpperBytes, getUpperValue, getValue, includesMax, includesZero, isFullRange, isMax, isMultiple, isPrefixed, isZero, toString
Methods inherited from interface inet.ipaddr.format.AddressDivisionSeries
getBitCount, getBlockCount, getCount, getDivisionStrings, getPrefixCount, getPrefixCount, getSequentialBlockIndex, isPrefixed, isSequential
Methods inherited from interface inet.ipaddr.format.AddressItem
compareTo, getByteCount, getBytes, getBytes, getBytes, getMinPrefixLengthForBlock, getUpperBytes, getUpperBytes, getUpperBytes, getUpperValue, getValue, includesMax, includesZero, isFullRange, isMax, isMultiple, isZero
Methods inherited from interface inet.ipaddr.format.string.AddressStringDivisionSeries
getDivisionCount
Methods inherited from interface inet.ipaddr.format.string.IPAddressStringDivisionSeries
isPrefixed
-
Constructor Details
-
IPAddressDivisionGrouping
public IPAddressDivisionGrouping(IPAddressDivision[] divisions, IPAddressNetwork<?, ?, throws AddressValueException?, ?, ?> network) Constructs a grouping of IPAddress divisions.Note: If the grouping is prefixed and the prefix length aligns with a division boundary, then we allow as division prefix lengths both null:null:x:0:0 where is x is the division bit count and null:null:null:0:0, which are essentially equivalent. The overall prefix length of this example grouping is the division bit count tripled. For further discussion of this, see
AddressDivisionGrouping.normalizePrefixBoundary(int, IPAddressSegment[], int, int, java.util.function.Function)
- Parameters:
divisions
-network
-- Throws:
NullPointerException
- if network is null or a division is nullAddressValueException
-
-
Method Details
-
getNetwork
- Specified by:
getNetwork
in interfaceIPAddressStringDivisionSeries
-
getDivision
- Specified by:
getDivision
in interfaceAddressDivisionSeries
- Specified by:
getDivision
in interfaceAddressStringDivisionSeries
- Specified by:
getDivision
in interfaceIPAddressDivisionSeries
- Specified by:
getDivision
in interfaceIPAddressStringDivisionSeries
- Overrides:
getDivision
in classAddressDivisionGrouping
- Returns:
- the given division in this series. The first is at index 0.
-
isMore
Description copied from interface:AddressDivisionSeries
Use this method to compare the counts of two address series. Rather than calculating counts with getCount(), there can be more efficient ways of comparing whether one series represents more individual address series than another.- Specified by:
isMore
in interfaceAddressDivisionSeries
- Returns:
- a positive integer if this AddressDivisionSeries has a larger count than the provided, 0 if they are the same, a negative integer if the other has a larger count.
-
getPrefixLength
Description copied from interface:AddressDivisionSeries
The bit-length of the portion of the address that is not specific to an individual address but common amongst a group of addresses.Typically this is the largest number of bits in the upper-most portion of the section for which the remaining bits assume all possible values.
For IP addresses, this must be explicitly defined when the address is created. For example, 1.2.0.0/16 has a prefix length of 16, while 1.2.*.* has no prefix length, even though they both represent the same set of addresses and are considered equal. Prefixes can be considered variable for any given IP addresses and can depend on the routing table.
The methods
AddressItem.getMinPrefixLengthForBlock()
andAddressItem.getPrefixLengthForSingleBlock()
can help you to obtain or define a prefix length if one does not exist already. 1.2.0.0/16 and 1.2.*.* both the same equivalent and minimum prefix length of 16.For MAC addresses, the prefix is initially defined by the range, so 1:2:3:*:*:* has a prefix length of 24 by definition. Addresses derived from the original may retain the original prefix length regardless of their range.
- Specified by:
getPrefixLength
in interfaceAddressDivisionSeries
- Specified by:
getPrefixLength
in interfaceIPAddressStringDivisionSeries
- Overrides:
getPrefixLength
in classAddressDivisionGroupingBase
- Returns:
- the prefix length or null if there is none
-
getNetworkPrefixLength
Description copied from interface:IPAddressDivisionSeries
Returns the CIDR network prefix length of the series, or null if the series has no associated prefix length.Equivalent to
AddressDivisionSeries.getPrefixLength()
, which is the more general concept of set of address series that share the same set of leading bits. For IP addresses and sections the prefix length and the CIDR network prefix length are the same thing.For IP addresses and sections each individual segment has an associated prefix length which is determine by the network prefix length. The segment prefix lengths follow the pattern: null, null, ...., null, x, 0, 0, ..., 0
For instance, an IPv4 address 1.2.3.4/16 has the network prefix length 16. The segment prefix lengths are [null, 8, 0, 0] The segment prefix lengths of 1.2.3.4/22 are [null, null, 6, 0]
- Specified by:
getNetworkPrefixLength
in interfaceIPAddressDivisionSeries
- Returns:
-
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 division 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 division represents multiple values.
- Parameters:
network
-- Returns:
-
isPrefixBlock
public boolean isPrefixBlock()Returns whether this address section represents a subnet block of addresses associated its prefix length. Returns false if it has no prefix length, if it is a single address with a prefix length (ie not a subnet), or if it is a range of addresses that does not include the entire subnet block for its prefix length. IfAddressNetwork.getPrefixConfiguration()
is set to consider all prefixes as subnets, this returns true for any grouping with prefix length.- Specified by:
isPrefixBlock
in interfaceAddressDivisionSeries
- Specified by:
isPrefixBlock
in interfaceIPAddressStringDivisionSeries
- Overrides:
isPrefixBlock
in classAddressDivisionGroupingBase
- Returns:
-
containsPrefixBlock
public boolean containsPrefixBlock(int prefixLength) Description copied from class:AddressDivisionGrouping
Returns whether the values of this division grouping contain the prefix block for the given prefix length- Specified by:
containsPrefixBlock
in interfaceAddressItem
- Overrides:
containsPrefixBlock
in classAddressDivisionGrouping
- Parameters:
prefixLength
-- Returns:
-
containsSinglePrefixBlock
public boolean containsSinglePrefixBlock(int prefixLength) Description copied from class:AddressDivisionGrouping
Returns whether the values of this division grouping match the prefix block for the given prefix length- Specified by:
containsSinglePrefixBlock
in interfaceAddressItem
- Overrides:
containsSinglePrefixBlock
in classAddressDivisionGrouping
- Parameters:
prefixLength
-- Returns:
-
isSinglePrefixBlock
public boolean isSinglePrefixBlock()Returns whether the division grouping range matches the block of values for its prefix length. In other words, returns true if and only if it has a prefix length and it has just a single prefix.- Specified by:
isSinglePrefixBlock
in interfaceAddressDivisionSeries
- Overrides:
isSinglePrefixBlock
in classAddressDivisionGroupingBase
- Returns:
-
getPrefixLengthForSingleBlock
Description copied from class:AddressDivisionGroupingBase
Returns a prefix length for which the range of this segment grouping matches the block of addresses for that prefix. If no such prefix exists, returns null If this segment grouping represents a single value, returns the bit length- Specified by:
getPrefixLengthForSingleBlock
in interfaceAddressItem
- Overrides:
getPrefixLengthForSingleBlock
in classAddressDivisionGroupingBase
- Returns:
- the prefix length or null
-
includesZeroHost
public boolean includesZeroHost() -
equals
Description copied from class:AddressDivisionGroupingBase
Two groupings are equal if: - they match type/version (ipv4, ipv6, mac, or a specific grouping class) - they match division counts - each division matches bit counts - each division matches their specific grouping class - each division matches values Prefix lengths, for those groupings and/or divisionsS that have them, are ignored.- Overrides:
equals
in classAddressDivisionGrouping
-
getZeroSegments
- Returns:
- the segments which are zero
-
getZeroRangeSegments
- Returns:
- the segments which are zero or whose prefix-based range includes 0
-