@Nullable
  static ExtremumTerminal extract(@NotNull TerminalBlock terminalBlock, @Nullable List<PsiVariable> nonFinalVariables) {
    PsiStatement[] statements = terminalBlock.getStatements();
    StreamApiMigrationInspection.FilterOp filterOp = terminalBlock.getLastOperation(StreamApiMigrationInspection.FilterOp.class);
    if (filterOp != null) {
      TerminalBlock block = terminalBlock.withoutLastOperation();
      if (block != null) {
        boolean negated = filterOp.isNegated();
        PsiExpression condition = filterOp.getExpression();
        ExtremumTerminal simpleRefCase = extractRefCase(condition, statements, block,
                                                        (nullCheckExpr, comparisonExpr, statements1, terminalBlock1, nonFinalVars, isNegated) -> SimpleRefExtremumTerminal
                                                          .extract(nullCheckExpr, comparisonExpr, statements1, terminalBlock1,
                                                                   nonFinalVars),
                                                        nonFinalVariables, negated);
        if (simpleRefCase != null) return simpleRefCase;
        ExtremumTerminal primitiveCase = PrimitiveExtremumTerminal.extract(condition, statements, block, nonFinalVariables, negated);
        if (primitiveCase != null) return primitiveCase;
        ExtremumTerminal complexRefCase = extractRefCase(condition, statements, block, ComplexExtremumTerminal::extract, nonFinalVariables,
                                                         negated);
        if (complexRefCase != null) return complexRefCase;
      }
    }
    return extractIfElseCase(statements, terminalBlock, nonFinalVariables);
  }
@Nullable
  static ExtremumTerminal extract(@NotNull TerminalBlock terminalBlock, @Nullable List<PsiVariable> nonFinalVariables)