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

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

@javax.enterprise.inject.Vetoed
public class WertelistenTK
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.String name;
    public java.lang.String getName(){
      return name;
    }
    protected final de.ivu.elect.business.wertelisten.entity.WertelistenArt wertelistenArt;
    public de.ivu.elect.business.wertelisten.entity.WertelistenArt getWertelistenArt(){
      return wertelistenArt;
    }

  public WertelistenTK(
java.lang.String name
, de.ivu.elect.business.wertelisten.entity.WertelistenArt wertelistenArt
  ) {
    super();


      this.name = name;
      this.wertelistenArt = wertelistenArt;
    
hashCode = calculateHashCode();
  }

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


  protected int calculateHashCode() {
        int result = 1;
    
    
                    result = result + ((name == null) ? 0 : name.hashCode());
                    result = result + ((wertelistenArt == null) ? 0 : wertelistenArt.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 WertelistenTK)) {
        return false;
      }

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

    }

        WertelistenTK other = (WertelistenTK) obj;

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

  protected boolean hatAttribute() {
        return true;
      }

  @Override
  public String getEntityMessageKey() {
    return WertelistenConstants.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());
    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(WertelistenConstants.MESSAGE_KEY_ENTITY_EINZAHL, WertelistenConstants.MESSAGE_KEY_NAME_EINZAHL, name));
                    result.add(new de.ivu.elect.jee.entity.tk.EntityFieldValue(WertelistenConstants.MESSAGE_KEY_ENTITY_EINZAHL, WertelistenConstants.MESSAGE_KEY_WERTELISTEN_ART_EINZAHL, wertelistenArt));
        
        return result;
      }


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



            protected String toStringParameter() {
            String result = ""

                                        +"name="+name
                            +", wertelistenArt="+wertelistenArt
                        
            ;
                            return result;
            
            }

  @Override
  public String toStringLokalisiert(Messages messages) {
    return messages.getMessageForMessageKey(getEntityMessageKey()) + " ["
            + toStringLokalisiertFields(messages)
            + "]"
            ;
   }

            protected String toStringLokalisiertFields(Messages messages) {
        return ""
                                      + messages.getMessageForMessageKey(WertelistenConstants.MESSAGE_KEY_NAME_EINZAHL) + "=" + name
                          + ", " + messages.getMessageForMessageKey(WertelistenConstants.MESSAGE_KEY_WERTELISTEN_ART_EINZAHL) + "=" + wertelistenArt
                                             ;
      }


            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 Wertelisten> java.util.Map<WertelistenTK, E> mappeWertelistenNachTK(java.util.Collection<E> entities) {
                return entities.stream().collect(java.util.stream.Collectors.toMap(Wertelisten::getWertelistenTK, Function.<E>identity(), (u,v)-> v));
                }


                public static Function<Wertelisten, WertelistenTK> getWertelistenToTKFunction() {
                return Wertelisten::getWertelistenTK;
                }

}
