Illustration.java

  1. /*
  2.  * The coLAB project
  3.  * Copyright (C) 2021-2023 AlbaSim, MEI, HEIG-VD, HES-SO
  4.  *
  5.  * Licensed under the MIT License
  6.  */
  7. package ch.colabproject.colab.api.model.common;

  8. import ch.colabproject.colab.generator.model.annotations.ExtractJavaDoc;
  9. import ch.colabproject.colab.generator.model.interfaces.WithJsonDiscriminator;
  10. import javax.persistence.Column;
  11. import javax.persistence.Embeddable;
  12. import javax.persistence.EnumType;
  13. import javax.persistence.Enumerated;
  14. import javax.validation.constraints.NotNull;
  15. import javax.validation.constraints.Size;
  16. import org.apache.commons.lang3.builder.EqualsBuilder;
  17. import org.apache.commons.lang3.builder.HashCodeBuilder;

  18. /**
  19.  * To store data of the illustration of some item.
  20.  * <p>
  21.  * It is a simple picture that illustrate a project or a card type.
  22.  *
  23.  * @author sandra
  24.  */
  25. @Embeddable
  26. @ExtractJavaDoc
  27. public class Illustration implements WithJsonDiscriminator {

  28.     private static final long serialVersionUID = 1L;

  29.     // ---------------------------------------------------------------------------------------------
  30.     // fields
  31.     // ---------------------------------------------------------------------------------------------

  32.     /**
  33.      * Which library of icons contains the key
  34.      */
  35.     @Column(length = 128)
  36.     @Enumerated(value = EnumType.STRING)
  37.     @NotNull
  38.     private IconLibrary iconLibrary = IconLibrary.MATERIAL_SYMBOLS_OUTLINED;

  39.     /**
  40.      * The key of the icon within the library of icons
  41.      */
  42.     @Size(max = 128)
  43.     @NotNull
  44.     private String iconKey;

  45.     /**
  46.      * The background color to set behind the icon
  47.      */
  48.     @Size(max = 64)
  49.     @NotNull
  50.     private String iconBkgdColor;

  51.     // ---------------------------------------------------------------------------------------------
  52.     // getters and setters
  53.     // ---------------------------------------------------------------------------------------------

  54.     /**
  55.      * @return which library of icons contains the key
  56.      */
  57.     public IconLibrary getIconLibrary() {
  58.         return iconLibrary;
  59.     }

  60.     /**
  61.      * @param iconLibrary which library of icons contains the key
  62.      */
  63.     public void setIconLibrary(IconLibrary iconLibrary) {
  64.         this.iconLibrary = iconLibrary;
  65.     }

  66.     /**
  67.      * @return the key of the icon within the library of icons
  68.      */
  69.     public String getIconKey() {
  70.         return iconKey;
  71.     }

  72.     /**
  73.      * @param iconKey the key of the icon within the library of icons
  74.      */
  75.     public void setIconKey(String iconKey) {
  76.         this.iconKey = iconKey;
  77.     }

  78.     /**
  79.      * @return the background color to set behind the icon
  80.      */
  81.     public String getIconBkgdColor() {
  82.         return iconBkgdColor;
  83.     }

  84.     /**
  85.      * @param iconBkgdColor the background color to set behind the icon
  86.      */
  87.     public void setIconBkgdColor(String iconBkgdColor) {
  88.         this.iconBkgdColor = iconBkgdColor;
  89.     }

  90.     // ---------------------------------------------------------------------------------------------
  91.     // concerning the whole class
  92.     // ---------------------------------------------------------------------------------------------

  93.     @Override
  94.     public int hashCode() {
  95.         return new HashCodeBuilder()
  96.             .append(this.iconLibrary)
  97.             .append(this.iconKey)
  98.             .append(this.iconBkgdColor)
  99.             .toHashCode();
  100.     }

  101.     @Override
  102.     public boolean equals(Object obj) {
  103.         if (this == obj) {
  104.             return true;
  105.         }
  106.         if (obj == null) {
  107.             return false;
  108.         }
  109.         if (getClass() != obj.getClass()) {
  110.             return false;
  111.         }
  112.         final Illustration other = (Illustration) obj;
  113.         return new EqualsBuilder()
  114.             .append(this.iconLibrary, other.iconLibrary)
  115.             .append(this.iconKey, other.iconKey)
  116.             .append(this.iconBkgdColor, other.iconBkgdColor)
  117.             .isEquals();
  118.     }

  119.     @Override
  120.     public String toString() {
  121.         return "Illustration{" + " iconLibrary=" + iconLibrary + ", iconKey=" + iconKey
  122.             + ", iconBkgdColor=" + iconBkgdColor + " }";
  123.     }

  124. }