1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.kernel.util;
16  
17  import java.io.Serializable;
18  
19  /**
20   * <a href="Tuple.java.html"><b><i>View Source</i></b></a>
21   *
22   * @author Alexander Chow
23   */
24  public class Tuple implements Serializable {
25  
26      public Tuple(Object... array) {
27          _array = array;
28      }
29  
30      public Object getObject(int i) {
31          return _array[i];
32      }
33  
34      public boolean equals(Object obj) {
35          if (!(obj instanceof Tuple)) {
36              return false;
37          }
38  
39          Tuple tuple = (Tuple)obj;
40  
41          if (tuple._array.length != _array.length) {
42              return false;
43          }
44  
45          for (int i = 0; i < _array.length; i++) {
46              if ((tuple._array != null) && (_array[i] != null) &&
47                  (!_array[i].equals(tuple._array[i]))) {
48  
49                  return false;
50              }
51              else if ((tuple._array[i] == null) || (_array[i] == null)) {
52                  return false;
53              }
54          }
55  
56          return true;
57      }
58  
59      public int hashCode() {
60          int hashCode = 0;
61  
62          for (int i = 0; i < _array.length; i++) {
63              hashCode = hashCode ^ _array[i].hashCode();
64          }
65  
66          return hashCode;
67      }
68  
69      private Object[] _array;
70  
71  }