package com.company; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.util.ArrayList; import java.util.List; public class RepositoryObservable { private List products = new ArrayList<>(10); private List consumers = new ArrayList<>(); private List manufacturers = new ArrayList<>(); private PropertyChangeSupport notify; public RepositoryObservable(){ notify = new PropertyChangeSupport(this); } public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener){ notify.addPropertyChangeListener(propertyChangeListener); } public void addConsumer(ConsumerObserver consumer){ consumers.add(consumer); } public void addManufacturer(ManufacturerObserver manufacturer){ manufacturers.add(manufacturer); } public List getProducts() { return products; } public void addProduct(int id){ if(products.size() < 10){ products.add(id); } } public boolean hasSpace(){ boolean state = products.size() < 10; notify.firePropertyChange("hasSpace", false, state); return state; } public boolean hasProducts(){ boolean state = !products.isEmpty(); notify.firePropertyChange("hasProducts", false, state); return state; } }