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

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

@javax.enterprise.inject.Vetoed
public class PruefkriteriumTK
implements de.ivu.elect.jee.entity.tk.EntityTK, java.io.Serializable
  {

  private static final long serialVersionUID = 1L;

  private final int hashCode;

    protected final java.lang.Long position;
    public java.lang.Long getPosition(){
      return position;
    }
  protected final de.ivu.elect.business.wahl.entity.WahlTK wahlTK;
    public de.ivu.elect.business.wahl.entity.WahlTK getWahlTK(){
      return wahlTK;
    }

  public PruefkriteriumTK(
java.lang.Long position
,   de.ivu.elect.business.wahl.entity.WahlTK wahlTK
  ) {
    super();


      this.position = position;
        this.wahlTK = wahlTK;
  
hashCode = calculateHashCode();
  }

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


  protected int calculateHashCode() {
        int result = 1;
    
    
                    result = result + ((position == null) ? 0 : position.hashCode());
        
                    result = result + ((wahlTK == null) ? 0 : wahlTK.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 (getClass() != obj.getClass()) {
      if (!(obj instanceof PruefkriteriumTK)) {
        return false;
      }

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

    }

        PruefkriteriumTK other = (PruefkriteriumTK) obj;

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

  protected boolean hatAttribute() {
        return true;
      }

  @Override
  public String getEntityMessageKey() {
    return PruefkriteriumConstants.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(getEntityFieldValuesForEntity());
    result.addAll(wahlTK.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(PruefkriteriumConstants.MESSAGE_KEY_ENTITY_EINZAHL, PruefkriteriumConstants.MESSAGE_KEY_POSITION_EINZAHL, position));
        
        return result;
      }


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



            protected String toStringParameter() {
            String result = ""

                                        +"position="+position
                                        +", wahlTK="+wahlTK
            
            ;
                            return result;
            
            }
  
  @Override
  public String toStringLokalisiert(Messages messages) {
    return messages.getMessageForMessageKey(getEntityMessageKey()) + " ["
    + messages.getMessageForMessageKey(PruefkriteriumConstants.MESSAGE_KEY_POSITION_EINZAHL) + "=" + position
    + ", " +  toStringLokalisiert(wahlTK, messages)
                + "]"

            ;
  }

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

            public static <E extends Pruefkriterium> java.util.Map<PruefkriteriumTK, E> mappePruefkriteriumNachTK(java.util.Collection<E> entities) {
                return entities.stream().collect(java.util.stream.Collectors.toMap(Pruefkriterium::getPruefkriteriumTK, Function.<E>identity(), (u,v)-> v));
                }


                public static Function<Pruefkriterium, PruefkriteriumTK> getPruefkriteriumToTKFunction() {
                return Pruefkriterium::getPruefkriteriumTK;
                }

}
