<commit_before>package com.hubspot.baragon.models;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Objects;
import com.google.common.base.Strings;
import io.dropwizard.validation.ValidationMethod;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.Collection;
import java.util.List;
import java.util.Map;

@JsonIgnoreProperties(ignoreUnknown = true)
public class Service {
  @NotEmpty
  @Pattern(regexp = "[^\\s/|]+", message = "cannot contain whitespace, '/', or '|'", flags = Pattern.Flag.MULTILINE)
  private final String serviceId;

  @NotNull
  private final Collection<String> owners;

  @NotEmpty
  @Pattern(regexp = "/(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@/?]|%[0-9A-Fa-f]{2})*", message = "must be an absolute URL path")
  private final String serviceBasePath;

  @NotEmpty
  private final List<String> loadBalancerGroups;

  private final Map<String, Object> options;
  
  public Service(@JsonProperty("serviceId") String serviceId,
                 @JsonProperty("owners") Collection<String> owners,
                 @JsonProperty("serviceBasePath") String serviceBasePath,
                 @JsonProperty("loadBalancerBaseUri") String loadBalancerBaseUri,  // <-- this is going away soon
                 @JsonProperty("loadBalancerGroups") List<String> loadBalancerGroups,
                 @JsonProperty("options") Map<String, Object> options) {
    this.serviceId = serviceId;
    this.owners = owners;
    this.serviceBasePath = !Strings.isNullOrEmpty(serviceBasePath) ? serviceBasePath : loadBalancerBaseUri;
    this.loadBalancerGroups = loadBalancerGroups;
    this.options = options;

    // TODO: bring back rewriteAppRootTo (sorry Ian)
  }

  public String getServiceId() {
    return serviceId;
  }

  public Collection<String> getOwners() {
    return owners;
  }

  public String getServiceBasePath() {
    return serviceBasePath;
  }

  @JsonIgnore
  @Deprecated
  public String getLoadBalancerBaseUri() {
    return serviceBasePath;
  }

  public List<String> getLoadBalancerGroups() {
    return loadBalancerGroups;
  }

  public Map<String, Object> getOptions() {
    return options;
  }

  @ValidationMethod(message = "loadBalancerGroups cannot contain '/'")
  public boolean validLoadBalancerGroups() {
    if (loadBalancerGroups != null) {
      for (String loadBalancerGroup : loadBalancerGroups) {
        if (loadBalancerGroup.contains("/")) {
          return false;
        }
      }
    }

    return true;
  }

  @Override
  public String toString() {
    return Objects.toStringHelper(Service.class)
        .add("serviceId", serviceId)
        .add("owners", owners)
        .add("serviceBasePath", serviceBasePath)
        .add("loadBalancerGroups", loadBalancerGroups)
        .add("options", options)
        .toString();
  }

  @Override
  public int hashCode() {
    return Objects.hashCode(serviceId, owners, serviceBasePath, loadBalancerGroups, options);
  }

  @Override
  public boolean equals(Object that) {
    if (this == that) {
      return true;
    }

    if (that == null) {
      return false;
    }

    if (that instanceof Service) {
      return Objects.equal(serviceId, ((Service)that).getServiceId())
          && Objects.equal(owners, ((Service)that).getOwners())
          && Objects.equal(serviceBasePath, ((Service)that).getServiceBasePath())
          && Objects.equal(loadBalancerGroups, ((Service)that).getLoadBalancerGroups())
          && Objects.equal(options, ((Service)that).getOptions());
    }

    return false;
  }
}<commit_msg>tweak Service.equals()<commit_after>package com.hubspot.baragon.models;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Objects;
import com.google.common.base.Strings;
import io.dropwizard.validation.ValidationMethod;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.Collection;
import java.util.List;
import java.util.Map;

@JsonIgnoreProperties(ignoreUnknown = true)
public class Service {
  @NotEmpty
  @Pattern(regexp = "[^\\s/|]+", message = "cannot contain whitespace, '/', or '|'", flags = Pattern.Flag.MULTILINE)
  private final String serviceId;

  @NotNull
  private final Collection<String> owners;

  @NotEmpty
  @Pattern(regexp = "/(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@/?]|%[0-9A-Fa-f]{2})*", message = "must be an absolute URL path")
  private final String serviceBasePath;

  @NotEmpty
  private final List<String> loadBalancerGroups;

  private final Map<String, Object> options;
  
  public Service(@JsonProperty("serviceId") String serviceId,
                 @JsonProperty("owners") Collection<String> owners,
                 @JsonProperty("serviceBasePath") String serviceBasePath,
                 @JsonProperty("loadBalancerBaseUri") String loadBalancerBaseUri,  // <-- this is going away soon
                 @JsonProperty("loadBalancerGroups") List<String> loadBalancerGroups,
                 @JsonProperty("options") Map<String, Object> options) {
    this.serviceId = serviceId;
    this.owners = owners;
    this.serviceBasePath = !Strings.isNullOrEmpty(serviceBasePath) ? serviceBasePath : loadBalancerBaseUri;
    this.loadBalancerGroups = loadBalancerGroups;
    this.options = options;

    // TODO: bring back rewriteAppRootTo (sorry Ian)
  }

  public String getServiceId() {
    return serviceId;
  }

  public Collection<String> getOwners() {
    return owners;
  }

  public String getServiceBasePath() {
    return serviceBasePath;
  }

  @JsonIgnore
  @Deprecated
  public String getLoadBalancerBaseUri() {
    return serviceBasePath;
  }

  public List<String> getLoadBalancerGroups() {
    return loadBalancerGroups;
  }

  public Map<String, Object> getOptions() {
    return options;
  }

  @ValidationMethod(message = "loadBalancerGroups cannot contain '/'")
  public boolean validLoadBalancerGroups() {
    if (loadBalancerGroups != null) {
      for (String loadBalancerGroup : loadBalancerGroups) {
        if (loadBalancerGroup.contains("/")) {
          return false;
        }
      }
    }

    return true;
  }

  @Override
  public String toString() {
    return Objects.toStringHelper(Service.class)
        .add("serviceId", serviceId)
        .add("owners", owners)
        .add("serviceBasePath", serviceBasePath)
        .add("loadBalancerGroups", loadBalancerGroups)
        .add("options", options)
        .toString();
  }

  @Override
  public int hashCode() {
    return Objects.hashCode(serviceId, owners, serviceBasePath, loadBalancerGroups, options);
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Service service = (Service) o;

    if (!loadBalancerGroups.equals(service.loadBalancerGroups)) return false;
    if (options != null ? !options.equals(service.options) : service.options != null) return false;
    if (!owners.equals(service.owners)) return false;
    if (!serviceBasePath.equals(service.serviceBasePath)) return false;
    if (!serviceId.equals(service.serviceId)) return false;

    return true;
  }
}
{'fraction_non_alphanumeric': 0.12023968042609853, 'fraction_numerical': 0.0013315579227696406, 'mean_word_length': 3.7031934877896053, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '4740104', 'n_tokens_mistral': 2228, 'n_tokens_neox': 2150, 'n_words': 478}