View Javadoc

1   /*
2    * @(#)InteractiveQuoteHandler.java Jul 11, 2004
3    * 
4    * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
5    * Delft, the Netherlands. All rights reserved.
6    * 
7    * See for project information <a href="http://www.simulation.tudelft.nl/">
8    * www.simulation.tudelft.nl </a>.
9    * 
10   * The source code and binary code of this software is proprietary information
11   * of Delft University of Technology.
12   */
13  package org.gscg.singleuser.handlers;
14  
15  import java.io.Serializable;
16  import java.util.HashSet;
17  import java.util.Set;
18  
19  import nl.tudelft.simulation.supplychain.actor.SupplyChainActor;
20  import nl.tudelft.simulation.supplychain.content.Quote;
21  import nl.tudelft.simulation.supplychain.handlers.SupplyChainHandler;
22  
23  /***
24   * An Interactive Quote Handler. <br>
25   * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
26   * Delft, the Netherlands. All rights reserved.
27   * 
28   * See for project information <a href="http://www.simulation.tudelft.nl/">
29   * www.simulation.tudelft.nl </a>.
30   * 
31   * The source code and binary code of this software is proprietary information
32   * of Delft University of Technology.
33   * 
34   * @author <a
35   *         href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
36   *         Verbraeck </a>
37   * @version $Revision: 1.1 $ $Date: 2005/06/16 12:33:56 $
38   * @since 1.0.0
39   */
40  public class InteractiveQuoteHandler extends SupplyChainHandler
41  {
42  	/*** the serial version uid */
43  	private static final long serialVersionUID = 11L;
44  
45  	// TODO make non persistent solution, as this will gradually fill the memory
46  	// of the JVM
47  	/*** a set of internal demand IDs for which we already answered */
48  	private Set answeredIDs = null;
49  
50  	/***
51  	 * Constructor of the empty interactive QuoteHandler
52  	 * 
53  	 * @param owner the actor for this QuoteHandler.
54  	 */
55  	public InteractiveQuoteHandler(final SupplyChainActor owner)
56  	{
57  		super(owner);
58  		this.answeredIDs = new HashSet();
59  	}
60  
61  	/***
62  	 * @see nl.tudelft.simulation.supplychain.handlers.SupplyChainHandler#checkContentClass(java.io.Serializable)
63  	 */
64  	protected boolean checkContentClass(final Serializable content)
65  	{
66  		return (content instanceof Quote);
67  	}
68  
69  	/***
70  	 * @see nl.tudelft.simulation.content.HandlerInterface#handleContent(java.io.Serializable)
71  	 */
72  	public boolean handleContent(final Serializable content)
73  	{
74  		boolean result = !this.answeredIDs.contains(((Quote) content)
75  				.getInternalDemandID());
76  
77  		return result;
78  	}
79  
80  	/***
81  	 * @param quote the quote
82  	 */
83  	public void addAnsweredQuote(final Quote quote)
84  	{
85  		this.answeredIDs.add(quote.getInternalDemandID());
86  	}
87  }