inet.ipaddr

Class IPAddressSegment

    • Method Detail

      • isIPv4

        public boolean isIPv4()
      • isIPv6

        public boolean isIPv6()
      • getMinPrefixLengthForBlock

        public int getMinPrefixLengthForBlock()
      • 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
        Overrides:
        isPrefixBlock in class IPAddressDivision
        Returns:
        whether the division range includes the block of values for the division prefix length, or false if the division has no prefix length
      • isMaskCompatibleWithRange

        public boolean isMaskCompatibleWithRange(int maskValue,
                                                 java.lang.Integer segmentPrefixLength)
                                          throws PrefixLenException
        Check that the range resulting from the mask is contiguous, otherwise we cannot represent it. 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 segment range. Any host mask is fine.
        Parameters:
        maskValue -
        segmentPrefixLength -
        Returns:
        Throws:
        PrefixLenException
      • isBitwiseOrCompatibleWithRange

        public boolean isBitwiseOrCompatibleWithRange(int maskValue,
                                                      java.lang.Integer segmentPrefixLength)
                                               throws PrefixLenException
        Similar to masking, checks that the range resulting from the bitwise or is contiguous.
        Parameters:
        maskValue -
        segmentPrefixLength -
        Returns:
        Throws:
        PrefixLenException
      • getLower

        public abstract IPAddressSegment getLower()
        If this segment represents a range of values, returns a segment representing just the lowest value in the range, otherwise returns this.
        Specified by:
        getLower in interface AddressComponent
        Specified by:
        getLower in interface AddressSegment
        Returns:
      • getUpper

        public abstract IPAddressSegment getUpper()
        If this segment represents a range of values, returns a segment representing just the highest value in the range, otherwise returns this.
        Specified by:
        getUpper in interface AddressComponent
        Specified by:
        getUpper in interface AddressSegment
        Returns:
      • iterator

        public abstract java.util.Iterator<? extends IPAddressSegment> iterator()
        Description copied from interface: AddressComponent
        Iterates through the individual elements of this address component.

        An address component can represent a single segment, address, or section, or it can represent multiple, typically a subnet or range of segment, address, or section values.

        Call AddressItem.isMultiple() to determine if this instance represents multiple.

        Specified by:
        iterator in interface AddressComponent
        Specified by:
        iterator in interface AddressSegment
        Returns:
      • prefixBlockIterator

        public abstract java.util.Iterator<? extends IPAddressSegment> prefixBlockIterator()
        Iterates through the individual prefix blocks. If the series has no prefix length, then this is equivalent to iterator()
      • getDefaultTextualRadix

        public static int getDefaultTextualRadix(IPAddress.IPVersion version)
      • matchesWithPrefixMask

        public boolean matchesWithPrefixMask(int value,
                                             java.lang.Integer segmentPrefixLength)
      • matchesWithMask

        public boolean matchesWithMask(int lowerValue,
                                       int upperValue,
                                       int mask)
        Specified by:
        matchesWithMask in interface AddressSegment
      • getPrefixValueCount

        public int getPrefixValueCount()
        Counts the number of prefixes in this address segment.

        If this segment has no prefix length, this is equivalent to getValueCount()

        Returns:
      • 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)
        Specified by:
        isMultiple in interface AddressItem
        Overrides:
        isMultiple in class AddressDivision
        Returns:
        whether this segment represents multiple values
      • reverseBits

        public abstract IPAddressSegment reverseBits(boolean perByte)
        Description copied from interface: AddressComponent
        Returns a new AddressComponent with the bits reversed. If this component represents a range of values that cannot be reversed, then this throws IncompatibleAddressException. In a range the most significant bits stay constant while the least significant bits range over different values, so reversing that scenario results in a series of non-consecutive values, in most cases, which cannot be represented with a single AddressComponent object.

        In such cases where isMultiple() is true, call iterator(), getLower(), getUpper() or some other methods to break the series down into a series representing a single value.

        Specified by:
        reverseBits in interface AddressComponent
        Specified by:
        reverseBits in interface AddressSegment
        Parameters:
        perByte - if true, only the bits in each byte are reversed, if false, then all bits in the component are reversed
        Returns:
      • reverseBytes

        public abstract IPAddressSegment reverseBytes()
        Description copied from interface: AddressComponent
        Returns an AddressComponent with the bytes reversed. If this component represents a range of values that cannot be reversed, then this throws IncompatibleAddressException. In a range the most significant bits stay constant while the least significant bits range over different values, so reversing that scenario results in a series of non-consecutive values, in most cases, which cannot be represented with a single AddressComponent object.

        In such cases where isMultiple() is true, call iterator(), getLower(), getUpper() or some other methods to break the series down into a series representing a single value.

        Specified by:
        reverseBytes in interface AddressComponent
        Specified by:
        reverseBytes in interface AddressSegment
        Returns:
      • removePrefixLength

        public abstract IPAddressSegment removePrefixLength(boolean zeroed)
      • getSegmentPrefixLength

        public java.lang.Integer getSegmentPrefixLength()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toHexString

        public java.lang.String toHexString(boolean with0xPrefix)
        Description copied from interface: AddressComponent
        Writes this address component as a single hexadecimal value with always the exact same number of characters, with or without a preceding 0x prefix.

        If this component represents a range of values outside of the network prefix length, then this is printed as a range of two hex values.

        For instance, for IPv4 addresses there are 8 hex characters, for IPv6 addresses there are 32 hex characters.

        Specified by:
        toHexString in interface AddressComponent
      • toNormalizedString

        public java.lang.String toNormalizedString()
        Description copied from interface: AddressComponent
        Produces a string that is somewhat similar for all address components of the same type.
        Specified by:
        toNormalizedString in interface AddressComponent
        Returns: