Class Category
java.lang.Object
com.goldenleaf.shop.model.Category
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 -
Method Summary
Modifier and TypeMethodDescriptionbooleanIndicates whether some other object is "equal to" this category.getId()Returns the unique identifier of this category.getName()Returns the name of this category.inthashCode()Returns a hash code value for the category.voidUpdates the name of this category.toString()Returns a string representation of the category.
-
Constructor Details
-
Category
public Category()Default constructor required by JPA. -
Category
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 isnullor blank (empty or whitespace-only)
-
-
Method Details
-
getId
Returns the unique identifier of this category.- Returns:
- the category ID, or
nullif not yet persisted
-
getName
Returns the name of this category.- Returns:
- the non-null, non-empty name of the category
-
setName
Updates the name of this category.The new name must not be
nullor blank. This method performs validation before assigning the value.- Parameters:
name- the new name for the category- Throws:
EmptyNameException- if the provided name isnull, empty, or consists only of whitespace
-
toString
-
equals
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. -
hashCode
public int hashCode()Returns a hash code value for the category.Consistent with
equals(Object)— based on the ID when available.
-