compareTo method

  1. @override
int compareTo(
  1. BayesCondition other, {
  2. String? mainVariable,
})
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(BayesCondition other, {String? mainVariable}) {
  if (identical(this, other)) return 0;

  if (mainVariable != null) {
    mainVariable =
        BayesVariable.resolveName(mainVariable, networkCache: network);

    var mainEvents1 = _events
        .where((e) => e.node.variablesAsString == mainVariable)
        .toList();
    var mainEvents2 = other._events
        .where((e) => e.node.variablesAsString == mainVariable)
        .toList();

    var cmp = mainEvents1.compareWith(mainEvents2);
    if (cmp == 0) {
      var otherEvents1 = _events
          .where((e) => e.node.variablesAsString != mainVariable)
          .toList();
      var otherEvents2 = other._events
          .where((e) => e.node.variablesAsString != mainVariable)
          .toList();

      cmp = otherEvents1.compareWith(otherEvents2);
    }

    return cmp;
  }

  return _events.compareWith(other._events);
}