Interface ProductStorage

    • Method Detail

      • hasProduct

        boolean hasProduct​(ProductId id)
                    throws java.lang.Exception
        A method to check whether a product is already in storage. Implementers should define this method as more than "getProduct(id) != null" when it is significantly less expensive to check whether a product exists, compared to loading a product from storage.
        Parameters:
        id - the product to check.
        Returns:
        true if the product is in this storage, false otherwise.
        Throws:
        java.lang.Exception - if an error occurs while checking.
      • getProduct

        Product getProduct​(ProductId id)
                    throws java.lang.Exception
        Retrieve a stored product. May be implemented as
         return ObjectProductHandler.getProduct(getProductInput(id));
         
        Parameters:
        id - which product to retrieve.
        Returns:
        the retrieved product, or null if the product isn't in storage.
        Throws:
        java.lang.Exception - if errors occur while retrieving product.
      • storeProduct

        ProductId storeProduct​(Product product)
                        throws java.lang.Exception
        Store a product. May be implemented as
         return storeProductSource(new ObjectProductInput(product));
         
        Parameters:
        product - the product to store.
        Returns:
        the stored product's id.
        Throws:
        java.lang.Exception - if errors occur while storing product.
      • getProductSource

        ProductSource getProductSource​(ProductId id)
                                throws java.lang.Exception
        Retrieve a ProductSource for a stored product.
        Parameters:
        id - which product to retrieve.
        Returns:
        a ProductInput for the stored product, or null if not in storage.
        Throws:
        java.lang.Exception - if any errors occur while getting the ProductInput.
      • storeProductSource

        ProductId storeProductSource​(ProductSource input)
                              throws java.lang.Exception
        Store a ProductSource.
        Parameters:
        input - the product to store.
        Returns:
        the stored product's id.
        Throws:
        java.lang.Exception - if errors occur while storing product.
      • removeProduct

        void removeProduct​(ProductId id)
                    throws java.lang.Exception
        Remove a Product from storage, if it exists.
        Parameters:
        id - which product to remove.
        Throws:
        java.lang.Exception - if errors occur while removing product.
      • notifyListeners

        void notifyListeners​(StorageEvent event)
        Notifies StorageListeners of the change to the ProductStorage.
        Parameters:
        event - StorageEvent
      • addStorageListener

        void addStorageListener​(StorageListener listener)
        Adds a StorageListener to be notified when a change occurs in this ProductStorage.
        Parameters:
        listener - The listener to notify of changes.
      • removeStorageListener

        void removeStorageListener​(StorageListener listener)
        Removes a StorageListener from being notified when a change occurs in this ProductStorage.
        Parameters:
        listener - The listener to remove