1
2
3
4
5
6
7
8
9
10
11
12
13 package org.gscg.singleuser.interactionlayer.business;
14
15 import java.io.Serializable;
16 import java.util.Comparator;
17
18 import nl.tudelft.simulation.logger.Logger;
19 import nl.tudelft.simulation.supplychain.product.Product;
20
21 /***
22 * A comparator to put products in an alfabetical order.
23 * <p>
24 * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
25 * Delft, the Netherlands. All rights reserved.
26 *
27 * See for project information <a href="http://www.simulation.tudelft.nl/">
28 * www.simulation.tudelft.nl </a>.
29 *
30 * The source code and binary code of this software is proprietary information
31 * of Delft University of Technology.
32 *
33 * @author <a
34 * href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
35 * van Houten </a>
36 * @version $Revision: 1.1 $ $Date: 2005/06/16 12:34:08 $
37 * @since 1.1.0
38 */
39 public class ProductComparator implements Comparator, Serializable
40 {
41 /*** the serial version uid */
42 private static final long serialVersionUID = 12L;
43
44 /***
45 * constructs a new ProductComparator
46 */
47 public ProductComparator()
48 {
49 super();
50 }
51
52 /***
53 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
54 */
55 public int compare(final Object o1, final Object o2)
56 {
57 try
58 {
59 Product product1 = (Product) o1;
60 Product product2 = (Product) o2;
61
62 int compare = new Integer(product1.getName().compareTo(
63 product2.getName())).intValue();
64 if (compare > 0)
65 {
66 return 1;
67 }
68 return -1;
69
70 } catch (Exception exception)
71 {
72 Logger.severe(this, "compare", exception);
73 }
74 return new Integer(o1.hashCode()).compareTo(new Integer(o2.hashCode()));
75 }
76 }