Module inet.ipaddr

Class MACAddressSection

    • Field Detail

      • addressSegmentIndex

        public final int addressSegmentIndex
      • extended

        public final boolean extended
    • Constructor Detail

      • MACAddressSection

        public MACAddressSection​(MACAddressSegment segment)
        Constructs a single segment section, the segment being the leading segment.
        Parameters:
        segment -
      • MACAddressSection

        public MACAddressSection​(MACAddressSegment segment,
                                 int startIndex,
                                 boolean extended)
        Constructs a single segment section with the segment at the given index in the address.
        Parameters:
        segment -
      • MACAddressSection

        public MACAddressSection​(MACAddressSegment[] segments)
        Use this constructor for any address section that includes the leading segment of a MAC address
      • MACAddressSection

        public MACAddressSection​(MACAddressSegment[] segments,
                                 int startIndex,
                                 boolean extended)
      • MACAddressSection

        public MACAddressSection​(byte[] bytes,
                                 int startIndex,
                                 boolean extended)
      • MACAddressSection

        public MACAddressSection​(byte[] bytes)
      • MACAddressSection

        public MACAddressSection​(long value,
                                 int startIndex,
                                 boolean extended)
      • MACAddressSection

        public MACAddressSection​(long value)
    • Method Detail

      • equals

        public boolean equals​(java.lang.Object o)
        Description copied from class: AddressDivisionGroupingBase
        Two groupings are equal if: - they match type/version (ipv4, ipv6, mac, or a specific grouping class) - they match division counts - each division matches bit counts - each division matches their specific grouping class - each division matches values Prefix lengths, for those groupings and/or divisionsS that have them, are ignored.
        Overrides:
        equals in class AddressDivisionGrouping
      • getSegments

        public void getSegments​(int start,
                                int end,
                                AddressSegment[] segs,
                                int destIndex)
        Description copied from interface: AddressSegmentSeries
        get the segments from start to end and insert into the segs array at the given index
        Specified by:
        getSegments in interface AddressSegmentSeries
        Parameters:
        start - the first segment index from this series to be included
        end - the first segment index to be excluded
        segs - the target array
        destIndex - where to insert the segments in the segs array
      • isExtended

        public boolean isExtended()
        Returns:
        whether this section is part of a larger EUI-64 address.
      • isEntireAddress

        public boolean isEntireAddress​(boolean extended)
      • getSegments

        public void getSegments​(java.util.Collection<? super MACAddressSegment> segs)
      • getSegments

        public void getSegments​(int start,
                                int end,
                                java.util.Collection<? super MACAddressSegment> segs)
      • getMaxSegmentValue

        public int getMaxSegmentValue()
        Description copied from interface: AddressSegmentSeries
        Returns the maximum possible segment value for this type of address. Note this is not the maximum value of the range of segment values in this specific address, this is the maximum value of any segment for this address type, and is usually determined by the number of bits per segment.
        Specified by:
        getMaxSegmentValue in interface AddressSegmentSeries
        Returns:
        the maximum possible segment value for a series of the same type
      • getBitsPerSegment

        public int getBitsPerSegment()
        Description copied from interface: AddressSegmentSeries
        Returns the number of bits comprising each segment in this series. Segments in the same series are equal length.
        Specified by:
        getBitsPerSegment in interface AddressSegmentSeries
        Returns:
      • getBytesPerSegment

        public int getBytesPerSegment()
        Description copied from interface: AddressSegmentSeries
        Returns the number of bytes comprising each segment in this series. Segments in the same series are equal length.
        Specified by:
        getBytesPerSegment in interface AddressSegmentSeries
        Returns:
      • getByteCount

        public int getByteCount()
        Description copied from interface: AddressItem
        Provides the number of bytes required for this address item, rounding up if the bit count is not a multiple of 8
        Specified by:
        getByteCount in interface AddressItem
        Returns:
        the number of bytes
      • getBlockCount

        public java.math.BigInteger getBlockCount​(int segmentCount)
        Description copied from interface: AddressDivisionSeries
        Returns the count of values in the initial (higher) count of divisions.
        Specified by:
        getBlockCount in interface AddressDivisionSeries
        Returns:
      • getPrefixCount

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

        public int getOUISegmentCount()
      • getODISegmentCount

        public int getODISegmentCount()
      • getPrefixLength

        public java.lang.Integer getPrefixLength()
        Description copied from interface: AddressDivisionSeries
        The bit-length of the portion of the address that is not specific to an individual address but common amongst a group of addresses.

        Typically this is the largest number of bits in the upper-most portion of the section for which the remaining bits assume all possible values.

        For IP addresses, this must be explicitly defined when the address is created. For example, 1.2.0.0/16 has a prefix length of 16, while 1.2.*.* has no prefix length, even though they both represent the same set of addresses and are considered equal. Prefixes can be considered variable for any given IP addresses and can depend on the routing table.

        The methods AddressItem.getMinPrefixLengthForBlock() and AddressItem.getPrefixLengthForSingleBlock() can help you to obtain or define a prefix length if one does not exist already. 1.2.0.0/16 and 1.2.*.* both the same equivalent and minimum prefix length of 16.

        For MAC addresses, the prefix is initially defined by the range, so 1:2:3:*:*:* has a prefix length of 24 by definition. Addresses derived from the original may retain the original prefix length regardless of their range.

        Specified by:
        getPrefixLength in interface AddressDivisionSeries
        Overrides:
        getPrefixLength in class AddressDivisionGroupingBase
        Returns:
        the number of bits in the prefix. The prefix is the smallest bit length x for which all possible values with the same first x bits are included in this range of sections, unless that value x matches the bit count of this section, in which case the prefix is null. If the prefix is the OUI bit length (24) then the ODI segments cover all possibly values.
      • getSection

        public MACAddressSection getSection​(int index,
                                            int endIndex)
        Description copied from interface: AddressSegmentSeries
        Gets the subsection from the series starting from the given index and ending just before the give endIndex The first segment is at index 0.
        Specified by:
        getSection in interface AddressSegmentSeries
        Returns:
      • toOUIPrefixBlock

        public MACAddressSection toOUIPrefixBlock()
        Returns a section in which the range of values match the block for the OUI (organizationally unique identifier) bytes
        Returns:
      • toEUI64IPv6

        public IPv6AddressSection toEUI64IPv6()
        Converts to Ipv6. Any MAC prefix length is ignored. Other elements of this address section are incorporated into the conversion.
        Returns:
      • isEUI64

        public boolean isEUI64​(boolean asMAC)
        Equivalent to isEUI64(asMAC, false)
        Returns:
      • isEUI64

        public boolean isEUI64​(boolean asMAC,
                               boolean partial)
        Whether this section is consistent with an EUI64 section, which means it came from an extended 8 byte address, and the corresponding segments in the middle match 0xff and 0xff/fe for MAC/not-MAC
        Parameters:
        partial - whether missing segments are considered a match (this only has an effect if this section came from an extended 8 byte address), or in other words, we don't consider 6 byte addresses to be "missing" the bytes that would make it 8 byte.
        asMAC - whether to search for the ffff or fffe pattern
        Returns:
      • toEUI64

        public MACAddressSection toEUI64​(boolean asMAC)
        If this section is part of a shorter 48 bit MAC or EUI-48 address see isExtended(), then the required sections are inserted (FF-FF for MAC, FF-FE for EUI-48) to extend it to EUI-64. However, if the section does not encompass the parts of the address where the new sections should be placed, then the section is unchanged. If the section is already part of an EUI-64 address, then it is checked to see if it has the segments that identify it as extended to EUI-64 (FF-FF for MAC, FF-FE for EUI-48), and if not, IncompatibleAddressException is thrown.
        Parameters:
        asMAC -
        Returns:
      • replace

        public MACAddressSection replace​(int index,
                                         MACAddressSection replacement)
        Replace the segments of this section starting at the given index with the given replacement segments
        Parameters:
        index -
        replacement -
        Returns:
      • replace

        public MACAddressSection replace​(int startIndex,
                                         int endIndex,
                                         MACAddressSection replacement,
                                         int replacementStartIndex,
                                         int replacementEndIndex)
        Replaces segments starting from startIndex and ending before endIndex with the segments starting at replacementStartIndex and ending before replacementEndIndex from the replacement section
        Parameters:
        startIndex -
        endIndex -
        replacement -
        replacementStartIndex -
        replacementEndIndex -
        Returns:
        Throws:
        java.lang.IndexOutOfBoundsException
        AddressValueException - if the resulting section would exceed the maximum segment count for this address type and version
      • longValue

        public long longValue()
      • upperLongValue

        public long upperLongValue()
      • adjustPrefixBySegment

        public MACAddressSection adjustPrefixBySegment​(boolean nextSegment,
                                                       boolean zeroed)
        Description copied from interface: AddressSegmentSeries
        Increases or decreases prefix length to the next segment boundary.
        Specified by:
        adjustPrefixBySegment in interface AddressSection
        Specified by:
        adjustPrefixBySegment in interface AddressSegmentSeries
        Parameters:
        nextSegment - whether to move prefix to previous or following segment boundary
        zeroed - whether the bits that move from one side of the prefix to the other become zero or retain their original values
        Returns:
      • setPrefixLength

        public MACAddressSection setPrefixLength​(int prefixLength)
        Description copied from interface: AddressSegmentSeries
        Sets the prefix length.

        If this series has a prefix length, and the prefix length is increased, the bits moved within the prefix become zero. For an alternative that does not set bits to zero, use AddressSegmentSeries.setPrefixLength(int, boolean) with the second argument as false.

        When the prefix is extended beyond the segment series boundary, it is removed.

        The bits that move from one side of the prefix length to the other (ie bits moved into the prefix or outside the prefix) are zeroed.

        Specified by:
        setPrefixLength in interface AddressSection
        Specified by:
        setPrefixLength in interface AddressSegmentSeries
        Returns:
      • setPrefixLength

        public MACAddressSection setPrefixLength​(int prefixLength,
                                                 boolean zeroed)
        Description copied from interface: AddressSegmentSeries
        Sets the prefix length.

        When the prefix is extended beyond the segment series boundary, it is removed.

        Specified by:
        setPrefixLength in interface AddressSection
        Specified by:
        setPrefixLength in interface AddressSegmentSeries
        zeroed - whether the bits that move from one side of the prefix length to the other (ie bits moved into the prefix or outside the prefix) are zeroed.
        Returns:
      • increment

        public MACAddressSection increment​(long increment)
        Description copied from interface: AddressSegmentSeries
        Returns the series from the subnet that is the given increment upwards into the subnet range, with the increment of 0 returning the first address in the range.

        If the subnet has multiple values and the increment exceeds the subnet size, then the amount by which it exceeds the size - 1 is added to the upper series of the range (the final iterator value).

        If the increment is negative, it is added to the lower series of the range (the first iterator value).

        If the subnet is just a single address values, the series is simply incremented by the given value, positive or negative.

        If a subnet has multiple values, a positive increment value is equivalent to the same number of values from the AddressSegmentSeries.iterator() For instance, a increment of 0 is the first value from the iterator, an increment of 1 is the second value from the iterator, and so on. A negative increment added to the subnet count is equivalent to the same number of values preceding the upper bound of the iterator. For instance, an increment of count - 1 is the last value from the iterator, an increment of count - 2 is the second last value, and so on.

        An increment of size count gives you the series just above the highest series of the subnet. To get the series just below the lowest series of the subnet, use the increment -1.

        Specified by:
        increment in interface AddressSection
        Specified by:
        increment in interface AddressSegmentSeries
        Returns:
      • toNormalizedString

        public java.lang.String toNormalizedString()
        The normalized string returned by this method is the most common representation of MAC addresses: xx:xx:xx:xx:xx:xx
        Specified by:
        toNormalizedString in interface AddressComponent
        Returns:
      • toCanonicalString

        public java.lang.String toCanonicalString()
        This produces a canonical string using the canonical standardized IEEE 802 MAC address representation of xx-xx-xx-xx-xx-xx For range segments, '..' is used: 11-22-33..44-55-66
        Specified by:
        toCanonicalString in interface AddressSegmentSeries
        Returns:
      • toCompressedString

        public java.lang.String toCompressedString()
        This produces a shorter string for the address that uses the canonical representation but not using leading zeroes. Each address has a unique compressed string.
        Specified by:
        toCompressedString in interface AddressSegmentSeries
        Returns:
      • toSpaceDelimitedString

        public java.lang.String toSpaceDelimitedString()
        This produces a string delimited by spaces: aa bb cc dd ee ff
      • toDashedString

        public java.lang.String toDashedString()
      • toColonDelimitedString

        public java.lang.String toColonDelimitedString()
      • getSegmentStrings

        public java.lang.String[] getSegmentStrings()
        Description copied from interface: AddressSegmentSeries
        Returns the an array with the values of each segment as they would appear in the normalized with wildcards string.
        Specified by:
        getSegmentStrings in interface AddressSegmentSeries
        Returns:
      • overlaps

        public boolean overlaps​(AddressSection other)
        Description copied from interface: AddressSection
        Determines if one section overlaps another.

        Sections must have the same number of segments to be comparable.

        For sections which are aware of their position in an address (IPv6 and MAC), their respective positions must match to be comparable.

        Specified by:
        overlaps in interface AddressSection
        Returns:
        whether this section overlaps the given address section
      • overlaps

        public boolean overlaps​(MACAddressSection other)
        Parameters:
        other -
        Returns:
        whether this section contains the given address section
      • contains

        public boolean contains​(AddressSection other)
        Description copied from interface: AddressSection
        Determines if one section contains another.

        Sections must have the same number of segments to be comparable.

        For sections which are aware of their position in an address (IPv6 and MAC), their respective positions must match to be comparable.

        Specified by:
        contains in interface AddressSection
        Returns:
        whether this section contains the given address section
      • contains

        public boolean contains​(MACAddressSection other)
        Parameters:
        other -
        Returns:
        whether this section contains the given address section
      • enumerate

        public java.math.BigInteger enumerate​(AddressSection other)
        Description copied from interface: AddressSection
        Indicates where an address section sits relative to the ordering of individual address sections within this section.

        Determines how many address section elements precede the given address section element, if the given address section is within this address section. If above the range, it is the distance to the upper boundary added to the address section count less one, and if below the range, the distance to the lower boundary.

        In other words, if the given address section is not in this section but above it, returns the number of individual address sections preceding the given address section from the upper section boundary, added to one less than the total number of individual address sections within. If the given address section is not in this section but below it, returns the number of individual address sections following the given address section to the lower section boundary.

        enumerate returns null when the argument is a multi-valued section. The argument must be an individual address section.

        When this address section is also single-valued, the returned value is the distance (difference) between this address section and the argument address section.

        enumerate is the inverse of the increment method:

        • section.enumerate(section.increment(inc)) = inc
        • section.increment(section.enumerate(individualSection)) = individualSection
        If the given address section does not have the same version or type as this address section, then null is returned. If the given address section is the same version and type, but has a different segment count, then SizeMismatchException is thrown.
        Specified by:
        enumerate in interface AddressSection
      • prefixEquals

        public boolean prefixEquals​(AddressSection o)
        Description copied from interface: AddressSection
        Determines if the argument section matches this section up to the prefix length of this section.

        The entire prefix of this section must be present in the other section to be comparable.

        For sections which are aware of their position in an address (IPv6 and MAC), the argument section must have the same or an earlier position in the address to match all prefix segments of this section, and the matching is lined up relative to the position.

        Specified by:
        prefixEquals in interface AddressSection
        Returns:
        whether the argument section has the same address section prefix as this