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

import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import com.google.common.base.Optional;

@JsonIgnoreProperties( ignoreUnknown = true )
public class BaragonGroup {
  private final String name;
  @Deprecated
  private Optional<String> domain;
  private Set<TrafficSource> trafficSources;
  @Deprecated
  private Set<String> sources;
  private Optional<String> defaultDomain;
  private Set<String> domains;

  @JsonCreator
  public BaragonGroup(@JsonProperty("name") String name,
                      @JsonProperty("domain") Optional<String> domain,
                      @JsonProperty("trafficSources") Set<TrafficSource> trafficSources,
                      @JsonProperty("sources") Set<String> sources,
                      @JsonProperty("defaultDomain") Optional<String> defaultDomain,
                      @JsonProperty("domains") Set<String> domains) {
    this.name = name;
    this.domain = domain;
    this.defaultDomain = defaultDomain;
    this.domains = MoreObjects.firstNonNull(domains, Collections.<String>emptySet());

    if (sources == null) {
      setTrafficSources(MoreObjects.firstNonNull(trafficSources, Collections.<TrafficSource>emptySet()));
    } else if (trafficSources == null) {
      setSources(sources);
    } else {
      setTrafficSources(trafficSources);
    }
  }

  public String getName() {
    return name;
  }

  @Deprecated
  public Optional<String> getDomain() {
    return getDefaultDomain();
  }

  @Deprecated
  public void setDomain(Optional<String> domain) {
    this.domain = domain;
  }

  @Deprecated
  public Set<String> getSources() {
    return this.sources;
  }

  @Deprecated
  public void setSources(Set<String> sources) {
    Set<TrafficSource> trafficSources = new HashSet<>();
    for (String source : sources) {
      trafficSources.add(new TrafficSource(source, TrafficSourceType.CLASSIC));
    }

    this.setTrafficSources(trafficSources);
  }

  public Set<TrafficSource> getTrafficSources() {
    return trafficSources;
  }

  public void setTrafficSources(Set<TrafficSource> sources) {
    this.trafficSources = sources;

    Set<String> classicSources = new HashSet<>();
    for (TrafficSource source : sources) {
      if (source.getType() == TrafficSourceType.CLASSIC) {
        classicSources.add(source.getName());
      }
    }

    this.sources = classicSources;
  }

  public void removeTrafficSource(TrafficSource trafficSource) {
    this.trafficSources.remove(trafficSource);
    if (trafficSource.getType() == TrafficSourceType.CLASSIC) {
      sources.remove(trafficSource.getName());
    }
  }

  public void addTrafficSource(TrafficSource trafficSource) {
    this.trafficSources.add(trafficSource);
    if (trafficSource.getType() == TrafficSourceType.CLASSIC) {
      this.sources.add(trafficSource.getName());
    }
  }

  public Optional<String> getDefaultDomain() {
    return defaultDomain.or(domain);
  }

  public void setDefaultDomain(Optional<String> defaultDomain) {
    this.defaultDomain = defaultDomain;
  }

  public Set<String> getDomains() {
    return domains;
  }

  public void setDomains(Set<String> domains) {
    this.domains = domains;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj instanceof BaragonGroup) {
      final BaragonGroup that = (BaragonGroup) obj;
      return Objects.equals(this.name, that.name) &&
          Objects.equals(this.domain, that.domain) &&
          Objects.equals(this.trafficSources, that.trafficSources) &&
          Objects.equals(this.sources, that.sources) &&<commit_msg>Neaten code for keeping `sources`<commit_after>package com.hubspot.baragon.models;

import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import com.google.common.base.Optional;

@JsonIgnoreProperties( ignoreUnknown = true )
public class BaragonGroup {
  private final String name;
  @Deprecated
  private Optional<String> domain;
  private Set<TrafficSource> trafficSources;
  @Deprecated
  private Set<String> sources;
  private Optional<String> defaultDomain;
  private Set<String> domains;

  @JsonCreator
  public BaragonGroup(@JsonProperty("name") String name,
                      @JsonProperty("domain") Optional<String> domain,
                      @JsonProperty("trafficSources") Set<TrafficSource> trafficSources,
                      @JsonProperty("sources") Set<String> sources,
                      @JsonProperty("defaultDomain") Optional<String> defaultDomain,
                      @JsonProperty("domains") Set<String> domains) {
    this.name = name;
    this.domain = domain;
    this.defaultDomain = defaultDomain;
    this.domains = MoreObjects.firstNonNull(domains, Collections.<String>emptySet());
    this.sources = Collections.emptySet();

    if (trafficSources == null && sources != null) {
      this.trafficSources = sources.stream()
          .map(source -> new TrafficSource(source, TrafficSourceType.CLASSIC))
          .collect(Collectors.toSet());
    } else {
      this.trafficSources = MoreObjects.firstNonNull(trafficSources, Collections.emptySet());
    }
  }

  public String getName() {
    return name;
  }

  @Deprecated
  public Optional<String> getDomain() {
    return getDefaultDomain();
  }

  @Deprecated
  public void setDomain(Optional<String> domain) {
    this.domain = domain;
  }

  @Deprecated
  public Set<String> getSources() {
    return Collections.emptySet();
  }

  @Deprecated
  public void setSources(Set<String> sources) { }

  public Set<TrafficSource> getTrafficSources() {
    return trafficSources;
  }

  public void setTrafficSources(Set<TrafficSource> sources) {
    this.trafficSources = sources;
  }

  public void removeTrafficSource(TrafficSource trafficSource) {
    this.trafficSources.remove(trafficSource);
  }

  public void addTrafficSource(TrafficSource trafficSource) {
    this.trafficSources.add(trafficSource);
  }

  public Optional<String> getDefaultDomain() {
    return defaultDomain.or(domain);
  }

  public void setDefaultDomain(Optional<String> defaultDomain) {
    this.defaultDomain = defaultDomain;
  }

  public Set<String> getDomains() {
    return domains;
  }

  public void setDomains(Set<String> domains) {
    this.domains = domains;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj instanceof BaragonGroup) {
      final BaragonGroup that = (BaragonGroup) obj;
      return Objects.equals(this.name, that.name) &&
          Objects.equals(this.domain, that.domain) &&
          Objects.equals(this.trafficSources, that.trafficSources) &&
          Objects.equals(this.sources, that.sources) &&
{'fraction_non_alphanumeric': 0.1070294158265433, 'fraction_numerical': 0.0, 'mean_word_length': 3.6692456479690523, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 51, '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': '830347', 'n_tokens_mistral': 2102, 'n_tokens_neox': 2012, 'n_words': 420}