示例#1
0
 /// <summary>
 /// Return true if the bytes in each wrapper are equal.
 /// </summary>
 ///
 /// <param name="other">the object to compare to.</param>
 /// <returns>true if the two objects are equal.</returns>
 /// @draft ICU 3.2
 /// @provisional This API might change or be removed in a future release.
 public override bool Equals(Object other)
 {
     if ((Object)this == other)
     {
         return(true);
     }
     if (other == null)
     {
         return(false);
     }
     try {
         ByteArrayWrapper that = (ByteArrayWrapper)other;
         if (size != that.size)
         {
             return(false);
         }
         for (int i = 0; i < size; ++i)
         {
             if (bytes[i] != that.bytes[i])
             {
                 return(false);
             }
         }
         return(true);
     } catch (InvalidCastException e) {
     }
     return(false);
 }
示例#2
0
        /// <summary>
        /// Compare this object to another ByteArrayWrapper, which must not be null.
        /// </summary>
        ///
        /// <param name="other">the object to compare to.</param>
        /// <returns>a value <0, 0, or >0 as this compares less than, equal to, or
        /// greater than other.</returns>
        /// <exception cref="ClassCastException">if the other object is not a ByteArrayWrapper</exception>
        /// @draft ICU 3.2
        /// @provisional This API might change or be removed in a future release.
        public virtual int CompareTo(Object other)
        {
            if ((Object)this == other)
            {
                return(0);
            }
            ByteArrayWrapper that = (ByteArrayWrapper)other;
            int minSize           = (size < that.size) ? size : that.size;

            for (int i = 0; i < minSize; ++i)
            {
                if (bytes[i] != that.bytes[i])
                {
                    return((bytes[i] & 0xFF) - (that.bytes[i] & 0xFF));
                }
            }
            return(size - that.size);
        }