Module inet.ipaddr

Class IPAddressDivision

All Implemented Interfaces:
AddressGenericDivision, AddressItem, IPAddressGenericDivision, AddressStringDivision, IPAddressStringDivision, Serializable, Comparable<AddressItem>
Direct Known Subclasses:
IPAddressBitsDivision, IPAddressJoinedSegments, IPAddressSegment

public abstract class IPAddressDivision extends AddressDivision implements IPAddressGenericDivision
A division of an IP address. 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 can assume all possible values.
Author:
sfoley
See Also:
  • Method Details

    • isPrefixed

      public boolean isPrefixed()
      Specified by:
      isPrefixed in interface IPAddressGenericDivision
    • getDivisionPrefixLength

      public 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.
      Specified by:
      getDivisionPrefixLength in interface IPAddressStringDivision
      Returns:
    • matchesWithPrefixMask

      public boolean matchesWithPrefixMask(long value, Integer divisionPrefixLen)
    • getBlockMaskPrefixLength

      public Integer getBlockMaskPrefixLength(boolean network)
      If this is equivalent to the mask for a CIDR prefix length block or subnet class, it returns the 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 there is no such prefix length
      See Also:
    • 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 segment 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 segment represents multiple values.

      Parameters:
      network -
      Returns:
    • containsPrefixBlock

      public boolean containsPrefixBlock(int divisionPrefixLen)
      Description copied from interface: AddressItem
      Returns whether the values of this series contains the prefix block for the given prefix length.

      Use AddressItem.getMinPrefixLengthForBlock() to determine the smallest prefix length for which this method returns true.

      Specified by:
      containsPrefixBlock in interface AddressItem
      Parameters:
      divisionPrefixLen -
      Returns:
      whether the division range includes the block of values for the given prefix length
    • isPrefixBlock

      public boolean isPrefixBlock()
      Description copied from interface: IPAddressStringDivision
      Returns whether the division range includes the block of values for its prefix length
      Specified by:
      isPrefixBlock in interface IPAddressStringDivision
      Returns:
      whether the division range includes the block of values for the division prefix length, or false if the division has no prefix length
    • containsSinglePrefixBlock

      public boolean containsSinglePrefixBlock(int divisionPrefixLen)
      Returns whether the division range matches exactly the block of values for the given prefix length.
      Specified by:
      containsSinglePrefixBlock in interface AddressItem
      Parameters:
      divisionPrefixLen -
      Returns:
      whether the range of this division matches the range for a single prefix with a single value and the given prefix length.
    • isSinglePrefixBlock

      public boolean isSinglePrefixBlock()
      Description copied from interface: IPAddressStringDivision
      Returns whether the division range matches the block of values for its prefix length
      Specified by:
      isSinglePrefixBlock in interface IPAddressStringDivision
      Returns:
      whether the division range matches exactly the block of values for its prefix length.
    • getString

      public 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.
      Returns:
    • getWildcardString

      public 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:
    • getPrefixAdjustedRangeString

      public int getPrefixAdjustedRangeString(int segmentIndex, AddressSegmentParams params, StringBuilder appendable)
      Description copied from interface: IPAddressStringDivision
      Produces a string to represent the segment of the form a-b where the value b has been adjusted for the prefix, anything beyond the prefix length being zero.
      Specified by:
      getPrefixAdjustedRangeString in interface IPAddressStringDivision
      Returns:
      if the supplied appendable is null, returns the length of the string that would have been appended, otherwise returns 0