001 package data.swing; 002 003 import data.*; 004 005 /** 006 * DataBasketEntryGrouper that groups entries that have the same main and secondary key as well as the same 007 * source and destination and where both values contain an {@link Integer} object. These are DataBasketEntries 008 * that describe operations on CountingStock items. 009 * 010 * @author Steffen Zschaler 011 * @version 2.0 23/08/1999 012 * @since v2.0 013 */ 014 public class CountingStockDBEGrouper extends Object implements DataBasketEntryGrouper { 015 016 /** 017 * ID for serialization. 018 */ 019 private static final long serialVersionUID = 1122749969060192691L; 020 021 /** 022 * Create a new CountingStockDBEGrouper. 023 */ 024 public CountingStockDBEGrouper() { 025 super(); 026 } 027 028 /** 029 * Return true if <code>dbe1</code> and <code>dbe2</code> have the same main and secondary key as well as 030 * the same source and destination and both values contain an {@link Integer} object. 031 * 032 * @override Never 033 */ 034 public boolean canGroup(DataBasketEntry dbe1, DataBasketEntry dbe2) { 035 return ((dbe1.getMainKey().equals(dbe2.getMainKey())) && 036 (dbe1.getSecondaryKey().equals(dbe2.getSecondaryKey())) && 037 (dbe1.getSource() == dbe2.getSource()) && (dbe1.getDestination() == dbe2.getDestination()) && 038 (dbe1.getValue()instanceof Integer) && (dbe2.getValue()instanceof Integer)); 039 } 040 041 /** 042 * Return a new DataBasketEntry with the same main and secondary key, source and destination as 043 * <code>dbe1</code> and a value of <code>dbe1.getValue() + dbe2.getValue()</code>. 044 * 045 * <p>The returned DataBasketEntry cannot be used for commiting or rolling back operations.</p> 046 * 047 * @override Never 048 */ 049 public DataBasketEntry group(DataBasketEntry dbe1, DataBasketEntry dbe2) { 050 class DBE extends Object implements DataBasketEntry { 051 private String m_sMainKey; 052 private String m_sSecondaryKey; 053 private DataBasketEntrySource m_dbes; 054 private DataBasketEntryDestination m_dbed; 055 private Object m_oValue; 056 private DataBasket m_dbOwner = null; 057 058 public DBE(String sMainKey, String sSecondaryKey, DataBasketEntrySource dbes, 059 DataBasketEntryDestination dbed, Object oValue) { 060 super(); 061 062 m_sMainKey = sMainKey; 063 m_sSecondaryKey = sSecondaryKey; 064 m_dbes = dbes; 065 m_dbed = dbed; 066 m_oValue = oValue; 067 } 068 069 public void rollback() {} 070 071 public void commit() {} 072 073 public void setOwner(DataBasket dbOwner) { 074 m_dbOwner = dbOwner; 075 } 076 077 public DataBasket getOwner() { 078 return m_dbOwner; 079 } 080 081 public DataBasketEntrySource getSource() { 082 return m_dbes; 083 } 084 085 public DataBasketEntryDestination getDestination() { 086 return m_dbed; 087 } 088 089 public Object getValue() { 090 return m_oValue; 091 } 092 093 public String getMainKey() { 094 return m_sMainKey; 095 } 096 097 public String getSecondaryKey() { 098 return m_sSecondaryKey; 099 } 100 101 public boolean isHandled() { 102 return true; 103 } 104 } 105 106 return new DBE(dbe1.getMainKey(), dbe1.getSecondaryKey(), dbe1.getSource(), dbe1.getDestination(), 107 new Integer(((Integer)dbe1.getValue()).intValue() + ((Integer)dbe2.getValue()).intValue())); 108 } 109 }