KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xpetstore > services > cart > model > CartItem


1 package xpetstore.services.cart.model;
2
3 import java.io.Serializable JavaDoc;
4
5 import java.util.Comparator JavaDoc;
6
7
8 /**
9  * @author <a HREF="mailto:tchbansi@sourceforge.net">Herve Tchepannou</a>
10  */

11 public class CartItem
12     implements Serializable JavaDoc
13 {
14     //~ Instance fields --------------------------------------------------------
15

16     private String JavaDoc itemId;
17     private String JavaDoc productId;
18     private String JavaDoc name;
19     private String JavaDoc description;
20     private int quantity;
21     private double unitCost;
22
23     //~ Constructors -----------------------------------------------------------
24

25     public CartItem( String JavaDoc itemId,
26                      String JavaDoc productId,
27                      String JavaDoc name,
28                      String JavaDoc description,
29                      int quantity,
30                      double unitCost )
31     {
32         this.itemId = itemId;
33         this.productId = productId;
34         this.name = name;
35         this.description = description;
36         this.quantity = quantity;
37         this.unitCost = unitCost;
38     }
39
40     //~ Methods ----------------------------------------------------------------
41

42     public String JavaDoc getItemId( )
43     {
44         return itemId;
45     }
46
47     public String JavaDoc getProductId( )
48     {
49         return productId;
50     }
51
52     public String JavaDoc getName( )
53     {
54         return name;
55     }
56
57     public String JavaDoc getDescription( )
58     {
59         return description;
60     }
61
62     public int getQuantity( )
63     {
64         return quantity;
65     }
66
67     public double getUnitCost( )
68     {
69         return unitCost;
70     }
71
72     public double getTotalCost( )
73     {
74         return quantity * unitCost;
75     }
76
77     //~ Inner Classes ----------------------------------------------------------
78

79     public static class ItemIdComparator
80         implements Comparator JavaDoc
81     {
82         //~ Methods ------------------------------------------------------------
83

84         public int compare( Object JavaDoc o1,
85                             Object JavaDoc o2 )
86         {
87             if ( ( o1 instanceof CartItem ) && ( o2 instanceof CartItem ) )
88             {
89                 return ( ( CartItem ) o1 ).getItemId( ).compareTo( ( ( CartItem ) o2 ).getItemId( ) );
90             }
91             else
92             {
93                 return 0;
94             }
95         }
96     }
97 }
98
Popular Tags