KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > j2ee > blueprints > consumerwebsite > Cart


1 /*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistribution in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * Neither the name of Sun Microsystems, Inc. or the names of
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * This software is provided "AS IS," without a warranty of any
21 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
22 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
24 * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
25 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
26 * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
27 * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
28 * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
29 * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
30 * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
31 * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 *
33 * You acknowledge that Software is not designed, licensed or intended
34 * for use in the design, construction, operation or maintenance of
35 * any nuclear facility.
36 */

37
38 package com.sun.j2ee.blueprints.consumerwebsite;
39
40 import java.util.*;
41
42 /**
43  * This class is used to represent the total package .
44  */

45 public class Cart implements java.io.Serializable JavaDoc {
46     
47     private HashMap activities;
48     private String JavaDoc packageId;
49     private String JavaDoc lodgingId;
50     private String JavaDoc destination;
51     private String JavaDoc departureFlight;
52     private String JavaDoc returnFlight;
53     private String JavaDoc origin;
54     private boolean configurationComplete = false;
55     private int headCount;
56     private int adventureDays =0;
57     private int lodgingDays = 0;
58     private int lodgingRoomCount = 0;
59     private Calendar departureDate = Calendar.getInstance();
60     private Calendar returnDate = Calendar.getInstance();
61     
62     /** Creates a new instance of AdventurePackage */
63     public Cart() {
64     }
65     
66     public void addActivity(String JavaDoc itemId) {
67        addActivity(itemId,1);
68     }
69     
70     public void addActivity(String JavaDoc itemId, int qty) {
71         if (activities == null) {
72             activities = new HashMap();
73         }
74         if (activities.containsKey(itemId)) {
75             activities.remove(itemId);
76         }
77         activities.put(itemId, new Integer JavaDoc(qty));
78     }
79     
80     public HashMap getActivities() {
81         return activities;
82     }
83     
84     public int getActivityCount() {
85         if (activities == null) return 0;
86         return activities.size();
87     }
88   
89     public void setActivityHeadCount(String JavaDoc itemId,
90                                     int quantity) {
91         if ((activities != null) && activities.containsKey(itemId)) {
92             activities.remove(itemId);
93             if (quantity > 0) activities.put(itemId, new Integer JavaDoc(quantity));
94         }
95     }
96     
97     public void setLodgingId(String JavaDoc lodgingId) {
98         this.lodgingId = lodgingId;
99     }
100     
101     public String JavaDoc getLodgingId() {
102         return lodgingId;
103     }
104     
105     public int getLodgingRoomCount() {
106         return lodgingRoomCount;
107     }
108     
109     public void setLodgingRoomCount(int lodgingRoomCount) {
110         this.lodgingRoomCount = lodgingRoomCount;
111     }
112     
113     public void setDepartureFlight(String JavaDoc departureFlight) {
114         this.departureFlight = departureFlight;
115     }
116     
117     public String JavaDoc getDepartureFlight() {
118         return departureFlight;
119     }
120     
121     public void setReturnFlight(String JavaDoc returnFlight) {
122         this.returnFlight = returnFlight;
123     }
124     
125     public String JavaDoc getReturnFlight() {
126         return returnFlight;
127     }
128     
129     public void setOrigin(String JavaDoc origin) {
130         this.origin = origin;
131     }
132     
133     public String JavaDoc getOrigin() {
134        return origin;
135     }
136     
137     public void setPackageId(String JavaDoc packageId) {
138         this.packageId = packageId;
139     }
140     
141     public String JavaDoc getPackageId() {
142         return packageId;
143     }
144
145     public void setDestination(String JavaDoc destination) {
146         this.destination = destination;
147     }
148     
149     public String JavaDoc getDestination() {
150         return destination;
151     }
152     
153     public int getHeadCount() {
154         return headCount;
155     }
156     
157     public void setAdventureDays(int adventureDays) {
158         this.adventureDays = adventureDays;
159         // set the lodging days to one less than the adventure days
160
this.lodgingDays = adventureDays - 1;
161     }
162     
163     public int getAdventureDays() {
164         return adventureDays;
165     }
166     
167     public int getLodgingDays() {
168         return lodgingDays;
169     }
170     
171     public void setLodgingDays(int lodgingDays) {
172         this.lodgingDays = lodgingDays;
173     }
174     
175     public void setHeadCount(int headCount) {
176         this.headCount = headCount;
177     }
178     
179     public Collection getActivityIds() {
180         if (activities == null) return null;
181         return activities.keySet();
182     }
183     
184     public Collection getValues() {
185         if (activities == null) return null;
186         return activities.values();
187     }
188     
189     public Calendar getDepartureDate() {
190         return departureDate;
191     }
192     
193     public void setDepartureDate(Calendar departureDate) {
194         this.departureDate = departureDate;
195     }
196     
197     public Calendar getReturnDate() {
198         return returnDate;
199     }
200     
201     public void setReturnDate(Calendar returnDate) {
202         this.returnDate = returnDate;
203     }
204     
205     public boolean isConfigurationComplete() {
206         return configurationComplete;
207     }
208     
209     public void setConfigurationComplete(boolean configurationComplete) {
210         this.configurationComplete = configurationComplete;
211     }
212     
213     public void clear() {
214         packageId = null;
215         activities = null;
216         lodgingId = null;
217         origin = null;
218         headCount = 0;
219         lodgingDays = 0;
220         lodgingRoomCount = 0;
221         adventureDays = 0;
222         returnFlight = null;
223         departureFlight = null;
224         departureDate = null;
225         configurationComplete = false;
226     }
227 }
228
Popular Tags