inet.ipaddr.format

Class IPAddressDivision

    • Field Detail

      • ADJUST_RANGES_BY_PREFIX

        public static final boolean ADJUST_RANGES_BY_PREFIX
        See Also:
        Constant Field Values
    • Method Detail

      • isPrefixed

        public boolean isPrefixed()
      • getDivisionPrefixLength

        public java.lang.Integer getDivisionPrefixLength()
        Returns the network prefix for the division. The network prefix is 16 for an address like 1.2.0.0/16. When it comes to each address division or segment, the prefix for the division is the prefix obtained when applying the address or section prefix. For instance, with the address 1.2.0.0/20, segment 1 has no prefix because the address prefix 20 extends beyond the 8 bits in the first segment, it does not even apply to the segment, segment 2 has no prefix because the address prefix extends beyond bits 9 to 16 which lie in the second segment, it does not apply to that segment either, segment 3 has the prefix 4 because the address prefix 20 corresponds to the first 4 bits in the 3rd segment, which means that the first 4 bits are part of the network section of the address or segment, and segment 4 has the prefix 0 because not a single bit is in the network section of the address or segment The prefix applied across the address is null ... null ... (1 to segment bit length) ... 0 ... 0 If the segment has no prefix then null is returned.
        Returns:
      • matchesWithPrefix

        public boolean matchesWithPrefix(long value,
                                         java.lang.Integer divisionPrefixLen)
      • getMaskPrefixLength

        public java.lang.Integer getMaskPrefixLength(boolean network)
        If this is equivalent to the mask for a CIDR prefix, it returns that prefix length. Otherwise, it returns null. A CIDR network mask is an address with all 1s in the network section (the upper bits) and then all 0s in the host section. A CIDR host mask is an address with all 0s in the network section (the lower bits) and then all 1s in the host section. The prefix length 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 portion 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 of an address with that prefix length. Therefore the two values can be different values, or one can be null while the other is not. This method applies only to the lower value of the range if this segment represents multiple values.
        Parameters:
        network - whether to check for a network mask or a host mask
        Returns:
        the prefix length corresponding to this mask, or null if this address is not a CIDR prefix mask
        See Also:
        IPAddressSection.getEquivalentPrefix()
      • isSamePrefixedRange

        public boolean isSamePrefixedRange(long lowerValue)
        Parameters:
        lowerValue -
        Returns:
        whether the range of this segment matches the range of a segment with the given value and the CIDR prefix length of this segment
      • isRangeEquivalent

        public boolean isRangeEquivalent(java.lang.Integer divisionPrefixLen)
        Parameters:
        divisionPrefixLen -
        Returns:
        whether the range of this segment can be specified only using the segment's lower value and the given prefix length If the prefix is null or equal to the bit length, then this returns true for non-multiple addresses.
      • isRangeUnchanged

        public boolean isRangeUnchanged(java.lang.Integer divisionPrefixLen)
        Parameters:
        divisionPrefixLen -
        Returns:
        whether the given range remains the same with the given prefix applied
      • isRangeEquivalentToPrefix

        public boolean isRangeEquivalentToPrefix()
        Returns:
        whether the range of this segment can be specified only using the segment's lower value and the segment's prefix length
      • isBitwiseOrCompatibleWithRange

        public boolean isBitwiseOrCompatibleWithRange(long maskValue,
                                                      java.lang.Integer divisionPrefixLen)
      • isMaskCompatibleWithRange

        public boolean isMaskCompatibleWithRange(long maskValue,
                                                 java.lang.Integer divisionPrefixLen)
      • getString

        public java.lang.String getString()
        Produces a normalized string to represent the segment. If the segment CIDR prefix length covers the range, then it is assumed to be a CIDR, and the string has only the lower value of the CIDR range. Otherwise, the explicit range will be printed.
        Overrides:
        getString in class AddressDivisionBase
        Returns:
      • getWildcardString

        public java.lang.String getWildcardString()
        Produces a string to represent the segment, favouring wildcards and range characters over the network prefix to represent subnets. If it exists, the segment CIDR prefix is ignored and the explicit range is printed.
        Returns:
      • getConfiguredString

        public int getConfiguredString(int segmentIndex,
                                       AddressSegmentParams params,
                                       java.lang.StringBuilder appendable)
        Produces a string to represent the segment.

        Use this instead of #getString(Wildcards, int, String, int, boolean, boolean, char, boolean, StringBuilder) if you wish to avoid printing wildcards in the host section of the address. Instead, this method will rely on the prefix length instead.

        Use this instead of getString() if you have a customized wildcard or range separator or you have a non-zero leadingZeroCount, or you have a string prefix, or you have a non-default radix (for IPv4 default radix is 10, for IPv6 it is 16)

        Specified by:
        getConfiguredString in interface AddressStringDivision
        Overrides:
        getConfiguredString in class AddressDivisionBase
        Returns:
        if the supplied appendable is null, returns the length of the string that would have been appended, otherwise returns 0