simplify method

  1. @override
Sorter simplify()
override

Implementation

@override
Sorter simplify() {
  var oldSorters = sorters;
  if (oldSorters.isEmpty) {
    return null;
  }
  if (oldSorters.length == 1) {
    return oldSorters.single.simplify();
  }
  List<Sorter> newSorters;
  for (var i = 0; i < oldSorters.length; i++) {
    final oldSorter = oldSorters[i];
    final newSorter = oldSorter.simplify();
    if (!identical(newSorter, oldSorter) || newSorter is MultiSorter) {
      if (newSorters == null) {
        newSorters = <Sorter>[];
        newSorters.addAll(oldSorters.take(i));
      }
      if (newSorter == null) {
        // Ignore
      } else if (newSorter is MultiSorter) {
        newSorters.addAll(newSorter.sorters);
      } else {
        newSorters.add(newSorter);
      }
    }
  }
  if (newSorters == null) {
    return this;
  }
  if (newSorters.isEmpty) {
    return null;
  }
  return MultiSorter(
    List<Sorter>.unmodifiable(newSorters),
  );
}