inet.ipaddr

Class IPAddressSegment

    • Method Detail

      • isIPv4

        public boolean isIPv4()
      • isIPv6

        public boolean isIPv6()
      • getMinPrefix

        public int getMinPrefix()
      • toMaskedSegment

        public abstract IPAddressSegment toMaskedSegment(IPAddressSegment maskSegment,
                                                         java.lang.Integer segmentPrefixLength)
                                                  throws AddressTypeException
        returns a new segment masked by the given mask This method applies the mask first to every address in the range, and it does not preserve any existing prefix. The given prefix will be applied to the range of addresses after the mask. If the combination of the two does not result in a contiguous range, then AddressTypeException is thrown. See IPAddress.applyPrefixLength(int), IPAddress#apply(IPAddress, Integer), IPAddress#isMaskCompatibleWithRange(IPAddress, Integer)
        Throws:
        AddressTypeException
      • isMaskCompatibleWithRange

        public boolean isMaskCompatibleWithRange(IPAddressSegment maskSegment,
                                                 java.lang.Integer segmentPrefixLength)
        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:
        maskSegment -
        segmentPrefixLength -
        Returns:
      • isMaskCompatibleWithRange

        public boolean isMaskCompatibleWithRange(int maskValue,
                                                 java.lang.Integer segmentPrefix)
      • 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
        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. This method iterates through the individual elements.
        Specified by:
        iterator in interface AddressComponent
        Specified by:
        iterator in interface AddressSegment
        Returns:
      • getDefaultTextualRadix

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

        public boolean matchesWithPrefix(int value,
                                         java.lang.Integer segmentPrefixLength)
      • 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 AddressTypeException. 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 AddressTypeException. 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
      • contains

        public boolean contains(AddressSegment other)
        Specified by:
        contains in interface AddressSegment
        Parameters:
        other -
        Returns:
        whether this subnet segment contains the given address segment
      • isFullRange

        public static boolean isFullRange(int lower,
                                          int upper,
                                          java.lang.Integer prefix,
                                          IPAddress.IPVersion version)
      • isFullRange

        public static boolean isFullRange(int lower,
                                          int upper,
                                          IPAddress.IPVersion version)
      • isFullRange

        public boolean isFullRange()
        Specified by:
        isFullRange in interface AddressItem
        Overrides:
        isFullRange in class AddressDivision
        Returns:
        whether this address item represents all possible values attainable by an address item of this type.
      • 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 section represents a range of values outside of the network prefix length, then this is printed as a range of two hex values.
        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: