Class IP

  • All Implemented Interfaces:
    java.io.Serializable, java.util.Comparator
    Direct Known Subclasses:
    IPaddress, Prefix

    public abstract class IP
    extends java.lang.Object
    implements java.util.Comparator, java.io.Serializable
    This class contains a number of constants used in the IPaddress and the Prefix classes.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int COMPRESSED
      Compressed IPv6 addresses have the longest set of 'empty' segments replaced with the double colon.
      static int DEFAULT_RADIX
      This is the radix that will be used, if one isn't explicitly specified.
      static int EXPANDED
      The expanded format has all segments present without leading zeroes.
      static int IPv4  
      static int IPv4_bits  
      static java.lang.String IPv4_normal_prefix
      Internally normalized form of IPv4_prefix.
      static java.lang.String IPv4_prefix
      The normalized IPv6 prefix that IPv4 addresses should reside in.
      static java.math.BigInteger IPv4_prefix_number
      Numeric value of IPv4_prefix.
      static java.lang.String IPv4_prefix_short
      Compressed form of IPv4_prefix.
      static java.lang.String IPv4_regex
      Non-capturing regular expression matching any valid IPv4 address.
      static int IPv6  
      static int IPv6_bits  
      static java.lang.String IPv6_regex
      Non-capturing regular expression matching any valid IPv6 address.
      static java.lang.String IPv6_regex_6hex_4dec
      Non-capturing regular expression matching an IPv6 address when all segments have one or more characters with the last segments represented as an IPv4 address.
      static java.lang.String IPv6_regex_6hex_4dec_compressed
      Non-capturing regular expression matching a compressed IPv6 address, and the last segments are represented as an IPv4 address.
      static java.lang.String IPv6_regex_compressed
      Non-capturing regular expression matching a compressed IPv6 address.
      static java.lang.String IPv6_regex_not_compressed
      Non-capturing regular expression matching an IPv6 address when all segments have one or more characters.
      static int IPv64
      The IP64 address is an IPv6 address with the last two segments represented as an IPv4 address.
      static int LOWER
      Display the IPv6 address in lower case.
      static int NORMALIZED
      A normalized address has all segments present, and has all leading zeroes in the address.
      static int PASSED
      Use the same format that the IPaddress or Prefix was created with.
      static int PREFERRED
      Name of the expanded format taken from RFC 4291 Section 2.2 Item 1.
      static int RADIX
      IP addresses can be converted to a number in an arbitrary radix.
      static java.lang.Boolean SUPPRESS_SORT_ERRORS
      Suppress the errors that would be thrown while sorting.
      static int UPPER
      Display the IPv6 address in upper case.
      static java.lang.String v4_set
      Non-capturing regular expression matching a number in the range 0-255.
      static java.lang.String v6_set
      Regular expression that matches one segment of an IPv6 address.
    • Constructor Summary

      Constructors 
      Constructor Description
      IP()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      static int cmp​(IP ip1, IP ip2)
      Compare ip1 to ip2.
      abstract int compare​(java.lang.Object ip1, java.lang.Object ip2)
      Compare ip1 to ip2.
      abstract int compareTo​(java.lang.Object ip)
      Compare the current IP to ip.
      boolean equals​(IP ip)
      Check if an IP is equal to the current IP.
      boolean gt​(IP ip)
      Check if an IP is greater than the current IP.
      boolean gte​(IP ip)
      Check if an IP is greater than or equal to the current IP.
      boolean lt​(IP ip)
      Check if an IP is less than the current IP.
      boolean lte​(IP ip)
      Check if an IP is less than or equal to the current IP.
      java.lang.String toCompressedString()
      Convenience method for toString (IP.COMPRESSED).
      java.lang.String toCompressedString​(int flags)
      Convenience method for toString (IP.COMPRESSED).
      java.lang.String toExpandedString()
      Convenience method for toString (IP.EXPANDED).
      java.lang.String toExpandedString​(int flags)
      Convenience method for toString (IP.EXPANDED).
      java.lang.String toIPv4String()
      Convenience method for toString (IP.IPv4).
      java.lang.String toIPv4String​(int flags)
      Convenience method for toString (IP.IPv4).
      java.lang.String toIPv6String()
      Convenience method for toString (IP.IPv6).
      java.lang.String toIPv6String​(int flags)
      Convenience method for toString (IP.IPv6).
      java.lang.String toNormalizedString()
      Convenience method for toString (IP.NORMALIZED).
      java.lang.String toNormalizedString​(int flags)
      Convenience method for toString (IP.NORMALIZED).
      java.lang.String toPassedString()
      Convenience method for toString (IP.PASSED).
      java.lang.String toPassedString​(int flags)
      Convenience method for toString (IP.PASSED).
      java.lang.String toPreferredString()
      Convenience method for toString (IP.PREFERRED).
      java.lang.String toPreferredString​(int flags)
      Convenience method for toString (IP.PREFERRED).
      abstract java.lang.String toString​(int flags)  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Field Detail

      • SUPPRESS_SORT_ERRORS

        public static java.lang.Boolean SUPPRESS_SORT_ERRORS
        Suppress the errors that would be thrown while sorting. This will effectively cause malformed addresses to be sorted to the end of whatever is being sorted.
      • IPv64

        public static final int IPv64
        The IP64 address is an IPv6 address with the last two segments represented as an IPv4 address.

        Example: 1:2::6:1.2.3.4

        See Also:
        Constant Field Values
      • PASSED

        public static final int PASSED
        Use the same format that the IPaddress or Prefix was created with.
        See Also:
        Constant Field Values
      • COMPRESSED

        public static final int COMPRESSED
        Compressed IPv6 addresses have the longest set of 'empty' segments replaced with the double colon. This flag has no effect with an IPv4 address.

        Example: 1:2:3::8

        See Also:
        Constant Field Values
      • NORMALIZED

        public static final int NORMALIZED
        A normalized address has all segments present, and has all leading zeroes in the address.

        Example: 001.002.003.004 or 0001:0002:0003:0000:0000:0006:0007:0008

        See Also:
        Constant Field Values
      • PREFERRED

        public static final int PREFERRED
        Name of the expanded format taken from RFC 4291 Section 2.2 Item 1.
        See Also:
        Constant Field Values
      • EXPANDED

        public static final int EXPANDED
        The expanded format has all segments present without leading zeroes. This flag has no effect with an IPv4 address.

        Example: 1:2:0:0:0:0:7:8

        See Also:
        Constant Field Values
      • LOWER

        public static final int LOWER
        Display the IPv6 address in lower case.
        See Also:
        Constant Field Values
      • UPPER

        public static final int UPPER
        Display the IPv6 address in upper case.
        See Also:
        Constant Field Values
      • RADIX

        public static final int RADIX
        IP addresses can be converted to a number in an arbitrary radix.
        See Also:
        Constant Field Values
      • DEFAULT_RADIX

        public static int DEFAULT_RADIX
        This is the radix that will be used, if one isn't explicitly specified.
      • IPv4_prefix

        public static final java.lang.String IPv4_prefix
        The normalized IPv6 prefix that IPv4 addresses should reside in.
        See Also:
        Constant Field Values
      • IPv4_prefix_short

        public static final java.lang.String IPv4_prefix_short
        Compressed form of IPv4_prefix.
        See Also:
        Constant Field Values
      • IPv4_normal_prefix

        public static final java.lang.String IPv4_normal_prefix
        Internally normalized form of IPv4_prefix.
      • IPv4_prefix_number

        public static final java.math.BigInteger IPv4_prefix_number
        Numeric value of IPv4_prefix.
      • v4_set

        public static final java.lang.String v4_set
        Non-capturing regular expression matching a number in the range 0-255.
        See Also:
        Constant Field Values
      • v6_set

        public static final java.lang.String v6_set
        Regular expression that matches one segment of an IPv6 address.
        See Also:
        Constant Field Values
      • IPv4_regex

        public static final java.lang.String IPv4_regex
        Non-capturing regular expression matching any valid IPv4 address.
        See Also:
        Constant Field Values
      • IPv6_regex_not_compressed

        public static final java.lang.String IPv6_regex_not_compressed
        Non-capturing regular expression matching an IPv6 address when all segments have one or more characters.
        See Also:
        Constant Field Values
      • IPv6_regex_6hex_4dec

        public static final java.lang.String IPv6_regex_6hex_4dec
        Non-capturing regular expression matching an IPv6 address when all segments have one or more characters with the last segments represented as an IPv4 address.
        See Also:
        Constant Field Values
      • IPv6_regex_compressed

        public static final java.lang.String IPv6_regex_compressed
        Non-capturing regular expression matching a compressed IPv6 address.
        See Also:
        Constant Field Values
      • IPv6_regex_6hex_4dec_compressed

        public static final java.lang.String IPv6_regex_6hex_4dec_compressed
        Non-capturing regular expression matching a compressed IPv6 address, and the last segments are represented as an IPv4 address.
        See Also:
        Constant Field Values
      • IPv6_regex

        public static final java.lang.String IPv6_regex
        Non-capturing regular expression matching any valid IPv6 address.
        See Also:
        Constant Field Values
    • Constructor Detail

      • IP

        public IP()
    • Method Detail

      • toString

        public abstract java.lang.String toString​(int flags)
        Parameters:
        flags - bit field of flags defined in the IP class. The following flags are understood:
        EXPANDED (or PREFERRED), NORMALIZED, COMPRESSED, PASSED, IPv4, IPv6, IPv64, LOWER, UPPER, RADIX

        Setting both the IPv4 and IPv6 flag will return an IPv6 address with the lower 32 bits displayed as an IPv4 address.

        Setting the IPv4 flag on an IPv6 address will return ONLY the lower 32 bits in an IPv4 format.

        The following precedences are used when processing flags:
        RADIX, PASSED, IPv4 and IPv6 (IPv4 and IPv6 have equal precedence)
        EXPANDED (or PREFERRED), NORMALIZED, COMPRESSED
        LOWER, UPPER

        See Also:
        EXPANDED, PREFERRED, NORMALIZED, COMPRESSED, PASSED, IPv4, IPv6, IPv64, LOWER, UPPER, RADIX
      • toCompressedString

        public java.lang.String toCompressedString()
        Convenience method for toString (IP.COMPRESSED).
      • toNormalizedString

        public java.lang.String toNormalizedString()
        Convenience method for toString (IP.NORMALIZED).
      • toExpandedString

        public java.lang.String toExpandedString()
        Convenience method for toString (IP.EXPANDED).
      • toPreferredString

        public java.lang.String toPreferredString()
        Convenience method for toString (IP.PREFERRED).
      • toPassedString

        public java.lang.String toPassedString()
        Convenience method for toString (IP.PASSED).
      • toIPv4String

        public java.lang.String toIPv4String()
        Convenience method for toString (IP.IPv4).
      • toIPv6String

        public java.lang.String toIPv6String()
        Convenience method for toString (IP.IPv6).
      • toCompressedString

        public java.lang.String toCompressedString​(int flags)
        Convenience method for toString (IP.COMPRESSED).
      • toNormalizedString

        public java.lang.String toNormalizedString​(int flags)
        Convenience method for toString (IP.NORMALIZED).
      • toPreferredString

        public java.lang.String toPreferredString​(int flags)
        Convenience method for toString (IP.PREFERRED).
      • toExpandedString

        public java.lang.String toExpandedString​(int flags)
        Convenience method for toString (IP.EXPANDED).
      • toPassedString

        public java.lang.String toPassedString​(int flags)
        Convenience method for toString (IP.PASSED).
      • toIPv4String

        public java.lang.String toIPv4String​(int flags)
        Convenience method for toString (IP.IPv4).
      • toIPv6String

        public java.lang.String toIPv6String​(int flags)
        Convenience method for toString (IP.IPv6).
      • lt

        public boolean lt​(IP ip)
        Check if an IP is less than the current IP.
        Returns:
        true if this < ip
      • lte

        public boolean lte​(IP ip)
        Check if an IP is less than or equal to the current IP.
        Returns:
        true if this <= ip
      • gt

        public boolean gt​(IP ip)
        Check if an IP is greater than the current IP.
        Returns:
        true if this > ip
      • gte

        public boolean gte​(IP ip)
        Check if an IP is greater than or equal to the current IP.
        Returns:
        true if this >= ip
      • equals

        public boolean equals​(IP ip)
        Check if an IP is equal to the current IP.
        Returns:
        true if this == ip
      • compare

        public abstract int compare​(java.lang.Object ip1,
                                    java.lang.Object ip2)
        Compare ip1 to ip2.
        Specified by:
        compare in interface java.util.Comparator
        See Also:
        compareTo(Object), SUPPRESS_SORT_ERRORS
      • compareTo

        public abstract int compareTo​(java.lang.Object ip)
        Compare the current IP to ip.
        Returns:
        -1 if this < ip
        1 if this > ip
        0 if this = ip
        See Also:
        SUPPRESS_SORT_ERRORS