1 package xpetstore.services.cart.model; 2 3 import java.io.Serializable ; 4 5 import java.util.Comparator ; 6 7 8 11 public class CartItem 12 implements Serializable 13 { 14 16 private String itemId; 17 private String productId; 18 private String name; 19 private String description; 20 private int quantity; 21 private double unitCost; 22 23 25 public CartItem( String itemId, 26 String productId, 27 String name, 28 String 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 42 public String getItemId( ) 43 { 44 return itemId; 45 } 46 47 public String getProductId( ) 48 { 49 return productId; 50 } 51 52 public String getName( ) 53 { 54 return name; 55 } 56 57 public String 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 79 public static class ItemIdComparator 80 implements Comparator 81 { 82 84 public int compare( Object o1, 85 Object 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 |