<commit_before>part of vint;

typedef bool Condition(Model t);

typedef Map<String, List> Errors(Model t);

abstract class Validator {
  Map<String, List> validate(Model model);
}

class CustomValidator implements Validator {
  Condition _condition;
  Errors _errors;

  CustomValidator(this._condition, this._errors);

  Map<String, List> validate(Model model)
    => _condition(model) ? {} :  _errors(model);
}

class CompositeValidator implements Validator {
  final List parts = [];

  Map<String, List> validate(Model model){
    var errors = parts.map((_) => _.validate(model));
    return _mergeErrors(errors);
  }

  _mergeErrors(errors){
    return errors.reduce({}, (memo, curr){
      curr.forEach((field, fieldErrors){
        memo.putIfAbsent(field, () => []);
        memo[field].addAll(fieldErrors);
      });
      return memo;
    });
  }
}

class Validations {
  final _composite = new CompositeValidator();

  void addValidator(Validator validator){
    _composite.parts.add(validator);
  }

  void add(Condition condition, Errors errors){
    addValidator(new CustomValidator(condition, errors));
  }

  Map<String, List> validate(Model model){
    var errors = _composite.validate(model);
    model.events.fireValidation(errors);
    return errors;
  }
}

class PresenceValidator implements Validator{
  String attr;

  PresenceValidator(this.attr);

  Map<String, List> validate(Model model){<commit_msg>changes Validations to implement Validator<commit_after>part of vint;

typedef bool Condition(Model t);

typedef Map<String, List> Errors(Model t);

abstract class Validator {
  Map<String, List> validate(Model model);
}

class CustomValidator implements Validator {
  Condition _condition;
  Errors _errors;

  CustomValidator(this._condition, this._errors);

  Map<String, List> validate(Model model)
    => _condition(model) ? {} :  _errors(model);
}

class CompositeValidator implements Validator {
  final List parts = [];

  Map<String, List> validate(Model model){
    var errors = parts.map((_) => _.validate(model));
    return _mergeErrors(errors);
  }

  _mergeErrors(errors){
    return errors.reduce({}, (memo, curr){
      curr.forEach((field, fieldErrors){
        memo.putIfAbsent(field, () => []);
        memo[field].addAll(fieldErrors);
      });
      return memo;
    });
  }
}

class Validations implements Validator {
  final _composite = new CompositeValidator();

  void addValidator(Validator validator){
    _composite.parts.add(validator);
  }

  void add(Condition condition, Errors errors){
    addValidator(new CustomValidator(condition, errors));
  }

  Map<String, List> validate(Model model){
    var errors = _composite.validate(model);
    model.events.fireValidation(errors);
    return errors;
  }
}

class PresenceValidator implements Validator{
  String attr;

  PresenceValidator(this.attr);

  Map<String, List> validate(Model model){
{'fraction_non_alphanumeric': 0.11991729841488628, 'fraction_numerical': 0.0, 'mean_word_length': 4.230630630630631, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, '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': '1969789', 'n_tokens_mistral': 868, 'n_tokens_neox': 847, 'n_words': 209}