compareTo method

  1. @override
int compareTo(
  1. Blob other
)
override

Compares this object to another object.

Returns a value like a Comparator when comparing this to other. That is, it returns a negative integer if this is ordered before other, a positive integer if this is ordered after other, and zero if this and other are ordered together.

The other argument must be a value that is comparable to this object.

Implementation

@override
int compareTo(Blob other) {
  // Blobs sort by subtype first, a regular blob has the subtype 0.
  if (subtype != other.subtype) {
    return subtype.compareTo(other.subtype);
  }

  final int size = min(_bytes.length, other._bytes.length);

  for (int i = 0; i < size; i++) {
    // Make sure the bytes are unsigned
    final int thisByte = _bytes[i] & 0xff;
    final int otherByte = other._bytes[i] & 0xff;
    if (thisByte < otherByte) {
      return -1;
    } else if (thisByte > otherByte) {
      return 1;
    }
    // Byte values are equal, continue with comparison
  }

  return _bytes.length.compareTo(other._bytes.length);
}