listWithSubRange method

InkList listWithSubRange(
  1. dynamic minBound,
  2. dynamic maxBound
)
Returns a sublist with the elements given the minimum and maxmimum bounds. The bounds can either be ints which are indices into the entire (sorted) list, or they can be InkLists themselves. These are intended to be single-item lists so you can specify the upper and lower bounds. If you pass in multi-item lists, it'll use the minimum and maximum items in those lists respectively. WARNING: Calling this method requires a full sort of all the elements in the list.

Implementation

InkList listWithSubRange(dynamic minBound, dynamic maxBound) {
  if (isEmpty) {
    return InkList();
  }

  var ordered = orderedItems;

  int minValue = 0;
  int maxValue = 1 << 32;

  if (minBound is int) {
    minValue = minBound;
  } else {
    if (minBound is InkList && minBound.isNotEmpty) {
      minValue = minBound.minItem.value;
    }
  }

  if (maxBound is int) {
    maxValue = maxBound;
  } else {
    if (minBound is InkList && minBound.isNotEmpty) {
      maxValue = maxBound.maxItem.value;
    }
  }

  var subList = InkList();
  subList.setInitialOriginNames(originNames);
  for (var item in ordered) {
    if (item.value >= minValue && item.value <= maxValue) {
      subList[item.key] = item.value;
    }
  }

  return subList;
}