<commit_before>package io.vertx.ext.web.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;

import io.vertx.codegen.annotations.Fluent;

public class ParsedMIME implements Comparable<ParsedMIME>{
  
  private String component;
  private String subComponent;
  
  private Map<String, String> parameter;

  private static final String STAR = "*";
  private static final String EMPTY = "";
  
  public ParsedMIME(String mimeComponent, String mimeSubComponent) {
    
    this.component = mimeComponent.equals(STAR) ? STAR : mimeComponent;
    this.subComponent = mimeSubComponent.equals(STAR) ? STAR : mimeSubComponent;
  }
  
  /**
   * Import a ParsedMIME
   */
  protected ParsedMIME(ParsedMIME mime) {
    this(mime.component, mime.subComponent);
    parameter = mime.parameter;
  }

  @Fluent
  public ParsedMIME addParameter(String key, String value) {
    ensureParameterExists();
    
    parameter.put(key, value);
    return this;
  }
  
  @Fluent
  public ParsedMIME addParameter(String key) {
    ensureParameterExists();
    
    parameter.put(key, EMPTY);
    return this;
  }
  
  /**
   * Tests if this MIME complies with matchTry MIME
   * @return
   */
  public boolean isMatchedBy(ParsedMIME matchTry) {

    if (component != STAR && !component.equals(matchTry.component)) {
      return false;
    }
    if (subComponent != STAR && !subComponent.equals(matchTry.subComponent)) {
      return false;
    }
    
    if (matchTry.parameter == null) {
      return true;
      
    }
    if (parameter == null) {
      return false;
    }
      
    for (Entry<String, String> requiredParameter : matchTry.parameter.entrySet()) {
      String parameterValueToTest = parameter.get(requiredParameter.getKey());
      String requiredParamVal = requiredParameter.getValue();
      
      if (parameterValueToTest == null || (
          requiredParamVal != null && !requiredParamVal.equals(parameterValueToTest))
         ){
        return false;
      }
    }
    return true;
  }
  
  public Optional<ParsedMIME> findMatchedBy(Iterable<ParsedMIME> matchTries) {
    
    for (ParsedMIME matchTry : matchTries) {
      if(isMatchedBy(matchTry)){
        return Optional.of(matchTry);<commit_msg>.findMatchedBy() needs to receive something slightly different<commit_after>package io.vertx.ext.web.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;

import io.vertx.codegen.annotations.Fluent;

public class ParsedMIME implements Comparable<ParsedMIME>{
  
  private String component;
  private String subComponent;
  
  private Map<String, String> parameter;

  private static final String STAR = "*";
  private static final String EMPTY = "";
  
  public ParsedMIME(String mimeComponent, String mimeSubComponent) {
    
    this.component = mimeComponent.equals(STAR) ? STAR : mimeComponent;
    this.subComponent = mimeSubComponent.equals(STAR) ? STAR : mimeSubComponent;
  }
  
  /**
   * Import a ParsedMIME
   */
  protected ParsedMIME(ParsedMIME mime) {
    this(mime.component, mime.subComponent);
    parameter = mime.parameter;
  }

  @Fluent
  public ParsedMIME addParameter(String key, String value) {
    ensureParameterExists();
    
    parameter.put(key, value);
    return this;
  }
  
  @Fluent
  public ParsedMIME addParameter(String key) {
    ensureParameterExists();
    
    parameter.put(key, EMPTY);
    return this;
  }
  
  /**
   * Tests if this MIME complies with matchTry MIME
   * @return
   */
  public boolean isMatchedBy(ParsedMIME matchTry) {

    if (component != STAR && !component.equals(matchTry.component)) {
      return false;
    }
    if (subComponent != STAR && !subComponent.equals(matchTry.subComponent)) {
      return false;
    }
    
    if (matchTry.parameter == null) {
      return true;
      
    }
    if (parameter == null) {
      return false;
    }
      
    for (Entry<String, String> requiredParameter : matchTry.parameter.entrySet()) {
      String parameterValueToTest = parameter.get(requiredParameter.getKey());
      String requiredParamVal = requiredParameter.getValue();
      
      if (parameterValueToTest == null || (
          requiredParamVal != null && !requiredParamVal.equals(parameterValueToTest))
         ){
        return false;
      }
    }
    return true;
  }
  
  public Optional<ParsedMIME> findMatchedBy(Iterable<? extends ParsedMIME> matchTries) {
    
    for (ParsedMIME matchTry : matchTries) {
      if(isMatchedBy(matchTry)){
        return Optional.of(matchTry);
{'fraction_non_alphanumeric': 0.10328638497652583, 'fraction_numerical': 0.0, 'mean_word_length': 3.216867469879518, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '1692263', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1499, 'n_words': 329}