/*
 * Copyright (c) 2006-2012 by Public Library of Science
 * http://plos.org
 * http://ambraproject.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.ambraproject.rhino.content;

import com.google.common.base.Preconditions;
import org.ambraproject.models.ArticlePerson;
import org.ambraproject.models.CitedArticlePerson;

/**
 * Immutable holder for a name that can be put into {@link ArticlePerson} or {@link CitedArticlePerson}.
 * <p/>
 * This is a hack to allow code to write to {@link ArticlePerson} and {@link CitedArticlePerson} with minimal
 * duplication, because those two classes lack a superclass or interface to unify them.
 */
public class PersonName {

  private final String fullName;
  private final String givenNames;
  private final String surname;
  private final String suffix;

  public PersonName(String fullName, String givenNames, String surname, String suffix) {
    this.fullName = Preconditions.checkNotNull(fullName);
    this.givenNames = Preconditions.checkNotNull(givenNames);
    this.surname = Preconditions.checkNotNull(surname);
    this.suffix = Preconditions.checkNotNull(suffix);
  }


  public <P extends ArticlePerson> P copyTo(P articlePerson) {
    articlePerson.setFullName(fullName);
    articlePerson.setGivenNames(givenNames);
    articlePerson.setSurnames(surname);
    articlePerson.setSuffix(suffix);
    return articlePerson;
  }

  public static PersonName from(ArticlePerson articlePerson) {
    return new PersonName(articlePerson.getFullName(), articlePerson.getGivenNames(),
        articlePerson.getSurnames(), articlePerson.getSuffix());
  }

  public <P extends CitedArticlePerson> P copyTo(P citedArticlePerson) {
    citedArticlePerson.setFullName(fullName);
    citedArticlePerson.setGivenNames(givenNames);
    citedArticlePerson.setSurnames(surname);
    citedArticlePerson.setSuffix(suffix);
    return citedArticlePerson;
  }

  public static PersonName from(CitedArticlePerson citedArticlePerson) {
    return new PersonName(citedArticlePerson.getFullName(), citedArticlePerson.getGivenNames(),
        citedArticlePerson.getSurnames(), citedArticlePerson.getSuffix());
  }


  public String getFullName() {
    return fullName;
  }

  public String getGivenNames() {
    return givenNames;
  }

  public String getSuffix() {
    return suffix;
  }

  public String getSurname() {
    return surname;
  }


  @Override
  public String toString() {
    return fullName;
  }

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

    PersonName that = (PersonName) o;

    if (!fullName.equals(that.fullName)) return false;
    if (!givenNames.equals(that.givenNames)) return false;
    if (!suffix.equals(that.suffix)) return false;
    if (!surname.equals(that.surname)) return false;

    return true;
  }

  @Override
  public int hashCode() {
    int result = fullName.hashCode();
    result = 31 * result + givenNames.hashCode();
    result = 31 * result + surname.hashCode();
    result = 31 * result + suffix.hashCode();
    return result;
  }
}

@@ -2670,239 +2670,8 @@
 %7D%0A%0A%0A
-  public String getFullName() %7B%0A    return fullName;%0A  %7D%0A%0A  public String getGivenNames() %7B%0A    return givenNames;%0A  %7D%0A%0A  public String getSuffix() %7B%0A    return suffix;%0A  %7D%0A%0A  public String getSurname() %7B%0A    return surname;%0A  %7D%0A%0A%0A
   @O

Remove unused getters