package nl.tudelft.simulation.examples.dsol.terminal; import nl.tudelft.simulation.event.EventProducer; import nl.tudelft.simulation.event.EventType; /** *

* Copyright (c) 2002-2018 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights * reserved. See for project information * https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can * be found at * https://simulation.tudelft.nl/dsol/3.0/license.html. *

* @author Peter Jacobs * @author Alexander Verbraeck */ public class Ship extends EventProducer { /** */ private static final long serialVersionUID = 1L; /** the number of loaded containers. */ private int containers = 0; /** the ship's capacity. */ private final int capacity; /** the ship-full event. */ public static final EventType SHIP_FULL_EVENT = new EventType("SHIP_FULL_EVENT"); /** * @param capacity int; the ship's capacity */ public Ship(final int capacity) { this.capacity = capacity; } /** * increase the number of containers and fire an event when full. */ public synchronized void incContainers() { this.containers++; if (this.containers >= this.capacity) { if (Terminal.DEBUG) { System.out.println("SHIP IS FULL -- EVENT FIRED"); } fireEvent(SHIP_FULL_EVENT, this.containers); } } /** * @return containers */ public final int getContainers() { return this.containers; } }