mayFollow static method

bool mayFollow(
  1. List<ExpandedPair> pairs,
  2. int value
)

Implementation

static bool mayFollow(List<ExpandedPair> pairs, int value) {
  if (pairs.isEmpty) {
    return true;
  }

  for (List<int> sequence in _finderPatternSequences) {
    if (pairs.length + 1 <= sequence.length) {
      // the proposed sequence (i.e. pairs + value) would fit in this allowed sequence
      for (int i = pairs.length; i < sequence.length; i++) {
        if (sequence[i] == value) {
          // we found our value in this allowed sequence, check to see if the elements preceding it match our existing
          // pairs; note our existing pairs may not be a full sequence (e.g. if processing a row in a stacked symbol)
          bool matched = true;
          for (int j = 0; j < pairs.length; j++) {
            final allowed = sequence[i - j - 1];
            final actual = pairs[pairs.length - j - 1].finderPattern?.value;
            if (allowed != actual) {
              matched = false;
              break;
            }
          }
          if (matched) {
            return true;
          }
        }
      }
    }
  }

  // the proposed finder pattern sequence is illegal
  return false;
}