KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > golfShop > business > cart > CartItemPairImpl


1 /*
2  * Enhydra Java Application Server
3  * The Initial Developer of the Original Code is Lutris Technologies Inc.
4  * Portions created by Lutris are Copyright (C) 1997-2000 Lutris Technologies
5  * Inc.
6  * All Rights Reserved.
7  *
8  * The contents of this file are subject to the Enhydra Public License Version
9  * 1.0 (the "License"); you may not use this file except in compliance with the
10  * License. You may obtain a copy of the License at
11  * http://www.enhydra.org/software/license/epl.html
12  *
13  * Software distributed under the License is distributed on an "AS IS" basis,
14  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
15  * License for the specific language governing rights and limitations under the
16  * License.
17  *
18  *
19  */

20
21 /**
22  * This class is used to associate quantities with items. When you ask the
23  * cart for it's contents, you get an enumeration of these objects. The cart
24  * object its self also uses these objects, thus the use of protected methods.
25 */

26 package golfShop.business.cart;
27
28 import java.lang.Cloneable JavaDoc;
29 import golfShop.business.item.*;
30 import golfShop.spec.cart.*;
31
32 import golfShop.business.item.*;
33
34 public class CartItemPairImpl implements CartItemPair,java.io.Serializable JavaDoc{
35     private CartItem item;
36     private int quantity;
37
38     // Constructor. Only my package-mates can create me.
39
protected CartItemPairImpl(CartItem item, int quantity) {
40         this.item = item;
41         this.quantity = quantity;
42     }
43     
44     public CartItem getItem() {
45         return item;
46     }
47
48     public int getQuantity() {
49         return quantity;
50     }
51
52     // Only my package-mates can modify me.
53
protected void setQuantity(int quantity) {
54         this.quantity = quantity;
55     }
56
57     // Only my package-mates can modify me.
58
protected void addToQuantity(int more) {
59         this.quantity += more;
60     }
61
62     // Make a copy of ourselfs. Both coppies will point to the same
63
// CartItem, but they will have distinct quantaties.
64
protected CartItemPairImpl copy() {
65         return new CartItemPairImpl(this.item, this.quantity);
66     }
67
68     /**
69      * Generate information for debugging.
70      */

71     public String JavaDoc toString() {
72         return item.toString() + "(" + quantity + ")";
73     }
74 }
75
76
Popular Tags