001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.shopping.model.impl;
022:
023: import com.liferay.portal.kernel.util.StringUtil;
024: import com.liferay.portal.kernel.util.Validator;
025: import com.liferay.portlet.shopping.model.ShoppingCartItem;
026: import com.liferay.portlet.shopping.model.ShoppingItem;
027:
028: /**
029: * <a href="ShoppingCartItemImpl.java.html"><b><i>View Source</i></b></a>
030: *
031: * @author Brian Wing Shun Chan
032: *
033: */
034: public class ShoppingCartItemImpl implements ShoppingCartItem {
035:
036: public static String[] getFieldsArray(String fields) {
037: return StringUtil.split(fields, "&");
038: }
039:
040: public ShoppingCartItemImpl(ShoppingItem item, String fields) {
041: _item = item;
042: _fields = fields;
043: }
044:
045: public String getCartItemId() {
046: long itemId = getItem().getItemId();
047:
048: if (Validator.isNull(_fields)) {
049: return String.valueOf(itemId);
050: } else {
051: return itemId + "|" + _fields;
052: }
053: }
054:
055: public ShoppingItem getItem() {
056: return _item;
057: }
058:
059: public String getFields() {
060: return _fields;
061: }
062:
063: public String[] getFieldsArray() {
064: return getFieldsArray(_fields);
065: }
066:
067: public int compareTo(Object obj) {
068: if (obj == null) {
069: return -1;
070: }
071:
072: ShoppingCartItem cartItem = (ShoppingCartItem) obj;
073:
074: int value = getItem().compareTo(cartItem.getItem());
075:
076: if (value == 0) {
077: value = getFields().compareTo(cartItem.getFields());
078: }
079:
080: return value;
081: }
082:
083: public boolean equals(Object obj) {
084: if (obj == null) {
085: return false;
086: }
087:
088: ShoppingCartItem cartItem = (ShoppingCartItem) obj;
089:
090: if (getItem().equals(cartItem.getItem())
091: && getFields().equals(cartItem.getFields())) {
092:
093: return true;
094: } else {
095: return false;
096: }
097: }
098:
099: private ShoppingItem _item;
100: private String _fields;
101:
102: }
|