001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.util;
016    
017    import java.io.Serializable;
018    
019    /**
020     * @author Alexander Chow
021     */
022    public class Tuple implements Serializable {
023    
024            public Tuple(Object... array) {
025                    _array = array;
026            }
027    
028            @Override
029            public boolean equals(Object obj) {
030                    if (!(obj instanceof Tuple)) {
031                            return false;
032                    }
033    
034                    Tuple tuple = (Tuple)obj;
035    
036                    if (tuple._array.length != _array.length) {
037                            return false;
038                    }
039    
040                    for (int i = 0; i < _array.length; i++) {
041                            if ((tuple._array != null) && (_array[i] != null) &&
042                                    (!_array[i].equals(tuple._array[i]))) {
043    
044                                    return false;
045                            }
046                            else if ((tuple._array[i] == null) || (_array[i] == null)) {
047                                    return false;
048                            }
049                    }
050    
051                    return true;
052            }
053    
054            public Object getObject(int i) {
055                    return _array[i];
056            }
057    
058            @Override
059            public int hashCode() {
060                    int hashCode = 0;
061    
062                    for (int i = 0; i < _array.length; i++) {
063                            hashCode = hashCode ^ _array[i].hashCode();
064                    }
065    
066                    return hashCode;
067            }
068    
069            private Object[] _array;
070    
071    }