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
    • Constructor Detail

      • Address

        public Address(AddressSection section)
        Constructs an address.
        Parameters:
        section - the address segments
    • Method Detail

      • getBitCount

        public int getBitCount()
        Specified by:
        getBitCount in interface AddressItem
        Returns:
        the number of bits in this 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:
      • 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.
      • iterator

        public abstract java.util.Iterator<? extends Address> 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 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)
      • isPrefixed

        public boolean isPrefixed()
        Description copied from interface: AddressDivisionSeries
        Whether there exists a prefix.
        Specified by:
        isPrefixed in interface AddressDivisionSeries
        Returns:
        whether this address represents a network prefix or the set of all addresses with the same network prefix
      • 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
      • getMinPrefix

        public int getMinPrefix()
        Description copied from interface: AddressDivisionSeries
        Returns the smallest prefix length possible such that this address paired with that prefix length represents the exact same range of addresses. If no such prefix exists, returns the bit length.
        Specified by:
        getMinPrefix in interface AddressDivisionSeries
        Returns:
        the prefix length
      • getEquivalentPrefix

        public java.lang.Integer getEquivalentPrefix()
        Returns a prefix length for which the range of this address can be specified only using the address lower value and the prefix length If no such prefix exists, returns null. IP address examples: 1.2.3.4 returns 32 1.2.*.* returns 16 1.2.*.0/24 returns 16 1.2.*.4 returns null 1.2.252-255.* returns 22 1.2.3.4/x returns x
        Specified by:
        getEquivalentPrefix in interface AddressDivisionSeries
        Returns:
        the prefix length or null if it does not exist
      • isMulticast

        public abstract boolean isMulticast()
        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 CIDR network prefix and it has no range, then there is only one such address.
        Specified by:
        getCount in interface AddressItem
        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:
        > 0 if this AddressDivisionSeries has a larger count than the provided, 0 if they are the same, < 0 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 represented by this address.
        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.
      • isZero

        public boolean isZero()
        Specified by:
        isZero in interface AddressItem
        Returns:
        whether this item has the value of zero
      • 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.
      • isLocal

        public abstract boolean isLocal()
      • 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)
      • isRangeEquivalentToPrefix

        public boolean isRangeEquivalentToPrefix()
        Description copied from interface: AddressDivisionSeries
        whether there is a prefix and the range of values is dictated entirely by the prefix.
        Specified by:
        isRangeEquivalentToPrefix in interface AddressDivisionSeries
        Returns:
        whether this address represents more than one address and the set of addresses is determined entirely by the prefix length.
      • toAddressString

        public HostIdentifierString toAddressString()
        Returns a host identifier string representation for this address, which will be validated already.
        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
      • 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:
      • adjustPrefixBySegment

        public abstract Address adjustPrefixBySegment(boolean nextSegment)
        Description copied from interface: AddressSegmentSeries
        Increases or decreases prefix length to the next segment boundary. When prefix length is increased, the bits moved within the prefix are zero.
        Specified by:
        adjustPrefixBySegment in interface AddressSegmentSeries
        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.
        Specified by:
        adjustPrefixLength in interface AddressSegmentSeries
        Returns:
      • setPrefixLength

        public abstract Address setPrefixLength(int prefixLength)
        Description copied from interface: AddressSegmentSeries
        Sets the prefix length. When the series already had a prefix, and the prefix length is increased, the bits moved within the prefix are zero. When the prefix is extended beyond the segment series boundary, it is removed.
        Specified by:
        setPrefixLength in interface AddressSegmentSeries
        Returns:
      • applyPrefixLength

        public abstract Address applyPrefixLength(int networkPrefixLength)
        Description copied from interface: AddressSegmentSeries
        Applies the given prefix length to create a new segment series representing all segment series starting with the same prefix. When this series already has a prefix length that is smaller, then this method returns this series.
        Specified by:
        applyPrefixLength in interface AddressSegmentSeries