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