inet.ipaddr

Class Address

  • java.lang.Object
    • inet.ipaddr.Address
    • Field Detail

      • RANGE_SEPARATOR_STR

        public static final java.lang.String RANGE_SEPARATOR_STR
      • ALTERNATIVE_RANGE_SEPARATOR

        public static final char ALTERNATIVE_RANGE_SEPARATOR
        See Also:
        Constant Field Values
      • ALTERNATIVE_RANGE_SEPARATOR_STR

        public static final java.lang.String ALTERNATIVE_RANGE_SEPARATOR_STR
      • SEGMENT_WILDCARD_STR

        public static final java.lang.String SEGMENT_WILDCARD_STR
      • ALTERNATIVE_SEGMENT_WILDCARD_STR

        public static final java.lang.String ALTERNATIVE_SEGMENT_WILDCARD_STR
        See Also:
        Constant Field Values
      • SEGMENT_SQL_WILDCARD_STR

        public static final java.lang.String SEGMENT_SQL_WILDCARD_STR
      • SEGMENT_SQL_SINGLE_WILDCARD

        public static final char SEGMENT_SQL_SINGLE_WILDCARD
        See Also:
        Constant Field Values
      • SEGMENT_SQL_SINGLE_WILDCARD_STR

        public static final java.lang.String SEGMENT_SQL_SINGLE_WILDCARD_STR
      • DEFAULT_ADDRESS_COMPARATOR

        public static final AddressComparator DEFAULT_ADDRESS_COMPARATOR
    • Method Detail

      • getBitCount

        public int getBitCount()
        Specified by:
        getBitCount in interface AddressItem
        Returns:
        the number of bits comprising this address item
      • getByteCount

        public int getByteCount()
        Description copied from interface: AddressComponent
        returns the number of bytes in each of the address components represented by this instance
        Specified by:
        getByteCount in interface AddressComponent
        Returns:
      • getSegments

        public void getSegments(int start,
                                int end,
                                AddressSegment[] segs,
                                int index)
        Description copied from interface: AddressSegmentSeries
        get the segments from start to end and insert into the segs array at the 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
        index - where to insert the segments in the segs array
      • getMaxSegmentValue

        public abstract int getMaxSegmentValue()
        Returns:
        the maximum possible segment value for this type of address. Note this is not the maximum value of the segments in this specific address.
      • increment

        public abstract Address increment(long increment)
        Description copied from interface: AddressSegmentSeries
        Returns the series from the subnet that is the given increment upwards into the subnet range, or if the given increment is negative the given increment downwards into the subnet range, or if this is just an individual series, it simply adds the increment to this. If the increment is 0, then this series is returned.

        If the subnet has multiple values and the increment exceeds the subnet size, then the amount by which is exceeds the size is added to the upper series of the range (the final iterator value) or is subtracted from the lower series of the range (the first iterator value) if negative.

        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 iterator. For instance, a increment of 1 is value 1 from the iterator, an increment of 2 is the second value from the iterator, and so on. A negative increment is equivalent to the same number of values preceding the upper bound of the iterator. For instance, an increment of -1 is the last value from the iterator, and increment of -2 is the second last value, and so on.

        Therefore, to get the series just above the highest series of the subnet, use an increment of size:count > 1 ? count + 1 : 1 where count is the subnet size. To get the series just below the lowest series of the subnet, use an increment of size:-(count > 1 ? count + 1 : 1) where count is the subnet size.

        Specified by:
        increment in interface AddressSegmentSeries
        Returns:
      • getLower

        public abstract Address getLower()
        Description copied from interface: AddressSegmentSeries
        If this represents a series with ranging values, returns a series representing the lower values of the range. If this represents an series with a single value in each segment, returns this.
        Specified by:
        getLower in interface AddressComponent
        Specified by:
        getLower in interface AddressSegmentSeries
        Returns:
      • getUpper

        public abstract Address getUpper()
        Description copied from interface: AddressSegmentSeries
        If this represents a series with ranging values, returns a series representing the upper values of the range If this represents a series with a single value in each segment, returns this.
        Specified by:
        getUpper in interface AddressComponent
        Specified by:
        getUpper in interface AddressSegmentSeries
        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
        Returns:
        whether this address represents more than one address. Such addresses include CIDR/IP addresses (eg 1.2.3.4/11) or wildcard addresses (eg 1.2.*.4) or range addresses (eg 1.2.3-4.5)
      • getPrefixLength

        public java.lang.Integer getPrefixLength()
        the largest number of high bits for which this address represents all addresses with the same set of high bits
        Specified by:
        getPrefixLength in interface AddressDivisionSeries
      • getMinPrefixLengthForBlock

        public int getMinPrefixLengthForBlock()
        Returns the smallest prefix length possible such that this includes the block of addresses for that prefix.

        If the entire range can be dictated this way, then this method returns the same value as getPrefixLengthForSingleBlock(). Otherwise, this method will return the minimal possible prefix that can be paired with this address, while getPrefixLengthForSingleBlock() will return null.

        In cases where the final bit in this address division series is constant, this returns the bit length of this address division series.

        Specified by:
        getMinPrefixLengthForBlock in interface AddressDivisionSeries
        Returns:
        the prefix length
      • getPrefixLengthForSingleBlock

        public java.lang.Integer getPrefixLengthForSingleBlock()
        Returns a prefix length for which the range of this address subnet matches the the block of addresses for that prefix.

        If the range can be dictated this way, then this method returns the same value as getMinPrefixLengthForBlock().

        If no such prefix exists, returns null.

        If this segment grouping represents a single value, returns the bit length of this address division series.

        IP address examples: 1.2.3.4 returns 32 1.2.*.* returns 16 1.2.*.0/24 returns 16 in the case of PrefixConfiguration == ALL_PREFIXES_ARE_SUBNETS, 32 otherwise 1.2.*.4 returns null 1.2.252-255.* returns 22 1.2.3.4/x returns x in the case of PrefixConfiguration == ALL_PREFIXES_ARE_SUBNETS, 32 otherwise 1.2.0.0/16 returns 16 in the case of PrefixConfiguration == ALL_PREFIXES_ARE_SUBNETS or PREFIXED_ZERO_HOSTS_ARE_SUBNETS, 32 otherwise

        Specified by:
        getPrefixLengthForSingleBlock in interface AddressDivisionSeries
        Returns:
        the prefix length or null if it does not exist
      • isMulticast

        public abstract boolean isMulticast()
        Whether the MAC address or IP address or other form of address is multicast.
        See Also:
        InetAddress.isMulticastAddress()
      • getCount

        public java.math.BigInteger getCount()
        Gets the count of addresses that this address may represent. If this address is not a subnet block of multiple addresses or has no range of values, then there is only one such address.
        Specified by:
        getCount in interface AddressItem
        Returns:
      • getPrefixCount

        public java.math.BigInteger getPrefixCount()
        If this has a prefix length, the count of the range of values in the prefix. If this has no prefix, returns the same value as getCount()
        Specified by:
        getPrefixCount in interface AddressDivisionSeries
        Returns:
      • isMore

        public int isMore(AddressDivisionSeries other)
        Description copied from interface: AddressDivisionSeries
        Use this method to compare the counts of two address series. Rather than calculating counts with getCount(), there can be more efficient ways of comparing whether one series represents more individual address series than another.
        Specified by:
        isMore in interface AddressDivisionSeries
        Returns:
        a positive integer if this AddressDivisionSeries has a larger count than the provided, 0 if they are the same, a negative integer if the other has a larger count.
      • getBytes

        public byte[] getBytes()
        Specified by:
        getBytes in interface AddressItem
        Returns:
        the bytes of the smallest address item represented by this address item
      • getBytes

        public byte[] getBytes(byte[] bytes)
        Description copied from interface: AddressItem
        Copies the bytes of the smallest address item represented by this address item into the supplied array, and returns that array. If the supplied array is null or of insufficient size, a new array is created and returned.
        Specified by:
        getBytes in interface AddressItem
        Returns:
        the bytes of the smallest address represented by this address item.
      • getUpperBytes

        public byte[] getUpperBytes()
        Gets the bytes for the highest address in the range of addresses represented by this address instance.
        Specified by:
        getUpperBytes in interface AddressItem
        Returns:
      • getUpperBytes

        public byte[] getUpperBytes(byte[] bytes)
        Description copied from interface: AddressItem
        Copies the bytes of the largest address item represented by this address item into the supplied array, and returns that array. If the supplied array is null or of insufficient size, a new array is created and returned.
        Specified by:
        getUpperBytes in interface AddressItem
        Returns:
        the bytes of the largest address represented by this address item.
      • getValue

        public java.math.BigInteger getValue()
        Specified by:
        getValue in interface AddressDivisionSeries
        Returns:
        the value of the lowest address item represented by this address division series
      • getUpperValue

        public java.math.BigInteger getUpperValue()
        Specified by:
        getUpperValue in interface AddressDivisionSeries
        Returns:
        the value of the highest address item represented by this address division series
      • isZero

        public boolean isZero()
        Specified by:
        isZero in interface AddressItem
        Returns:
        whether this item matches the value of zero
      • includesZero

        public boolean includesZero()
        Specified by:
        includesZero in interface AddressItem
        Returns:
        whether this item includes the value of zero within its range
      • isMax

        public boolean isMax()
        Specified by:
        isMax in interface AddressItem
        Returns:
        whether this item matches the maximum possible value
      • includesMax

        public boolean includesMax()
        Specified by:
        includesMax in interface AddressItem
        Returns:
        whether this item includes the maximum possible value within its range
      • isFullRange

        public boolean isFullRange()
        Specified by:
        isFullRange in interface AddressItem
        Returns:
        whether this address item represents all possible values attainable by an address item of this type, or in other words, both includesZero() and includesMax() return true
      • isLocal

        public abstract boolean isLocal()
        Whether the address can be considered a local address (as opposed to a global one)
        Returns:
      • hashCode

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

        public int compareTo(Address other)
        Specified by:
        compareTo in interface java.lang.Comparable<Address>
      • isSameAddress

        public boolean isSameAddress(Address other)
      • equals

        public boolean equals(java.lang.Object o)
        Two Address objects are equal if they represent the same set of addresses.
        Overrides:
        equals in class java.lang.Object
      • contains

        public abstract boolean contains(Address other)
      • toAddressString

        public HostIdentifierString toAddressString()
        Returns a host identifier string representation for this address, which will be already validated.
        Returns:
      • toHexString

        public java.lang.String toHexString(boolean with0xPrefix)
        Writes this address 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()
        The normalized string returned by this method is a common and consistent representation of the address. The string returned by this method is unique for each address.
        Specified by:
        toNormalizedString in interface AddressComponent
        Returns:
      • toCanonicalString

        public java.lang.String toCanonicalString()
        This produces a canonical string. RFC 5952 describes canonical representations for Ipv6 http://en.wikipedia.org/wiki/IPv6_address#Recommended_representation_as_text http://tools.ietf.org/html/rfc5952 Each address has a unique canonical string, not counting the prefix, which can give two equal addresses different strings.
        Specified by:
        toCanonicalString in interface AddressSegmentSeries
        Returns:
      • toCompressedString

        public java.lang.String toCompressedString()
        Produce short strings for the address in the usual address format. Each address has a unique compressed string.
        Specified by:
        toCompressedString in interface AddressSegmentSeries
        Returns:
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • 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:
      • reverseBits

        public abstract Address reverseBits(boolean perByte)
        Description copied from interface: AddressSegmentSeries
        Returns a new segment series with the bits reversed.
        Specified by:
        reverseBits in interface AddressComponent
        Specified by:
        reverseBits in interface AddressSegmentSeries
        Parameters:
        perByte - if true, only the bits in each byte are reversed, if false, then all bits in the component are reversed
        Returns:
      • isPrefixBlock

        public boolean isPrefixBlock()
        Returns whether the address range has a prefix length and includes the block of values for its prefix length.
        Specified by:
        isPrefixBlock in interface AddressDivisionSeries
        Returns:
      • isSinglePrefixBlock

        public boolean isSinglePrefixBlock()
        Returns whether the address range the block of values for a single prefix identified by its prefix length. This is similar to isPrefixBlock() except that it returns false when the subnet has multiple prefixes. For instance, 1.*.*.* /16 return false for this method and returns true for isPrefixBlock()
        Specified by:
        isSinglePrefixBlock in interface AddressDivisionSeries
        Returns:
      • toPrefixBlock

        public abstract Address toPrefixBlock()
        Description copied from interface: AddressSegmentSeries
        If this series has a prefix length, returns the block for that prefix. Otherwise, this address series is returned.
        Specified by:
        toPrefixBlock in interface AddressSegmentSeries
        Returns:
        the block of address series for the prefix length
      • adjustPrefixBySegment

        public abstract Address adjustPrefixBySegment(boolean nextSegment)
        Description copied from interface: AddressSegmentSeries
        Increases or decreases prefix length to the next segment boundary.

        Follows the same rules as AddressSegmentSeries.adjustPrefixLength(int):
        When prefix length is increased, the bits moved within the prefix become zero. When a prefix length is decreased, the bits moved outside the prefix become zero.

        Specified by:
        adjustPrefixBySegment in interface AddressSegmentSeries
        Parameters:
        nextSegment - whether to move prefix to previous or following segment coundary
        Returns:
      • adjustPrefixBySegment

        public abstract Address 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 AddressSegmentSeries
        Parameters:
        nextSegment - whether to move prefix to previous or following segment coundary
        zeroed - whether the bits that move from one side of the prefix to the other become zero or retain their original values
        Returns:
      • adjustPrefixLength

        public abstract Address adjustPrefixLength(int adjustment)
        Description copied from interface: AddressSegmentSeries
        Increases or decreases prefix length by the given increment.

        When prefix length is increased, the bits moved within the prefix become zero. When the prefix is extended beyond the segment series boundary, it is removed. When a prefix length is decreased, the bits moved outside the prefix become zero.

        Specified by:
        adjustPrefixLength in interface AddressSegmentSeries
        Returns:
      • adjustPrefixLength

        public abstract Address adjustPrefixLength(int adjustment,
                                                   boolean zeroed)
        Description copied from interface: AddressSegmentSeries
        Increases or decreases prefix length by the given increment.
        Specified by:
        adjustPrefixLength in interface AddressSegmentSeries
        Parameters:
        adjustment - the increment
        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 abstract Address 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.

        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 AddressSegmentSeries
        Returns:
        See Also:
        AddressSegmentSeries.applyPrefixLength(int)
      • setPrefixLength

        public abstract Address 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 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: