01: /*
02: * Enhydra Java Application Server
03: * The Initial Developer of the Original Code is Lutris Technologies Inc.
04: * Portions created by Lutris are Copyright (C) 1997-2000 Lutris Technologies
05: * Inc.
06: * All Rights Reserved.
07: *
08: * The contents of this file are subject to the Enhydra Public License Version
09: * 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: */package golfShop.business.cart;
26:
27: import java.lang.Cloneable;
28: import golfShop.business.item.*;
29: import golfShop.spec.cart.*;
30:
31: import golfShop.business.item.*;
32:
33: public class CartItemPairImpl implements CartItemPair,
34: java.io.Serializable {
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 toString() {
72: return item.toString() + "(" + quantity + ")";
73: }
74: }
|