/*
 * Fachlicher Schlüssel für JPA Entität
 */
package de.ivu.elect.business.wahlvorschlag.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 ReferendumOptionTK
extends de.ivu.elect.business.wahlvorschlag.entity.WahlvorschlagTK
  {

  private static final long serialVersionUID = 1L;

  private final int hashCode;

    protected final java.lang.Long position;
    public java.lang.Long getPosition(){
      return position;
    }

  public ReferendumOptionTK(
java.lang.String discriminator
,   de.ivu.elect.business.gruppeimgebiet.entity.GruppeImGebietTK gruppeImGebietTK
, java.lang.Long position
  ) {
super(

discriminator

,   gruppeImGebietTK
);


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

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


  protected int calculateHashCode() {
        int result = super.calculateHashCode();
    
    
                    result = result + ((position == null) ? 0 : position.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 ReferendumOptionTK)) {
        return false;
      }

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

    }

        ReferendumOptionTK other = (ReferendumOptionTK) obj;

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

  protected boolean hatAttribute() {
        return true;
      }

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


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



            protected String toStringParameter() {
            String result = ""

                                        +"position="+position
                        
            ;
                            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(ReferendumOptionConstants.MESSAGE_KEY_POSITION_EINZAHL) + "=" + position
                                                  + 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 ReferendumOption> java.util.Map<ReferendumOptionTK, E> mappeReferendumOptionNachTK(java.util.Collection<E> entities) {
                return entities.stream().collect(java.util.stream.Collectors.toMap(ReferendumOption::getReferendumOptionTK, Function.<E>identity(), (u,v)-> v));
                }


                public static Function<ReferendumOption, ReferendumOptionTK> getReferendumOptionToTKFunction() {
                return ReferendumOption::getReferendumOptionTK;
                }

}
