content: package org.agoncal.book.javaee7.chapter03.ex10;
  
  import javax.validation.constraints.DecimalMin;
  import javax.validation.constraints.Max;
  import javax.validation.constraints.NotNull;
  import javax.validation.constraints.Pattern;
  
  /**
   * @author Antonio Goncalves
   *         APress Book - Beginning Java EE 7 with Glassfish 4
   *         http://www.apress.com/
   *         http://www.antoniogoncalves.org
   *         --
   */
  public class CD10 extends Item10 {
  
    // ======================================
    // =             Attributes             =
    // ======================================
  
    @Pattern(regexp = "[A-Z][a-z]{1,}", message = "{music.company}")
    private String musicCompany;
    @Max(value = 5, message = "{number.cds}")
    private Integer numberOfCDs;
    private Float totalDuration;
    @MusicGenre
    private String genre;
  
    // ======================================
    // =            Constructors            =
    // ======================================
  
    public CD10() {
    }
  
    public CD10(String title, Float price, String description, String musicCompany, Integer numberOfCDs, Float totalDuration, String genre) {
      super(title, price, description);
      this.musicCompany = musicCompany;
      this.numberOfCDs = numberOfCDs;
      this.totalDuration = totalDuration;
      this.genre = genre;
    }
  
    // ======================================
    // =           Public Methods           =
    // ======================================
  
    @NotNull
    @DecimalMin("5.8")
    public Float calculatePrice(Float rate) {
      return price * rate;
    }
  
    // ======================================
    // =          Getters & Setters         =
    // ======================================
  
    public String getMusicCompany() {
      return musicCompany;
    }
  
    public void setMusicCompany(String musicCompany) {
      this.musicCompany = musicCompany;
    }
  
    public Integer getNumberOfCDs() {
      return numberOfCDs;
    }
  
    public void setNumberOfCDs(Integer numberOfCDs) {
      this.numberOfCDs = numberOfCDs;
    }
  
    public Float getTotalDuration() {
      return totalDuration;
    }
  
    public void setTotalDuration(Float totalDuration) {
      this.totalDuration = totalDuration;
    }
  
    public String getGenre() {
      return genre;
    }
  
    public void setGenre(String genre) {
      this.genre = genre;
    }
  
    // ======================================
    // =         hash, equals, toString     =
    // ======================================
  
    @Override
    public String toString() {
      final StringBuilder sb = new StringBuilder();
      sb.append("CD");
      sb.append("{id=").append(id);
      sb.append(", title='").append(title).append('\'');
      sb.append(", price=").append(price);
      sb.append(", description='").append(description).append('\'');
      sb.append(", musicCompany='").append(musicCompany).append('\'');
      sb.append(", numberOfCDs=").append(numberOfCDs);
      sb.append(", totalDuration=").append(totalDuration);
      sb.append(", genre='").append(genre).append('\'');
      sb.append('}');
      return sb.toString();
    }
  }
  