Record Class FactoryBrick

java.lang.Object
java.lang.Record
fr.univ_eiffel.legotools.model.FactoryBrick
Record Components:
name - Le nom technique composite (ex: "2-2/c9cae2").
serial - Le numéro de série unique (encodant la date de fabrication).
certificate - La signature numérique (Ed25519) prouvant que la brique vient bien de l'usine.

public record FactoryBrick(String name, String serial, String certificate) extends Record
Représente un actif numérique "Brique" tel que livré par l'usine.

Garantit que les données sont immuables (inchangeables). Cette classe représente la forme physique, mais aussi son identité unique (numéro de série) et sa preuve d'authenticité (certificat cryptographique).

  • Constructor Details

    • FactoryBrick

      public FactoryBrick(String name, String serial, String certificate)
      Creates an instance of a FactoryBrick record class.
      Parameters:
      name - the value for the name record component
      serial - the value for the serial record component
      certificate - the value for the certificate record component
  • Method Details

    • color

      public String color()
      Extrait le code couleur hexadécimal du nom composite.

      Le format attendu de l'API est "Forme/Couleur" (ex: "2x4_Plate/FF0000").

      Returns:
      Le code hexadécimal (ex: "FF0000") ou "000000" (Noir) par défaut si le format est invalide.
    • shapeName

      public String shapeName()
      Extrait l'identifiant de la forme (Shape) du nom composite.
      Returns:
      Le nom de la forme sans la couleur.
    • getManufacturingDateInfo

      public String getManufacturingDateInfo()
      Décode la date de fabrication cachée dans le numéro de série.

      Le numéro de série n'est pas aléatoire, ses 5 premiers octets suivent un protocole précis :

      • Octets 0-1 (16 bits) : Nombre de jours écoulés depuis le 01/01/2000.
      • Octets 2-4 (24 bits) : Nombre de millisecondes écoulées depuis minuit.

      On utilise des opérations bit à bit (shifters) pour reconstruire ces nombres.

      Returns:
      Une chaîne lisible (ex: "2023-10-15 à 14:30:00") ou "Date invalide".
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • serial

      public String serial()
      Returns the value of the serial record component.
      Returns:
      the value of the serial record component
    • certificate

      public String certificate()
      Returns the value of the certificate record component.
      Returns:
      the value of the certificate record component