- java.lang.Object
-
- inet.ipaddr.format.AddressDivisionBase
-
- inet.ipaddr.format.standard.AddressDivision
-
- All Implemented Interfaces:
AddressGenericDivision
,AddressItem
,AddressStringDivision
,java.io.Serializable
,java.lang.Comparable<AddressItem>
- Direct Known Subclasses:
AddressBitsDivision
,IPAddressDivision
,MACAddressSegment
public abstract class AddressDivision extends AddressDivisionBase
A division of an address.- Author:
- sfoley
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AddressDivision.BitwiseOrResult
Represents the result of a bitwise or of a sequential range of valuesstatic class
AddressDivision.MaskResult
Represents the result of masking a sequential range of values
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static AddressDivision.BitwiseOrResult
bitwiseOrRange(long value, long upperValue, long maskValue)
Applies bitwise or to a range of values.boolean
equals(java.lang.Object o)
Two divisions are equal if they: - they match type/version (ipv4, ipv6, mac, or a specific division class) - match bit counts - match values Prefix lengths, for those divisions that have them, are ignored.java.math.BigInteger
getCount()
The count of possible distinct values for this AddressComponent.int
getDigitCount(int radix)
Returns the count of digits of the value, or if a range, the larger value in the rangelong
getDivisionPrefixCount(int divisionPrefixLength)
abstract long
getDivisionValue()
long
getDivisionValueCount()
int
getMaxDigitCount(int radix)
Returns the count of digits of the largest possible valuelong
getMaxValue()
int
getMinPrefixLengthForBlock()
Returns the smallest prefix length possible such that this item includes the block of all values for that prefix length.java.math.BigInteger
getPrefixCount(int divisionPrefixLength)
The count of the number of distinct values within the prefix part of the address item, the bits that appear within the prefix length.java.lang.Integer
getPrefixLengthForSingleBlock()
Returns a prefix length for which the range of this item matches the block of all values for that prefix length.abstract long
getUpperDivisionValue()
java.math.BigInteger
getUpperValue()
Returns the highest value represented by this address item, the highest value included in the range of valuesjava.math.BigInteger
getValue()
Returns the lowest value represented by this address item, the lowest value included in the range of valuesint
hashCode()
boolean
hasUppercaseVariations(int radix, boolean lowerOnly)
boolean
includesMax()
Returns whether this item includes the maximum possible value for the address type or version within its rangeboolean
includesZero()
Returns whether this item includes the value of zero within its rangeboolean
isBitwiseOrCompatibleWithRange(int maskValue)
Similar to masking, checks that the range resulting from the bitwise "or" operation is sequential.boolean
isBoundedBy(int value)
Returns true if the possible values of this division fall below the given value.boolean
isMaskCompatibleWithRange(int maskValue)
Check that the range resulting from the mask is contiguous, otherwise it cannot be represented by a division or segment instance.boolean
isMax()
Returns whether this item matches the maximum possible value for the address type or versionboolean
isMultiple()
Whether this represents multiple potential values (eg a prefixed address or a segment representing a range of values)boolean
isZero()
Returns whether this item matches the value of zerostatic AddressDivision.MaskResult
maskRange(long value, long upperValue, long maskValue)
Returns an object that provides the masked values for a range, which for subnets is an aggregation of all masked individual addresses in the subnet.boolean
matches(long value)
boolean
matchesWithMask(long value, long mask)
boolean
matchesWithMask(long lowerValue, long upperValue, long mask)
returns whether masking with the given mask results in a valid contiguous range for this segment, and if it does, if it matches the range obtained when masking the given values with the same mask.-
Methods inherited from class inet.ipaddr.format.AddressDivisionBase
getBytes, getBytes, getBytes, getDigitCount, getLowerStandardString, getStandardString, getUpperBytes, getUpperBytes, getUpperBytes, toString
-
Methods inherited from interface inet.ipaddr.format.AddressItem
compareTo, containsPrefixBlock, containsSinglePrefixBlock, getBitCount, getByteCount, isFullRange
-
-
-
-
Method Detail
-
isMultiple
public boolean isMultiple()
Description copied from interface:AddressItem
Whether this represents multiple potential values (eg a prefixed address or a segment representing a range of values)- Returns:
- whether this segment represents multiple values
-
getMinPrefixLengthForBlock
public int getMinPrefixLengthForBlock()
Description copied from interface:AddressItem
Returns the smallest prefix length possible such that this item includes the block of all values for that prefix length.If the entire range can be dictated this way, then this method returns the same value as
AddressItem.getPrefixLengthForSingleBlock()
. Otherwise, this method will return the minimal possible prefix that can be paired with this address, whileAddressItem.getPrefixLengthForSingleBlock()
will return null.In cases where the final bit is constant so there is no such block, this returns the bit count.
- Returns:
- the prefix length
-
getPrefixLengthForSingleBlock
public java.lang.Integer getPrefixLengthForSingleBlock()
Description copied from interface:AddressItem
Returns a prefix length for which the range of this item matches the block of all values for that prefix length.If the range can be dictated this way, then this method returns the same value as
AddressItem.getMinPrefixLengthForBlock()
.If no such prefix length exists, returns null.
If this item represents a single value, this returns the bit count.
- Returns:
- the prefix length or null
-
getMaxValue
public long getMaxValue()
-
isZero
public boolean isZero()
Description copied from interface:AddressItem
Returns whether this item matches the value of zero- Returns:
- whether this item matches the value of zero
-
includesZero
public boolean includesZero()
Description copied from interface:AddressItem
Returns whether this item includes the value of zero within its range- Returns:
- whether this item includes the value of zero within its range
-
isMax
public boolean isMax()
Description copied from interface:AddressItem
Returns whether this item matches the maximum possible value for the address type or version- Returns:
- whether this item matches the maximum possible value
-
includesMax
public boolean includesMax()
Description copied from interface:AddressItem
Returns whether this item includes the maximum possible value for the address type or version within its range- Returns:
- whether this item includes the maximum possible value within its range
-
getDivisionValue
public abstract long getDivisionValue()
-
getUpperDivisionValue
public abstract long getUpperDivisionValue()
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classAddressDivisionBase
-
getValue
public java.math.BigInteger getValue()
Description copied from interface:AddressItem
Returns the lowest value represented by this address item, the lowest value included in the range of values- Returns:
- the lowest value represented by this address item
-
getUpperValue
public java.math.BigInteger getUpperValue()
Description copied from interface:AddressItem
Returns the highest value represented by this address item, the highest value included in the range of values- Returns:
- the highest value represented by this address item
-
getDivisionValueCount
public long getDivisionValueCount()
-
getPrefixCount
public java.math.BigInteger getPrefixCount(int divisionPrefixLength)
Description copied from interface:AddressItem
The count of the number of distinct values within the prefix part of the address item, the bits that appear within the prefix length.- Returns:
-
getDivisionPrefixCount
public long getDivisionPrefixCount(int divisionPrefixLength)
-
getCount
public java.math.BigInteger getCount()
Description copied from interface:AddressItem
The count of possible distinct values for this AddressComponent. If not multiple, this is 1. For instance, if this is the ip address series subnet 0::/64, then the count is 2 to the power of 64. If this is a the segment 3-7, then the count is 5.- Returns:
-
isBoundedBy
public boolean isBoundedBy(int value)
Returns true if the possible values of this division fall below the given value.
-
matches
public boolean matches(long value)
-
matchesWithMask
public boolean matchesWithMask(long value, long mask)
-
matchesWithMask
public boolean matchesWithMask(long lowerValue, long upperValue, long mask)
returns whether masking with the given mask results in a valid contiguous range for this segment, and if it does, if it matches the range obtained when masking the given values with the same mask.- Parameters:
lowerValue
-upperValue
-mask
-- Returns:
-
equals
public boolean equals(java.lang.Object o)
Description copied from class:AddressDivisionBase
Two divisions are equal if they: - they match type/version (ipv4, ipv6, mac, or a specific division class) - match bit counts - match values Prefix lengths, for those divisions that have them, are ignored.- Overrides:
equals
in classAddressDivisionBase
-
isMaskCompatibleWithRange
public boolean isMaskCompatibleWithRange(int maskValue)
Check that the range resulting from the mask is contiguous, otherwise it cannot be represented by a division or segment instance. For instance, for the range 0 to 3 (bits are 00 to 11), if we mask all 4 numbers from 0 to 3 with 2 (ie bits are 10), then we are left with 1 and 3. 2 is not included. So we cannot represent 1 and 3 as a contiguous range. The underlying rule is that mask bits that are 0 must be above the resulting range in each segment. Any bit in the mask that is 0 must not fall below any bit in the masked segment range that is different between low and high. Any network mask must eliminate the entire division range or keep the entire range. Any host mask is fine.- Parameters:
maskValue
-- Returns:
-
maskRange
public static AddressDivision.MaskResult maskRange(long value, long upperValue, long maskValue)
Returns an object that provides the masked values for a range, which for subnets is an aggregation of all masked individual addresses in the subnet. SeebitwiseOrRange(long, long, long)
- Parameters:
value
-upperValue
-maskValue
-- Returns:
- an instance that provides the result of masking the values. With individual addresses, the result is simply value & maskValue. But with subnets, returns an object providing lower and upper results along with whether the resulting set of values is sequential.
-
isBitwiseOrCompatibleWithRange
public boolean isBitwiseOrCompatibleWithRange(int maskValue)
Similar to masking, checks that the range resulting from the bitwise "or" operation is sequential.- Parameters:
maskValue
-- Returns:
-
bitwiseOrRange
public static AddressDivision.BitwiseOrResult bitwiseOrRange(long value, long upperValue, long maskValue)
Applies bitwise or to a range of values. Returns an object that provides the ored values for a range, which for subnets is an aggregation of all ored individual addresses in the subnet. SeemaskRange(long, long, long)
- Parameters:
maskValue
-- Returns:
-
hasUppercaseVariations
public boolean hasUppercaseVariations(int radix, boolean lowerOnly)
-
getDigitCount
public int getDigitCount(int radix)
Description copied from interface:AddressStringDivision
Returns the count of digits of the value, or if a range, the larger value in the range- Returns:
-
getMaxDigitCount
public int getMaxDigitCount(int radix)
Description copied from interface:AddressStringDivision
Returns the count of digits of the largest possible value- Returns:
-
-