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<CatalogItem>, Serializable { 013 /** 014 * ID for Serialization. 015 */ 016 private static final long serialVersionUID = -7793618990288671338L; 017 018 /** 019 * Constructs a new <code>ComparatorCurrency</code> 020 * 021 */ 022 public ComparatorCurrency() { 023 } 024 /** 025 * Compares <code>CatalogItemes</code> or <code>CountingStockTableModel.Records</code>. 026 * 027 * @return 0 if both objects are equal, a positive int if arg0 is greater than arg1, otherwise 028 * a negative int. 029 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) 030 */ 031 public int compare(CatalogItem arg0, CatalogItem arg1) { 032 if (arg0 instanceof CatalogItem) { 033 return ((CatalogItem) arg0).getValue().compareTo( 034 ((CatalogItem) arg1).getValue()); 035 } 036 if (arg0 instanceof CountingStockTableModel.Record) { 037 Value v1 = 038 ((CountingStockTableModel.Record) arg0) 039 .getDescriptor() 040 .getValue(); 041 Value v2 = 042 ((CountingStockTableModel.Record) arg1) 043 .getDescriptor() 044 .getValue(); 045 return v1.compareTo(v2); 046 } 047 return 0; 048 } 049 }