001    package videoautomat;
002    import java.io.Serializable;
003    import java.util.Comparator;
004    
005    import data.CatalogItem;
006    import data.Value;
007    import data.swing.CountingStockTableModel;
008    
009    /**
010     * Comparator used to compare <code>NumberValues</code> of <code>CatalogItems</code> and <code>CountingStockTableModel.Records</code>
011     */
012    public class ComparatorCurrency implements Comparator, Serializable {
013            /**
014             * Constructs a new <code>ComparatorCurrency</code>
015             *  
016             */
017            public ComparatorCurrency() {
018            }
019            /**
020             * Compares <code>CatalogItemes</code> or <code>CountingStockTableModel.Records</code>.
021             * 
022             * @return 0 if both objects are equal, a positive int if arg0 is greater than arg1, otherwise
023             *              a negative int.
024             * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
025             */
026            public int compare(Object arg0, Object arg1) {
027                    if (arg0 instanceof CatalogItem) {
028                            return ((CatalogItem) arg0).getValue().compareTo(
029                                    ((CatalogItem) arg1).getValue());
030                    }
031                    if (arg0 instanceof CountingStockTableModel.Record) {
032                            Value v1 =
033                                    ((CountingStockTableModel.Record) arg0)
034                                            .getDescriptor()
035                                            .getValue();
036                            Value v2 =
037                                    ((CountingStockTableModel.Record) arg1)
038                                            .getDescriptor()
039                                            .getValue();
040                            return v1.compareTo(v2);
041                    }
042                    return 0;
043            }
044    }