content: package org.agoncal.application.petstore.domain;
  
  import javax.persistence.Column;
  import javax.persistence.Embeddable;
  import javax.persistence.EnumType;
  import javax.persistence.Enumerated;
  import javax.validation.constraints.NotNull;
  import javax.validation.constraints.Size;
  
  /**
   * @author Antonio Goncalves
   *         http://www.antoniogoncalves.org
   *         --
   */
  
  @Embeddable
  public class CreditCard {
  
      // ======================================
      // =             Attributes             =
      // ======================================
  
      @Column(name = "credit_card_number", length = 30)
      @NotNull
      @Size(min = 1, max = 30)
      private String creditCardNumber;
      @Column(name = "credit_card_type")
      @NotNull
      @Enumerated(EnumType.STRING)
      private CreditCardType creditCardType;
      @Column(name = "credit_card_expiry_date", length = 5)
      @NotNull
      @Size(min = 1, max = 5)
      private String creditCardExpDate;
  
      // ======================================
      // =            Constructors            =
      // ======================================
  
      public CreditCard() {
      }
  
      public CreditCard(String creditCardNumber, CreditCardType creditCardType, String creditCardExpDate) {
          this.creditCardNumber = creditCardNumber;
          this.creditCardType = creditCardType;
          this.creditCardExpDate = creditCardExpDate;
      }
  
      // ======================================
      // =         Getters & setters          =
      // ======================================
  
      public String getCreditCardNumber() {
          return creditCardNumber;
      }
  
      public void setCreditCardNumber(String creditCardNumber) {
          this.creditCardNumber = creditCardNumber;
      }
  
      public CreditCardType getCreditCardType() {
          return creditCardType;
      }
  
      public void setCreditCardType(CreditCardType creditCardType) {
          this.creditCardType = creditCardType;
      }
  
      public String getCreditCardExpDate() {
          return creditCardExpDate;
      }
  
      public void setCreditCardExpDate(String creditCardExpDate) {
          this.creditCardExpDate = creditCardExpDate;
      }
  
      // ======================================
      // =   Methods hash, equals, toString   =
      // ======================================
  
      @Override
      public boolean equals(Object o) {
          if (this == o) return true;
          if (!(o instanceof CreditCard)) return false;
  
          CreditCard that = (CreditCard) o;
  
          if (!creditCardNumber.equals(that.creditCardNumber)) return false;
  
          return true;
      }
  
      @Override
      public int hashCode() {
          return creditCardNumber.hashCode();
      }
  
      @Override
      public String toString() {
          final StringBuilder sb = new StringBuilder();
          sb.append("CreditCard");
          sb.append("{creditCardNumber='").append(creditCardNumber).append('\'');
          sb.append(", creditCardType=").append(creditCardType);
          sb.append(", creditCardExpDate='").append(creditCardExpDate).append('\'');
          sb.append('}');
          return sb.toString();
      }
  }