<commit_before>import 'package:jefe/src/project/jefe_project.dart';
import 'dart:async';
import 'package:jefe/src/project_commands/project_command.dart'
    show Callable, CommandConcurrencyMode, executeTask;

typedef Future<S> SingleProjectCommandFactory<S>(JefeProject project);
typedef Future<T> SingleProjectCommand<S, T>(S single);
typedef Callable<T> _Processor<T>(ProjectFunction/*<T>*/ command,
    {ProjectFilter filter, Combiner/*<T>*/ combine});

abstract class BaseCommandsImpl<S> {
  final JefeProjectGraph graph;
  final SingleProjectCommandFactory<S> _singleProjectCommandFactory;

  BaseCommandsImpl(this.graph, this._singleProjectCommandFactory);

  Future/*<T>*/ processAllConcurrently2/*<T>*/(
      String taskDescription, SingleProjectCommand<S, dynamic/*=T*/ > command,
      {ProjectFilter filter, Combiner/*<T>*/ combine}) {
    Future/*<T>*/ _executeOnSingleProject(JefeProject p) async {
      return command(await _singleProjectCommandFactory(p));
    }

    return graph.processAllConcurrently(_executeOnSingleProject,
        filter: filter, combine: combine);
  }

  Future/*<T>*/ processDepthFirst/*<T>*/(ProjectFunction/*<T>*/ command,
          {ProjectFilter filter, Combiner/*<T>*/ combine}) =>
      graph.processDepthFirst(command, filter: filter, combine: combine);

  Callable/*<T>*/ _concurrentProcessor/*<T>*/(ProjectFunction/*<T>*/ command,
      {ProjectFilter filter, Combiner/*<T>*/ combine}) {
    return () =>
        graph.processAllConcurrently(command, filter: filter, combine: combine);
  }

  Callable/*<T>*/ _serialProcessor/*<T>*/(ProjectFunction/*<T>*/ command,
      {ProjectFilter filter, Combiner/*<T>*/ combine}) {
    return () =>
        graph.processDepthFirst(command, filter: filter, combine: combine);
  }

  _Processor/*<T>*/ _processor/*<T>*/(CommandConcurrencyMode mode) {
    switch (mode) {
      case CommandConcurrencyMode.serial:
        return _concurrentProcessor; // TODO:!!!
      case CommandConcurrencyMode.concurrentCommand:
      case CommandConcurrencyMode.concurrentProject:
      default:
        return _concurrentProcessor;
    }
  }

  Future/*<T>*/ process/*<T>*/(
      String taskDescription, SingleProjectCommand<S, dynamic/*=T*/ > command,
      {ProjectFilter filter,
      Combiner/*<T>*/ combine,
      CommandConcurrencyMode mode: CommandConcurrencyMode.concurrentCommand}) {
    final processor =
        _processor/*<T>*/(mode ?? CommandConcurrencyMode.concurrentCommand);

    return executeTask/*<T>*/(
        taskDescription,
        processor(
            (JefeProject project) =>
                _processOnSingeProject2(project, taskDescription, command),
            filter: filter,
            combine: combine));
  }

  Future/*<T>*/ processAllConcurrently/*<T>*/(
          String taskDescription, ProjectFunction/*<T>*/ command,<commit_msg>JefeProject<commit_after>import 'package:jefe/src/project/jefe_project.dart';
import 'dart:async';
import 'package:jefe/src/project_commands/project_command.dart'
    show Callable, CommandConcurrencyMode, executeTask;

typedef Future<S> SingleProjectCommandFactory<S>(JefeProject project);
typedef Future<T> SingleProjectCommand<S, T>(S single);
typedef Callable<T> _Processor<T>(ProjectFunction/*<T>*/ command,
    {ProjectFilter filter, Combiner/*<T>*/ combine});

abstract class BaseCommandsImpl<S> {
  final JefeProjectGraph graph;
  final SingleProjectCommandFactory<S> _singleProjectCommandFactory;

  BaseCommandsImpl(this.graph, this._singleProjectCommandFactory);

  Future/*<T>*/ processAllConcurrently2/*<T>*/(
      String taskDescription, SingleProjectCommand<S, dynamic/*=T*/ > command,
      {ProjectFilter filter, Combiner/*<T>*/ combine}) {
    Future/*<T>*/ _executeOnSingleProject(JefeProject p) async {
      return command(await _singleProjectCommandFactory(p));
    }

    return graph.processAllConcurrently(_executeOnSingleProject,
        filter: filter, combine: combine);
  }

  Future/*<T>*/ processDepthFirst/*<T>*/(ProjectFunction/*<T>*/ command,
          {ProjectFilter filter, Combiner/*<T>*/ combine}) =>
      graph.processDepthFirst(command, filter: filter, combine: combine);

  Callable/*<T>*/ _concurrentProcessor/*<T>*/(ProjectFunction/*<T>*/ command,
      {ProjectFilter filter, Combiner/*<T>*/ combine}) {
    return () =>
        graph.processAllConcurrently(command, filter: filter, combine: combine);
  }

  Callable/*<T>*/ _serialProcessor/*<T>*/(ProjectFunction/*<T>*/ command,
      {ProjectFilter filter, Combiner/*<T>*/ combine}) {
    return () =>
        graph.processDepthFirst(command, filter: filter, combine: combine);
  }

  _Processor/*<T>*/ _processor/*<T>*/(CommandConcurrencyMode mode) {
    switch (mode) {
      case CommandConcurrencyMode.serial:
        return _serialProcessor;
      case CommandConcurrencyMode.concurrentCommand:
      case CommandConcurrencyMode.concurrentProject:
      default:
        return _concurrentProcessor;
    }
  }

  Future/*<T>*/ process/*<T>*/(
      String taskDescription, SingleProjectCommand<S, dynamic/*=T*/ > command,
      {ProjectFilter filter,
      Combiner/*<T>*/ combine,
      CommandConcurrencyMode mode: CommandConcurrencyMode.concurrentCommand}) {
    final processor =
        _processor/*<T>*/(mode ?? CommandConcurrencyMode.concurrentCommand);

    return executeTask/*<T>*/(
        taskDescription,
        processor(
            (JefeProject project) =>
                _processOnSingeProject2(project, taskDescription, command),
            filter: filter,
            combine: combine));
  }

  Future/*<T>*/ processAllConcurrently/*<T>*/(
          String taskDescription, ProjectFunction/*<T>*/ command,
{'fraction_non_alphanumeric': 0.13732394366197184, 'fraction_numerical': 0.0007042253521126761, 'mean_word_length': 4.031886625332152, 'pattern_counts': {'":': 0, '<': 79, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3094993', 'n_tokens_mistral': 1641, 'n_tokens_neox': 1618, 'n_words': 306}