001/*
002 * Copyright 2014 Global Biodiversity Information Facility (GBIF)
003 * Licensed under the Apache License, Version 2.0 (the "License");
004 * you may not use this file except in compliance with the License.
005 * You may obtain a copy of the License at
006 * http://www.apache.org/licenses/LICENSE-2.0
007 * Unless required by applicable law or agreed to in writing, software
008 * distributed under the License is distributed on an "AS IS" BASIS,
009 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
010 * See the License for the specific language governing permissions and
011 * limitations under the License.
012 */
013package org.gbif.api.model.registry;
014
015import java.io.Serializable;
016import javax.annotation.Nullable;
017import javax.validation.constraints.Size;
018
019import com.google.common.base.Objects;
020
021
022/**
023 * A citation can have one or both of a textual component and an identifier which can be
024 * of any form, but expected to be resolvable in some way such as an LSID, DOI or similar.
025 */
026public class Citation implements Serializable {
027
028  private static final long serialVersionUID = 5587531070690709593L;
029
030  @Nullable
031  private String text;
032
033  @Nullable
034  @Size(min = 1, max = 100)
035  private String identifier;
036
037  public Citation() {
038  }
039
040  public Citation(String text, String identifier) {
041    this.text = text;
042    this.identifier = identifier;
043  }
044
045  public String getIdentifier() {
046    return identifier;
047  }
048
049  public void setIdentifier(String identifier) {
050    this.identifier = identifier;
051  }
052
053  public String getText() {
054    return text;
055  }
056
057  public void setText(String text) {
058    this.text = text;
059  }
060
061  @Override
062  public boolean equals(Object obj) {
063    if (obj instanceof Citation) {
064      Citation that = (Citation) obj;
065      return Objects.equal(this.text, that.text) && Objects.equal(this.identifier, that.identifier);
066    }
067    return false;
068  }
069
070  @Override
071  public int hashCode() {
072    return Objects.hashCode(text, identifier);
073  }
074
075  @Override
076  public String toString() {
077    return Objects.toStringHelper(this)
078      .add("text", text)
079      .add("identifier", identifier)
080      .toString();
081  }
082
083}