001package org.gbif.api.model.common;
002
003import java.net.URI;
004
005import javax.annotation.Nullable;
006import javax.validation.constraints.NotNull;
007
008import com.google.common.base.Objects;
009import com.google.common.base.Preconditions;
010import org.codehaus.jackson.annotate.JsonCreator;
011import org.codehaus.jackson.annotate.JsonProperty;
012
013/**
014 * Data about a DOI with a target URI and a status enumeration.
015 */
016public class DoiData {
017  private final DoiStatus status;
018  private final URI target;
019
020  @JsonCreator
021  public DoiData(@JsonProperty("status") DoiStatus status, @JsonProperty("target") URI target) {
022    this.status = Preconditions.checkNotNull(status, "DOI status is required");
023    this.target = target;
024  }
025
026  public DoiData(String ezidStatus, URI target) {
027    this.status = Preconditions.checkNotNull(DoiStatus.fromString(ezidStatus));
028    this.target = target;
029  }
030
031  @NotNull
032  public DoiStatus getStatus() {
033    return status;
034  }
035
036  @Nullable
037  public URI getTarget() {
038    return target;
039  }
040
041  @Override
042  public int hashCode() {
043    return Objects.hashCode(status, target);
044  }
045
046  @Override
047  public boolean equals(Object obj) {
048    if (this == obj) {
049      return true;
050    }
051    if (obj == null || getClass() != obj.getClass()) {
052      return false;
053    }
054    final DoiData other = (DoiData) obj;
055    return Objects.equal(this.status, other.status) && Objects.equal(this.target, other.target);
056  }
057
058  @Override
059  public String toString() {
060    return Objects.toStringHelper(this)
061      .add("status", status)
062      .add("target", target)
063      .toString();
064  }
065
066}