
package de.ivu.elect.jee.entity;

import java.io.Serializable;

/**
 * Klasse, die eine Entität eindeutig anhand ihres Namens und ihrer ID identifiziert
 */
public class EntityTechnicalNamePk implements Serializable {

  private static final long serialVersionUID = 1L;

  private final String technicalName;

  private final Long id;

  public EntityTechnicalNamePk(Entity< ? , ? > entity) {
    this(entity.getEntityTechnicalName(), entity.getId());
  }

  public EntityTechnicalNamePk(String technicalName, Long id) {
    super();

    this.technicalName = technicalName;
    this.id = id;
  }

  public String getTechnicalName() {
    return technicalName;
  }

  public Long getId() {
    return id;
  }

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

    EntityTechnicalNamePk that = (EntityTechnicalNamePk) o;

    if (!id.equals(that.id)) {
      return false;
    }
    if (!technicalName.equals(that.technicalName)) {
      return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    int result = technicalName.hashCode();
    result = 31 * result + id.hashCode();
    return result;
  }

  @Override
  public String toString() {
    return "EntityTechnicalNamePk{" + "technicalName='" + technicalName + '\'' + ", id=" + id + '}';
  }
}
