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<T> implements Comparator<T>, Serializable { 013 /** 014 * Constructs a new <code>ComparatorCurrency</code> 015 * 016 */ 017 public ComparatorCurrency() { 018 } 019 /** 020 * Compares <code>CatalogItems</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(T arg0, T arg1) { 027 if (arg0 instanceof CatalogItem) { 028 return ((CatalogItem) arg0).getValue().compareTo( 029 ((CatalogItem) arg1).getValue()); 030 } 031 // überhaupt notwendig? 032 if (arg0 instanceof CountingStockTableModel.Record) { 033 Value v1 = 034 ((CountingStockTableModel.Record) arg0) 035 .getDescriptor() 036 .getValue(); 037 Value v2 = 038 ((CountingStockTableModel.Record) arg1) 039 .getDescriptor() 040 .getValue(); 041 return v1.compareTo(v2); 042 } 043 return 0; 044 } 045 }