001    package data;
002    
003    /**
004     * Basic implementation of the {@link DataBasketCondition} interface. You can use this
005     * class as a basis for implementing more sophisticated queries.
006     *
007     * @author Steffen Zschaler
008     * @version 2.0 14/06/1999
009     * @since v2.0
010     */
011    public class DataBasketConditionImpl<T> extends Object implements DataBasketCondition<T> {
012    
013        /**
014             * ID for serialization.
015             */
016            private static final long serialVersionUID = 3408012447279335129L;
017    
018            /**
019         * The source condition.
020         *
021         * @serial
022         */
023        protected DataBasketEntrySource m_dbesSource;
024    
025        /**
026         * The destination condition.
027         *
028         * @serial
029         */
030        protected DataBasketEntryDestination m_dbedDest;
031    
032        /**
033         * The main key condition.
034         *
035         * @serial
036         */
037        protected String m_sMainKey;
038    
039        /**
040         * The secondary key condition.
041         *
042         * @serial
043         */
044        protected String m_sSecondaryKey;
045    
046        /**
047         * The value condition.
048         *
049         * @serial
050         */
051        protected Object m_oValue;
052    
053        /**
054         * Create a new DataBasketConditionImpl.
055         *
056         * @param sMainKey the value for {@link #m_sMainKey}.
057         * @param sSecondaryKey the value for {@link #m_sSecondaryKey}.
058         * @param dbesSource the value for {@link #m_dbesSource}.
059         * @param dbedDest the value for {@link #m_dbedDest}.
060         * @param oValue the value for {@link #m_oValue}.
061         */
062        public DataBasketConditionImpl(String sMainKey, String sSecondaryKey, DataBasketEntrySource dbesSource,
063                DataBasketEntryDestination dbedDest, Object oValue) {
064            super();
065    
066            m_sMainKey = sMainKey;
067            m_sSecondaryKey = sSecondaryKey;
068            m_dbesSource = dbesSource;
069            m_dbedDest = dbedDest;
070            m_oValue = oValue;
071        }
072    
073        /**
074         * @return {@link #m_dbesSource}.
075         *
076         * @override Never Instead set the value of {@link #m_dbesSource}.
077         */
078        public DataBasketEntrySource getSource() {
079            return m_dbesSource;
080        }
081    
082        /**
083         * @return {@link #m_dbedDest}.
084         *
085         * @override Never Instead set the value of {@link #m_dbedDest}.
086         */
087        public DataBasketEntryDestination getDestination() {
088            return m_dbedDest;
089        }
090    
091        /**
092         * @return {@link #m_oValue}.
093         *
094         * @override Never Instead set the value of {@link #m_oValue}.
095         */
096        public Object getValue() {
097            return m_oValue;
098        }
099    
100        /**
101         * @return {@link #m_sMainKey}.
102         *
103         * @override Never Instead set the value of {@link #m_sMainKey}.
104         */
105        public String getMainKey() {
106            return m_sMainKey;
107        }
108    
109        /**
110         * @return {@link #m_sSecondaryKey}.
111         *
112         * @override Never Instead set the value of {@link #m_sSecondaryKey}.
113         */
114        public String getSecondaryKey() {
115            return m_sSecondaryKey;
116        }
117    
118        /**
119         * As a default, always returns true.
120         *
121         * @override Sometimes
122         */
123        public boolean match(DataBasketEntry<T> dbe) {
124            return true;
125        }
126    
127        // some static convenience functions and objects
128        /**
129         * A DataBasketCondition matching all items in a DataBasket.
130         */
131        public final static DataBasketCondition ALL_ENTRIES = new DataBasketConditionImpl(null, null, null, null, null);
132        /**
133         * A DataBasketCondition that matches all entries that describe StockItem movements.
134         */
135        public final static DataBasketCondition ALL_STOCK_ITEMS = new DataBasketConditionImpl(STOCK_ITEM_MAIN_KEY, null, null, null, null);
136    
137        /**
138         * A DataBasketCondition that matches all entries that describe CatalogItem movements.
139         */
140        public final static DataBasketCondition ALL_CATALOG_ITEMS = new DataBasketConditionImpl(
141                CATALOG_ITEM_MAIN_KEY, null, null, null, null);
142    
143        /**
144         * A DataBasketCondition that matches all entries that describe StockItems being taken from the
145         * given Stock.
146         */
147        public static final DataBasketCondition allStockItemsWithSource(Stock stSource) {
148            return new DataBasketConditionImpl(STOCK_ITEM_MAIN_KEY, null, stSource, null, null);
149        }
150    
151        /**
152         * A DataBasketCondition that matches all entries that describe StockItems being entered into the
153         * given Stock.
154         */
155        public static final DataBasketCondition allStockItemsWithDest(Stock stDest) {
156            return new DataBasketConditionImpl(STOCK_ITEM_MAIN_KEY, null, null, stDest, null);
157        }
158    
159        /**
160         * A DataBasketCondition that matches all entries that describe CatalogItems being taken from the
161         * given Catalog.
162         */
163        public static final DataBasketCondition allCatalogItemsWithSource(Catalog cSource) {
164            return new DataBasketConditionImpl(CATALOG_ITEM_MAIN_KEY, null, cSource, null, null);
165        }
166    
167        /**
168         * A DataBasketCondition that matches all entries that describe CatalogItems being entered into the
169         * given Catalog.
170         */
171        public static final DataBasketCondition allCatalogItemsWithDest(Catalog cDest) {
172            return new DataBasketConditionImpl(CATALOG_ITEM_MAIN_KEY, null, null, cDest, null);
173        }
174    
175        /**
176         * A DataBasketCondition that matches exactly one given CatalogItem.
177         */
178        public static final DataBasketCondition specificCatalogItem(CatalogItem ci) {
179            return new DataBasketConditionImpl(CATALOG_ITEM_MAIN_KEY, ci.getName(), null, null, ci);
180        }
181    
182        /**
183         * A DataBasketCondition that matches exactly one given StockItem.
184         */
185        public static final DataBasketCondition specificStockItem(StockItem si) {
186            return new DataBasketConditionImpl(STOCK_ITEM_MAIN_KEY, si.getName(), null, null, si);
187        }
188    }