Class ProtocolVersion

  • All Implemented Interfaces:
    java.io.Serializable
    Direct Known Subclasses:
    HttpVersion

    @Contract(threading=IMMUTABLE)
    public class ProtocolVersion
    extends java.lang.Object
    implements java.io.Serializable
    Represents a protocol version. The "major.minor" numbering scheme is used to indicate versions of the protocol.

    This class defines a protocol version as a combination of protocol name, major version number, and minor version number. Note that equals(int, int) and hashCode() are defined as final here, they cannot be overridden in derived classes.

    Since:
    4.0
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int major
      Major version number of the protocol
      private int minor
      Minor version number of the protocol
      private java.lang.String protocol
      Name of the protocol.
      private static long serialVersionUID  
    • Constructor Summary

      Constructors 
      Constructor Description
      ProtocolVersion​(java.lang.String protocol, int major, int minor)
      Create a protocol version designator.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareToVersion​(ProtocolVersion that)
      Compares this protocol version with another one.
      boolean equals​(int major, int minor)
      Checks whether this instance has the same major and minor version as the arguments.
      boolean equals​(java.lang.Object obj)
      Checks equality of this protocol version with an object.
      java.lang.String format()
      Formats this protocol version as a string.
      int getMajor()
      Returns the major version number of the protocol.
      int getMinor()
      Returns the minor version number of the HTTP protocol.
      java.lang.String getProtocol()
      Returns the name of the protocol.
      boolean greaterEquals​(ProtocolVersion version)
      Tests if this protocol version is greater or equal to the given one.
      int hashCode()
      Obtains a hash code consistent with equals(int, int).
      boolean isComparable​(ProtocolVersion that)
      Checks whether this protocol can be compared to another one.
      boolean lessEquals​(ProtocolVersion version)
      Tests if this protocol version is less or equal to the given one.
      java.lang.String toString()
      Converts this protocol version to a string.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • protocol

        private final java.lang.String protocol
        Name of the protocol.
      • major

        private final int major
        Major version number of the protocol
      • minor

        private final int minor
        Minor version number of the protocol
    • Constructor Detail

      • ProtocolVersion

        public ProtocolVersion​(java.lang.String protocol,
                               int major,
                               int minor)
        Create a protocol version designator.
        Parameters:
        protocol - the name of the protocol, for example "HTTP"
        major - the major version number of the protocol
        minor - the minor version number of the protocol
    • Method Detail

      • getProtocol

        public final java.lang.String getProtocol()
        Returns the name of the protocol.
        Returns:
        the protocol name
      • getMajor

        public final int getMajor()
        Returns the major version number of the protocol.
        Returns:
        the major version number.
      • getMinor

        public final int getMinor()
        Returns the minor version number of the HTTP protocol.
        Returns:
        the minor version number.
      • hashCode

        public final int hashCode()
        Obtains a hash code consistent with equals(int, int).
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hashcode of this protocol version
      • equals

        public final boolean equals​(int major,
                                    int minor)
        Checks whether this instance has the same major and minor version as the arguments.
        Parameters:
        major - the major version to check.
        minor - the minor version to check.
        Returns:
        whether this instance has the same major and minor version as the arguments.
        Since:
        5.0
      • equals

        public final boolean equals​(java.lang.Object obj)
        Checks equality of this protocol version with an object. The object is equal if it is a protocol version with the same protocol name, major version number, and minor version number. The specific class of the object is not relevant, instances of derived classes with identical attributes are equal to instances of the base class and vice versa.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the object to compare with
        Returns:
        true if the argument is the same protocol version, false otherwise
      • format

        public java.lang.String format()
        Formats this protocol version as a string.
        Returns:
        a protocol version string, like "HTTP/1.1"
        Since:
        5.0
      • isComparable

        public boolean isComparable​(ProtocolVersion that)
        Checks whether this protocol can be compared to another one. Only protocol versions with the same protocol name can be compared.
        Parameters:
        that - the protocol version to consider
        Returns:
        true if compareToVersion can be called with the argument, false otherwise
      • compareToVersion

        public int compareToVersion​(ProtocolVersion that)
        Compares this protocol version with another one. Only protocol versions with the same protocol name can be compared. This method does not define a total ordering, as it would be required for Comparable.
        Parameters:
        that - the protocol version to compare with
        Returns:
        a negative integer, zero, or a positive integer as this version is less than, equal to, or greater than the argument version.
        Throws:
        java.lang.IllegalArgumentException - if the argument has a different protocol name than this object, or if the argument is null
      • greaterEquals

        public final boolean greaterEquals​(ProtocolVersion version)
        Tests if this protocol version is greater or equal to the given one.
        Parameters:
        version - the version against which to check this version
        Returns:
        true if this protocol version is comparable to the argument and compares as greater or equal, false otherwise
      • lessEquals

        public final boolean lessEquals​(ProtocolVersion version)
        Tests if this protocol version is less or equal to the given one.
        Parameters:
        version - the version against which to check this version
        Returns:
        true if this protocol version is comparable to the argument and compares as less or equal, false otherwise
      • toString

        public java.lang.String toString()
        Converts this protocol version to a string.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a protocol version string, like "HTTP/1.1"