View Javadoc

1   /*
2    * @(#) Renderable2DComparator.java Apr 28, 2004
3    * 
4    * Copyright (c) 2002-2005 Delft University of Technology Jaffalaan 5, 2628 BX
5    * Delft, the Netherlands. All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the Lesser General Public License
9    */
10  package nl.tudelft.simulation.dsol.gui.animation2D;
11  
12  import java.util.Comparator;
13  
14  import nl.tudelft.simulation.dsol.animation.D2.Renderable2DInterface;
15  import nl.tudelft.simulation.logger.Logger;
16  
17  /***
18   * <p>
19   * (c) copyright 2002-2005 <a href="http://www.simulation.tudelft.nl">Delft
20   * University of Technology </a>, the Netherlands. <br>
21   * See for project information <a
22   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
23   * License of use: <a href="http://www.gnu.org/copyleft/lesser.html">Lesser
24   * General Public License (LGPL) </a>, no warranty.
25   * 
26   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
27   *         Jacobs </a>
28   * @version $Revision$ $Date$
29   * @since 1.4
30   */
31  public class Renderable2DComparator implements Comparator
32  {
33  
34  	/***
35  	 * constructs a new Renderable2DComparator
36  	 */
37  	public Renderable2DComparator()
38  	{
39  		super();
40  	}
41  
42  	/***
43  	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
44  	 */
45  	public int compare(final Object o1, final Object o2)
46  	{
47  		try
48  		{
49  			Renderable2DInterface r1 = (Renderable2DInterface) o1;
50  			Renderable2DInterface r2 = (Renderable2DInterface) o2;
51  			if (r1.getSource().getLocation().z > r2.getSource().getLocation().z)
52  			{
53  				return 1;
54  			}
55  			if (r1.getSource().getLocation().z < r2.getSource().getLocation().z)
56  			{
57  				return -1;
58  			}
59  
60  		} catch (Exception exception)
61  		{
62  			Logger.warning(this, "compare", exception);
63  		}
64  		return new Integer(o1.hashCode()).compareTo(new Integer(o2.hashCode()));
65  	}
66  }