/*
 * Fachlicher Schlüssel für JPA Entität
 */
package de.ivu.elect.business.kandidatur.entity;

import de.ivu.elect.jee.faces.Messages;
import de.ivu.elect.jee.faces.IMessages;
import java.util.function.Function;

@javax.enterprise.inject.Vetoed
public class ListenkandidaturTK
extends de.ivu.elect.business.kandidatur.entity.KandidaturTK
  {

  private static final long serialVersionUID = 1L;

  private final int hashCode;

    protected final java.lang.Long relativePosition;
    public java.lang.Long getRelativePosition(){
      return relativePosition;
    }
  protected final de.ivu.elect.business.wahlvorschlag.entity.ListeTK listeTK;
    public de.ivu.elect.business.wahlvorschlag.entity.ListeTK getListeTK(){
      return listeTK;
    }

  public ListenkandidaturTK(
java.lang.Long relativePosition
,   de.ivu.elect.business.wahlvorschlag.entity.ListeTK listeTK
  ) {
super(



);


      this.relativePosition = relativePosition;
        this.listeTK = listeTK;
  
hashCode = calculateHashCode();
  }

  @Override
  public int hashCode(){
    return hashCode;
  }


  protected int calculateHashCode() {
        int result = super.calculateHashCode();
    
    
                    result = result + ((relativePosition == null) ? 0 : relativePosition.hashCode());
        
                    result = result + ((listeTK == null) ? 0 : listeTK.hashCode());
            
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }

    if (obj == null) {
      return false;
    }

    if (hashCode()!=obj.hashCode()) {
      return false;
    }


                    if (super.hatAttribute() && !super.equals(obj)) {
          return false;
        }
        
    if (getClass() != obj.getClass()) {
      if (!(obj instanceof ListenkandidaturTK)) {
        return false;
      }

      if (!obj.getClass().isInstance(this)) {
        return obj.equals(this); // equals-Methode aus speziellerer Klasse verwenden
      }

    }

        ListenkandidaturTK other = (ListenkandidaturTK) obj;

                if (relativePosition == null) {
          if (other.relativePosition != null) {
            return false;
          }
        } else if (!relativePosition.equals(other.relativePosition)) {
          return false;
        }
        
                if (listeTK == null) {
          if (other.listeTK != null) {
            return false;
          }
        } else if (!listeTK.equals(other.listeTK)) {
          return false;
        }
            return true;
    
  }

  protected boolean hatAttribute() {
        return true;
      }

  @Override
  public String getEntityMessageKey() {
    return ListenkandidaturConstants.MESSAGE_KEY_ENTITY_EINZAHL;
  }

  @Override
  public java.util.List<de.ivu.elect.jee.entity.tk.EntityFieldValue> getAllEntityFieldValues() {
    java.util.List<de.ivu.elect.jee.entity.tk.EntityFieldValue> result = new java.util.ArrayList<>();

    result.addAll(super.getAllEntityFieldValues());
    result.addAll(getEntityFieldValuesForEntity());
    result.addAll(listeTK.getAllEntityFieldValues());
    return result;
  }

  @Override
  public java.util.List<de.ivu.elect.jee.entity.tk.EntityFieldValue> getEntityFieldValuesForEntity() {
            java.util.List<de.ivu.elect.jee.entity.tk.EntityFieldValue> result = new java.util.ArrayList<>();

                    result.add(new de.ivu.elect.jee.entity.tk.EntityFieldValue(ListenkandidaturConstants.MESSAGE_KEY_ENTITY_EINZAHL, ListenkandidaturConstants.MESSAGE_KEY_RELATIVE_POSITION_EINZAHL, relativePosition));
        
        return result;
      }


            @Override
            public String toString() {
            return "ListenkandidaturTK[" + toStringParameter() + "]";
            }



            protected String toStringParameter() {
            String result = ""

                                        +"relativePosition="+relativePosition
                                        +", listeTK="+listeTK
            
            ;
                            String resultParent = super.toStringParameter();
                if (resultParent.isEmpty()) {
                return result;
                }
                if (result.isEmpty()) {
                return resultParent;
                }
                return resultParent +", " + result;
            
            }


      @Override       protected String toStringLokalisiertFields(IMessages messages) {
        return ""
                                      + messages.getMessageForMessageKey(ListenkandidaturConstants.MESSAGE_KEY_RELATIVE_POSITION_EINZAHL) + "=" +

                                    relativePosition
                
                                      + ", " +  toStringLokalisiert(listeTK, messages)
                                      + super.toStringLokalisiertFields(messages)
                     ;
      }


            private String toStringLokalisiert(de.ivu.elect.jee.entity.tk.EntityTK entityTK, IMessages messages) {
                if (entityTK != null) {
                    return entityTK.toStringLokalisiert(messages);
                }
                return null;
            }

            public static <E extends Listenkandidatur> java.util.Map<ListenkandidaturTK, E> mappeListenkandidaturNachTK(java.util.Collection<E> entities) {
                return entities.stream().collect(java.util.stream.Collectors.toMap(Listenkandidatur::getListenkandidaturTK, Function.<E>identity(), (u,v)-> v));
                }


                public static Function<Listenkandidatur, ListenkandidaturTK> getListenkandidaturToTKFunction() {
                return Listenkandidatur::getListenkandidaturTK;
                }

}
