1
19
20 package com.liferay.portlet.shopping.model.impl;
21
22 import com.liferay.portal.kernel.util.StringUtil;
23 import com.liferay.portal.kernel.util.Validator;
24 import com.liferay.portlet.shopping.model.ShoppingCartItem;
25 import com.liferay.portlet.shopping.model.ShoppingItem;
26
27
33 public class ShoppingCartItemImpl implements ShoppingCartItem {
34
35 public static String[] getFieldsArray(String fields) {
36 return StringUtil.split(fields, "&");
37 }
38
39 public ShoppingCartItemImpl(ShoppingItem item, String fields) {
40 _item = item;
41 _fields = fields;
42 }
43
44 public String getCartItemId() {
45 long itemId = getItem().getItemId();
46
47 if (Validator.isNull(_fields)) {
48 return String.valueOf(itemId);
49 }
50 else {
51 return itemId + "|" + _fields;
52 }
53 }
54
55 public ShoppingItem getItem() {
56 return _item;
57 }
58
59 public String getFields() {
60 return _fields;
61 }
62
63 public String[] getFieldsArray() {
64 return getFieldsArray(_fields);
65 }
66
67 public int compareTo(ShoppingCartItem cartItem) {
68 if (cartItem == null) {
69 return -1;
70 }
71
72 int value = getItem().compareTo(cartItem.getItem());
73
74 if (value == 0) {
75 value = getFields().compareTo(cartItem.getFields());
76 }
77
78 return value;
79 }
80
81 public boolean equals(Object obj) {
82 if (obj == null) {
83 return false;
84 }
85
86 ShoppingCartItem cartItem = (ShoppingCartItem)obj;
87
88 if (getItem().equals(cartItem.getItem()) &&
89 getFields().equals(cartItem.getFields())) {
90
91 return true;
92 }
93 else {
94 return false;
95 }
96 }
97
98 private ShoppingItem _item;
99 private String _fields;
100
101 }