Class Product

All Implemented Interfaces:
Comparable<Product>, Persistable<Product.ProductIdentifier>

@Entity public class Product extends AbstractAggregateRoot<Product.ProductIdentifier> implements Comparable<Product>
A product.
Author:
Paul Henke, Oliver Gierke
  • Constructor Details

    • Product

      public Product(String name, javax.money.MonetaryAmount price)
      Creates a new Product with the given name and price.
      Parameters:
      name - must not be null or empty.
      price - must not be null.
    • Product

      public Product(String name, javax.money.MonetaryAmount price, Metric metric)
      Creates a new Product with the given name, price and Metric.
      Parameters:
      name - the name of the Product, must not be null or empty.
      price - the price of the Product, must not be null.
      metric - the Metric of the Product, must not be null.
    • Product

      @Deprecated protected Product()
      Deprecated.
  • Method Details

    • getId

      public Product.ProductIdentifier getId()
      Returns the unique id of this Product.
      Specified by:
      getId in interface Persistable<Product.ProductIdentifier>
      Returns:
      will never be null
    • getCategories

      public Streamable<String> getCategories()
      Returns the categories the Product is assigned to.
      Returns:
      will never be null.
    • addCategory

      public final boolean addCategory(String category)
      Adds the Product to the given category.
      Parameters:
      category - must not be null or empty.
      Returns:
    • removeCategory

      public final boolean removeCategory(String category)
    • supports

      public boolean supports(Quantity quantity)
      Returns whether the Product supports the given Quantity.
      Parameters:
      quantity -
      Returns:
    • verify

      public void verify(Quantity quantity)
      Verifies the given Quantity to match the one supported by the current Product.
      Parameters:
      quantity -
      Throws:
      MetricMismatchException - in case the Product does not support the given Quantity.
    • createQuantity

      public Quantity createQuantity(double amount)
      Creates a Quantity of the given amount and the current Product's underlying Metric.
      Parameters:
      amount - must not be null.
      Returns:
    • createQuantity

      public Quantity createQuantity(long amount)
      Creates a Quantity of the given amount and the current Product's underlying Metric.
      Parameters:
      amount - must not be null.
      Returns:
    • compareTo

      public int compareTo(Product other)
      Specified by:
      compareTo in interface Comparable<Product>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getName

      @NonNull public @NonNull String getName()
    • setName

      public Product setName(@NonNull @NonNull String name)
      Returns:
      this.
    • getPrice

      @NonNull public @NonNull javax.money.MonetaryAmount getPrice()
    • setPrice

      public Product setPrice(@NonNull @NonNull javax.money.MonetaryAmount price)
      Returns:
      this.