/// <summary>Compares this protocol version with another one.</summary> /// <remarks> /// Compares this protocol version with another one. /// Only protocol versions with the same protocol name can be compared. /// This method does <i>not</i> define a total ordering, as it would be /// required for /// <see cref="System.IComparable{T}">System.IComparable<T></see> /// . /// </remarks> /// <param name="that">the protocol version to compare with</param> /// <returns> /// a negative integer, zero, or a positive integer /// as this version is less than, equal to, or greater than /// the argument version. /// </returns> /// <exception cref="System.ArgumentException"> /// if the argument has a different protocol name than this object, /// or if the argument is <code>null</code> /// </exception> public virtual int CompareToVersion(Org.Apache.Http.ProtocolVersion that) { Args.NotNull(that, "Protocol version"); Args.Check(this.protocol.Equals(that.protocol), "Versions for different protocols cannot be compared: %s %s" , this, that); int delta = GetMajor() - that.GetMajor(); if (delta == 0) { delta = GetMinor() - that.GetMinor(); } return(delta); }
/// <summary>Checks equality of this protocol version with an object.</summary> /// <remarks> /// Checks equality of this protocol version with an object. /// The object is equal if it is a protocl version with the same /// protocol name, major version number, and minor version number. /// The specific class of the object is <i>not</i> relevant, /// instances of derived classes with identical attributes are /// equal to instances of the base class and vice versa. /// </remarks> /// <param name="obj">the object to compare with</param> /// <returns> /// <code>true</code> if the argument is the same protocol version, /// <code>false</code> otherwise /// </returns> public sealed override bool Equals(object obj) { if (this == obj) { return(true); } if (!(obj is Org.Apache.Http.ProtocolVersion)) { return(false); } Org.Apache.Http.ProtocolVersion that = (Org.Apache.Http.ProtocolVersion)obj; return((this.protocol.Equals(that.protocol)) && (this.major == that.major) && (this .minor == that.minor)); }
/// <summary>Tests if this protocol version is less or equal to the given one.</summary> /// <remarks>Tests if this protocol version is less or equal to the given one.</remarks> /// <param name="version">the version against which to check this version</param> /// <returns> /// <code>true</code> if this protocol version is /// <see cref="IsComparable(ProtocolVersion)">comparable</see> /// to the argument /// and /// <see cref="CompareToVersion(ProtocolVersion)">compares</see> /// as less or equal, /// <code>false</code> otherwise /// </returns> public bool LessEquals(Org.Apache.Http.ProtocolVersion version) { return(IsComparable(version) && (CompareToVersion(version) <= 0)); }
/// <summary>Checks whether this protocol can be compared to another one.</summary> /// <remarks> /// Checks whether this protocol can be compared to another one. /// Only protocol versions with the same protocol name can be /// <see cref="CompareToVersion(ProtocolVersion)">compared</see> /// . /// </remarks> /// <param name="that">the protocol version to consider</param> /// <returns> /// <code>true</code> if /// <see cref="CompareToVersion(ProtocolVersion)">compareToVersion</see> /// can be called with the argument, <code>false</code> otherwise /// </returns> public virtual bool IsComparable(Org.Apache.Http.ProtocolVersion that) { return((that != null) && this.protocol.Equals(that.protocol)); }