/** Adds an uninitialized component to the brewery. * It will be possible to lookup this component by all it's * superclasses and interfaces it implements. * @throws RuntimeException if component is null */ public void ingredient(Object component) { Exceptions.checkNotNullParameter(component, "component"); String name = component.getClass().getName(); alias(name, component.getClass()); ingredient(component, name); if (component instanceof Stoppable) { addStoppable((Stoppable) component); } }
/** Adds a factory to the brewery that will be able to * create components when it's requested by name. * The supplier will be {@link Supplier#supply(Brewery) asked} * to instantiate a component when it's being retrieved from * the brewery, aka lazy initialization. * @throws RuntimeException if supplier is null * @throws RuntimeException if name is null */ public void supplier(Supplier supplier, String name) { Exceptions.checkNotNullParameter(supplier, "supplier"); Exceptions.checkNotNullParameter(name, "name"); suppliers.put(name, supplier); if (supplier instanceof Stoppable) { addStoppable((Stoppable) supplier); } }
/** Adds an initialized component to the brewery * under the given name. * @throws RuntimeException if component is null * @throws RuntimeException if name is null */ public void beer(Object component, String name) { Exceptions.checkNotNullParameter(component, "component"); Exceptions.checkNotNullParameter(name, "name"); beers.put(name, component); if (component instanceof Brewable) { ((Brewable)component).brew(this); } if (component instanceof Stoppable) { addStoppable((Stoppable) component); } }