View Javadoc

1   /*
2    * @(#) XYSeriesComparator.java May 11, 2005
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 are proprietary information
11   * of Delft University of Technology.
12   */
13  package org.gscg.common.gui.statistics.components;
14  
15  import java.io.Serializable;
16  import java.util.Comparator;
17  
18  import nl.tudelft.simulation.jstats.charts.xy.XYSeries;
19  import nl.tudelft.simulation.logger.Logger;
20  
21  /***
22   * The XYSeriesComparator compares XYSeries based on their name and sorts them
23   * in alfabetical order.
24   * <p>
25   * (c) copyright 2005 <a href="http://www.simulation.tudelft.nl">Delft
26   * University of Technology </a>, the Netherlands. <br>
27   * See for project information <a
28   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
29   * 
30   * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
31   * Delft, the Netherlands. All rights reserved.
32   * 
33   * See for project information <a href="http://www.simulation.tudelft.nl/">
34   * www.simulation.tudelft.nl </a>.
35   * 
36   * The source code and binary code of this software are proprietary information
37   * of Delft University of Technology.
38   * 
39   * @author <a
40   *         href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
41   *         van Houten </a>
42   * @version $Revision: 1.1 $ $Date: 2005/06/16 12:33:54 $
43   * @since 1.1.3
44   */
45  public class XYSeriesComparator implements Comparator, Serializable
46  {
47  
48  	/***
49  	 * constructs a new XYSeriesComparator
50  	 */
51  	public XYSeriesComparator()
52  	{
53  		super();
54  	}
55  
56  	/***
57  	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
58  	 */
59  	public int compare(final Object o1, final Object o2)
60  	{
61  		try
62  		{
63  			XYSeries series1 = (XYSeries) o1;
64  			XYSeries series2 = (XYSeries) o2;
65  
66  			int compare = new Integer(series1.getSeriesName().compareTo(
67  					series2.getSeriesName())).intValue();
68  			if (compare > 0)
69  			{
70  				return 1;
71  			}
72  			return -1;
73  
74  		} catch (Exception exception)
75  		{
76  			Logger.severe(this, "compare", exception);
77  		}
78  		return new Integer(o1.hashCode()).compareTo(new Integer(o2.hashCode()));
79  	}
80  
81  }