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