Class Item

java.lang.Object
org.troy.capstone.entities.Item
All Implemented Interfaces:
Cloneable

public class Item extends Object implements Cloneable
A shopping item with various attributes. Main entity of the application. Implements cloneable to allow deep copy of ItemHashMap.
  • Field Details

    • faker

      private static final Faker faker
      Faker instance for generating random data.
    • id

      private String id
      Unique identifier for the item.
    • index

      private short index
      Index of the item in the collection.
    • imageUrl

      private String imageUrl
      URL of the item's image.
    • name

      private String name
      Name of the item.
    • publisher

      private String publisher
      Publisher of the item.
    • description

      private String description
      Description of the item.
    • category

      private String category
      Category of the item.
    • tags

      private Set<String> tags
      Tags associated with the item.
    • photoAuthor

      private String photoAuthor
      Author of the item's photo.
    • photoAuthorUrl

      private String photoAuthorUrl
      URL of the photo's author.
    • price

      private float price
      Price of the item.
    • reviewScore

      private float reviewScore
      Review score of the item.
    • reviewCount

      private short reviewCount
      Number of reviews for the item.
    • stockQuantity

      private short stockQuantity
      Quantity of the item in stock.
    • dateAdded

      private Date dateAdded
      Date the item was added to the collection.
    • JARO_WINKLER_SIMILARITY

      private static final JaroWinklerSimilarity JARO_WINKLER_SIMILARITY
      Jaro-Winkler similarity instance for calculating string similarity.
  • Constructor Details

    • Item

      private Item()
      Private constructor to prevent direct instantiation of the Item class and to satisfy a Javadoc warning.
  • Method Details

    • getAttribute

      public Object getAttribute(TableColumnName column)
      Returns the value of the specified attribute for this item. The attribute is determined by the provided TableColumnName enum value.
      Parameters:
      column - An enum value representing the attribute to retrieve from this item.
      Returns:
      The value of the specified attribute for this item, returned as an Object. The caller must cast result.
      Throws:
      IllegalArgumentException - If the provided column does not correspond to a valid attribute of the Item class.
      Preconditions:
      column is not null and corresponds to a valid attribute of the Item class.
    • randomItem

      @Deprecated public static Item randomItem()
      Deprecated.
      Used for testing purposes, not intended for production use.
      Generates a random Item object with realistic values for each attribute using the Faker library.
      Returns:
      A randomly generated Item object with all attributes populated with realistic random values.
    • fromRow

      public static Item fromRow(Row itemRow)
      Creates an Item object from a tablesaw Row. The Row must contain columns corresponding to the attributes of the Item class. The method of converting a LocalDate to a Date is sourced from [7].
      Parameters:
      itemRow - A Row from a tablesaw Table containing item info.
      Returns:
      An Item object created from the data in the provided Row.
      Preconditions:
      itemRow is not null and contains the expected columns for creating an Item (ID, Name, etc.).
    • similarity

      public float similarity(Item other)
      Calculates a similarity score between this item and another item based on shared attributes such as category, publisher, tags, and price. The similarity score is a float value between 0.0 and 1.0, where higher values indicate greater similarity.
      Parameters:
      other - The other Item to compare against this item for similarity.
      Returns:
      A float value representing the similarity between the two items.
    • clone

      public Object clone() throws CloneNotSupportedException
      Creates and returns a deep copy of this Item instance.
      Overrides:
      clone in class Object
      Returns:
      A deep copy of this Item instance.
      Throws:
      CloneNotSupportedException - if the Item cannot be cloned.