Module inet.ipaddr
Package inet.ipaddr

Class IPAddressSegment

    • Method Detail

      • getNetwork

        public abstract IPAddressNetwork<?,​?,​?,​?,​?> getNetwork()
        Description copied from interface: AddressComponent
        Returns the network object for components of the same version (eg IPv4, IPv6 and MAC each have their own network object)
        Specified by:
        getNetwork in interface AddressComponent
        Returns:
      • isIPv4

        public boolean isIPv4()
      • isIPv6

        public boolean isIPv6()
      • 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
      • 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()

      • prefixBlockSpliterator

        public abstract AddressComponentSpliterator<? extends IPAddressSegment> prefixBlockSpliterator()
        Partitions and traverses through the individual prefix blocks of this segment for its prefix length.
        Returns:
      • prefixBlockStream

        public abstract java.util.stream.Stream<? extends IPAddressSegment> prefixBlockStream()
        Returns a sequential stream of the individual prefix blocks of this segment. For a parallel stream, call BaseStream.parallel() on the returned stream.
        Returns:
      • prefixIterator

        public abstract java.util.Iterator<? extends IPAddressSegment> prefixIterator()
        Iterates through the individual prefixes.

        If the series has no prefix length, then this is equivalent to iterator()

      • prefixSpliterator

        public abstract AddressComponentSpliterator<? extends IPAddressSegment> prefixSpliterator()
        Partitions and traverses through the individual prefixes of this segment for its prefix length.
        Returns:
      • prefixStream

        public abstract java.util.stream.Stream<? extends IPAddressSegment> prefixStream()
        Returns a sequential stream of the individual prefixes of this segment. For a parallel stream, call BaseStream.parallel() on the returned stream.
        Returns:
      • prefixBlockIterator

        public abstract java.util.Iterator<? extends IPAddressSegment> prefixBlockIterator​(int prefixLength)
        Iterates through the individual prefix blocks according to the given segment prefix length. Any existing prefix length is disregarded.
      • prefixBlockSpliterator

        public abstract AddressComponentSpliterator<? extends IPAddressSegment> prefixBlockSpliterator​(int prefixLength)
        Partitions and traverses through the individual prefix blocks for the given prefix length.
        Returns:
      • prefixBlockStream

        public abstract java.util.stream.Stream<? extends IPAddressSegment> prefixBlockStream​(int prefixLength)
        Returns a sequential stream of the individual prefix blocks for the given prefix length. For a parallel stream, call BaseStream.parallel() on the returned stream.
        Returns:
      • 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
      • getValueCount

        public int getValueCount()
        Description copied from interface: AddressSegment
        Returns the count of values in this address segment.
        Specified by:
        getValueCount in interface AddressSegment
        Returns:
        the same value as getCount() as an integer
      • 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:
      • 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. Note that an AddressDivisionSeries with no divisions or AddressSection with no segments has a single value of 0. 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.
        Specified by:
        getCount in interface AddressItem
        Returns:
      • getPrefixCount

        public java.math.BigInteger getPrefixCount​(int segmentPrefixLength)
        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.
        Specified by:
        getPrefixCount in interface AddressItem
        Returns:
      • getPrefixValueCount

        public int getPrefixValueCount​(int segmentPrefixLength)
        Description copied from interface: AddressSegment
        Returns the count of prefix values in this address segment for the given prefix bit count.
        Specified by:
        getPrefixValueCount in interface AddressSegment
        Returns:
        the count of values
      • 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:
      • toZeroHost

        public abstract IPAddressSegment toZeroHost()
        Returns a segment with the same network bits as this segment, but with the host bits changed to 0.

        If there is no prefix length associated with this segment, returns an all-zero segment.

        This is nearly equivalent to doing the mask (see maskRange(int)) of this segment with the network mask for the given prefix length, but when applying a mask to a range of values you can have a non-sequential result.

        With this method, if the resulting series has a range of values, then the resulting series range boundaries will have host values of 0, but not necessarily all the intervening values.

        For instance, the 1-byte segment range 4-7 with prefix length 6, when masked with 252 (the network mask) results in just the single value 4, matching the result of this method. The 1-byte segment range 4-8 with prefix length 6, when masked with 252 results in the two non-sequential values, 4 and 8, but the result of this method with prefix length 6 results in the range 4-8, the same as the original segment.

        The default behaviour is that the resultant series will have the same prefix length. The resultant series will not have a prefix length if AddressNetwork.getPrefixConfiguration() is AddressNetwork.PrefixConfiguration.ALL_PREFIXED_ADDRESSES_ARE_SUBNETS.

        Returns:
      • withoutPrefixLength

        public abstract IPAddressSegment withoutPrefixLength()
        Returns a segment with the same values but without a prefix length.
        Returns:
      • getSegmentPrefixLength

        public java.lang.Integer getSegmentPrefixLength()
      • prefixEquals

        public boolean prefixEquals​(AddressSegment other,
                                    int prefixLength)
        Description copied from interface: AddressSegment
        Returns whether the given prefix bits match the same bits of the given segment.
        Specified by:
        prefixEquals in interface AddressSegment
        Returns:
      • prefixContains

        public boolean prefixContains​(IPAddressSegment other)
        Using the prefix length of this segment, or the whole segment if it has no prefix length, returns whether the prefix bit value ranges contain the same bits of the given segment.
        Parameters:
        other -
        Returns:
      • prefixContains

        public boolean prefixContains​(IPAddressSegment other,
                                      int prefixLength)
        Returns whether the given prefix bit value ranges contain the same bits of the given segment.
        Parameters:
        other -
        prefixLength -
        Returns:
      • includesZero

        public boolean includesZero()
        Description copied from interface: AddressItem
        Returns whether this item includes the value of zero within its range
        Specified by:
        includesZero in interface AddressItem
        Overrides:
        includesZero in class AddressDivision
        Returns:
        whether this item includes the value of zero within its range
      • 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
        Specified by:
        includesMax in interface AddressItem
        Overrides:
        includesMax in class AddressDivision
        Returns:
        whether this item includes the maximum possible value within its range
      • 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