Class Category

java.lang.Object
com.goldenleaf.shop.model.Category

@Entity public class Category extends Object
Entity representing a product category in the online shop.

Categories are used to group similar Product items (e.g., "Electronics", "Clothing", "Books"). Each category has a unique auto-generated identifier and a non-empty name with a maximum length of 100 characters.

This is a simple JPA entity mapped to the database table named category. The id field is auto-incremented using the database's identity column strategy.

Since:
1.0
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor required by JPA.
    Constructs a new category with the specified name.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Indicates whether some other object is "equal to" this category.
    Returns the unique identifier of this category.
    Returns the name of this category.
    int
    Returns a hash code value for the category.
    void
    Updates the name of this category.
    Returns a string representation of the category.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Category

      public Category()
      Default constructor required by JPA.
    • Category

      public Category(String name) throws EmptyNameException
      Constructs a new category with the specified name.

      The name is validated immediately upon construction.

      Parameters:
      name - the name of the category
      Throws:
      EmptyNameException - if the name is null or blank (empty or whitespace-only)
  • Method Details

    • getId

      public Long getId()
      Returns the unique identifier of this category.
      Returns:
      the category ID, or null if not yet persisted
    • getName

      public String getName()
      Returns the name of this category.
      Returns:
      the non-null, non-empty name of the category
    • setName

      public void setName(String name) throws EmptyNameException
      Updates the name of this category.

      The new name must not be null or blank. This method performs validation before assigning the value.

      Parameters:
      name - the new name for the category
      Throws:
      EmptyNameException - if the provided name is null, empty, or consists only of whitespace
    • toString

      public String toString()
      Returns a string representation of the category.

      Useful for logging and debugging.

      Overrides:
      toString in class Object
      Returns:
      a string containing the category ID and name
    • equals

      public boolean equals(Object o)
      Indicates whether some other object is "equal to" this category.

      Two categories are considered equal if they have the same non-null ID. If ID is null, fallback to object reference comparison.

      Overrides:
      equals in class Object
      Parameters:
      o - the reference object with which to compare
      Returns:
      true if this object is the same as the obj argument; false otherwise
    • hashCode

      public int hashCode()
      Returns a hash code value for the category.

      Consistent with equals(Object) — based on the ID when available.

      Overrides:
      hashCode in class Object
      Returns:
      a hash code value for this object