001    /**
002     * Copyright (c) 2000-2013 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 (this == obj) {
031                            return true;
032                    }
033    
034                    if (!(obj instanceof Tuple)) {
035                            return false;
036                    }
037    
038                    Tuple tuple = (Tuple)obj;
039    
040                    if (tuple._array.length != _array.length) {
041                            return false;
042                    }
043    
044                    for (int i = 0; i < _array.length; i++) {
045                            if ((tuple._array != null) && (_array[i] != null) &&
046                                    !_array[i].equals(tuple._array[i])) {
047    
048                                    return false;
049                            }
050                            else if ((tuple._array[i] == null) || (_array[i] == null)) {
051                                    return false;
052                            }
053                    }
054    
055                    return true;
056            }
057    
058            public Object getObject(int i) {
059                    return _array[i];
060            }
061    
062            public int getSize() {
063                    return _array.length;
064            }
065    
066            @Override
067            public int hashCode() {
068                    int hashCode = 0;
069    
070                    for (int i = 0; i < _array.length; i++) {
071                            hashCode = hashCode ^ _array[i].hashCode();
072                    }
073    
074                    return hashCode;
075            }
076    
077            private Object[] _array;
078    
079    }