sortIfNecessary static method

void sortIfNecessary(
  1. Object? value
)

Sorts the given value if it's a List<Object>.

This method provides safe sorting that only operates on compatible types. It's useful in scenarios where you're not sure if a value needs sorting or is even sortable.

Parameters:

  • value: The value to potentially sort

Behavior:

  • If value is a List<Object>, sorts it in-place
  • For any other type, does nothing (safe no-op)

Example:

void configureProcessors(Object processors) {
  // Safely sort if it's a list, otherwise ignore
  OrderComparator.sortIfNecessary(processors);
}

// Both usages are safe
configureProcessors([processor1, processor2]);
configureProcessors('not-a-list'); // safely ignored

Implementation

static void sortIfNecessary(Object? value) {
  if (value is List<Object>) {
    sortList(value);
  }
}