I work on a class for measurements, so I would like to provide a nice API to compare two measurements.
In order to work with ordering in collection I implemented Comparator
. For a nice API I implemented as well comparing operators <
, <=
, =>
, >
, ==
.
So my class has the following methods:
bool operator <=(SELF other) => _value <= other._value;
bool operator <(SELF other) => _value < other._value;
bool operator >(SELF other) => _value > other._value;
bool operator >=(SELF other) => _value >= other._value;
@override
bool operator ==(Object other) =>
identical(this, other) || other is UnitValue && runtimeType == other.runtimeType && _value == other._value;
@override
int get hashCode => _value.hashCode;
int compareTo(SELF other) => _value.compareTo(other._value);
It feels like I had to add way too much boilerplate code. Does Dart provide any mixing for getting all that implementation based on a subset of operators?