<commit_before>package com.celements.model.metadata;

import java.util.Objects;

import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import javax.validation.constraints.NotNull;

import org.suigeneris.jrcs.rcs.Version;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.model.reference.SpaceReference;

import com.celements.model.util.References;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;

@Immutable
public final class ImmutableDocumentMetaData implements DocumentMetaData {

  private final SpaceReference spaceRef;
  private final String name;
  private final String lang;
  private final Version version;

  public static class Builder {

    private final SpaceReference spaceRef;
    private final String name;
    private String lang;
    private Version version;

    public Builder(@NotNull SpaceReference spaceRef, @NotNull String name) {
      this.spaceRef = Objects.requireNonNull(spaceRef);
      this.name = Objects.requireNonNull(name);
      Preconditions.checkArgument(!name.isEmpty());
      this.lang = "";
    }

    public Builder language(@Nullable String val) {
      lang = Strings.nullToEmpty(val).trim();
      return this;
    }

    public Builder version(@Nullable String val) {
      if (!Strings.isNullOrEmpty(val)) {
        version(new Version(val));
      }
      return this;
    }

    public Builder version(@Nullable Version val) {
      version = val;
      return this;
    }

    public ImmutableDocumentMetaData build() {
      return new ImmutableDocumentMetaData(this);
    }

  }

  protected ImmutableDocumentMetaData(@NotNull Builder builder) {
    this.spaceRef = builder.spaceRef;
    this.name = builder.name;
    this.lang = builder.lang;
    this.version = builder.version;
  }

  @Override
  public DocumentReference getDocRef() {
    return new DocumentReference(name, References.cloneRef(spaceRef, SpaceReference.class));
  }

  @Override
  public String getLanguage() {
    return lang;
  }

  @Override
  public Version getVersion() {
    return version;
  }

  @Override
  public int hashCode() {
    return Objects.hash(spaceRef, name, lang, version);
  }

  @Override
  public boolean equals(Object obj) {
    boolean ret = false;
    if (this == obj) {
      ret = true;
    } else if (obj instanceof DocumentMetaData) {
      DocumentMetaData other = (DocumentMetaData) obj;
      ret = Objects.equals(this.getDocRef(), other.getDocRef()) && Objects.equals(this.lang,
          other.getLanguage()) && Objects.equals(this.version, other.getVersion());
    }
    return ret;
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("ImmutableDocumentMetaData [docRef=").append(getDocRef()).append(", lang=").append(
        lang).append(", version=").append(version).append("]");
    return sb.toString();
  }

}
<commit_msg>renamed name to docName<commit_after>package com.celements.model.metadata;

import java.util.Objects;

import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import javax.validation.constraints.NotNull;

import org.suigeneris.jrcs.rcs.Version;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.model.reference.SpaceReference;

import com.celements.model.util.References;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;

@Immutable
public final class ImmutableDocumentMetaData implements DocumentMetaData {

  private final SpaceReference spaceRef;
  private final String docName;
  private final String lang;
  private final Version version;

  public static class Builder {

    private final SpaceReference spaceRef;
    private final String docName;
    private String lang;
    private Version version;

    public Builder(@NotNull SpaceReference spaceRef, @NotNull String docName) {
      this.spaceRef = Objects.requireNonNull(spaceRef);
      this.docName = Objects.requireNonNull(docName);
      Preconditions.checkArgument(!docName.isEmpty());
      this.lang = "";
    }

    public Builder language(@Nullable String val) {
      lang = Strings.nullToEmpty(val).trim();
      return this;
    }

    public Builder version(@Nullable String val) {
      if (!Strings.isNullOrEmpty(val)) {
        version(new Version(val));
      }
      return this;
    }

    public Builder version(@Nullable Version val) {
      version = val;
      return this;
    }

    public ImmutableDocumentMetaData build() {
      return new ImmutableDocumentMetaData(this);
    }

  }

  protected ImmutableDocumentMetaData(@NotNull Builder builder) {
    this.spaceRef = builder.spaceRef;
    this.docName = builder.docName;
    this.lang = builder.lang;
    this.version = builder.version;
  }

  @Override
  public DocumentReference getDocRef() {
    return new DocumentReference(docName, References.cloneRef(spaceRef, SpaceReference.class));
  }

  @Override
  public String getLanguage() {
    return lang;
  }

  @Override
  public Version getVersion() {
    return version;
  }

  @Override
  public int hashCode() {
    return Objects.hash(spaceRef, docName, lang, version);
  }

  @Override
  public boolean equals(Object obj) {
    boolean ret = false;
    if (this == obj) {
      ret = true;
    } else if (obj instanceof DocumentMetaData) {
      DocumentMetaData other = (DocumentMetaData) obj;
      ret = Objects.equals(this.getDocRef(), other.getDocRef()) && Objects.equals(this.lang,
          other.getLanguage()) && Objects.equals(this.version, other.getVersion());
    }
    return ret;
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("ImmutableDocumentMetaData [docRef=").append(getDocRef()).append(", lang=").append(
        lang).append(", version=").append(version).append("]");
    return sb.toString();
  }

}

{'fraction_non_alphanumeric': 0.10571040108769544, 'fraction_numerical': 0.0, 'mean_word_length': 3.6120689655172415, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6204672', 'n_tokens_mistral': 1650, 'n_tokens_neox': 1627, 'n_words': 401}