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 obj0, Object obj1) {
27          _array = new Object[] {obj0, obj1};
28      }
29  
30      public Tuple(Object obj0, Object obj1, Object obj2) {
31          _array = new Object[] {obj0, obj1, obj2};
32      }
33  
34      public Tuple(Object obj0, Object obj1, Object obj2, Object obj3) {
35          _array = new Object[] {obj0, obj1, obj2, obj3};
36      }
37  
38      public Tuple(Object[] array) {
39          _array = array;
40      }
41  
42      public Object getObject(int i) {
43          return _array[i];
44      }
45  
46      public boolean equals(Object obj) {
47          if (!(obj instanceof Tuple)) {
48              return false;
49          }
50  
51          Tuple tuple = (Tuple)obj;
52  
53          if (tuple._array.length != _array.length) {
54              return false;
55          }
56  
57          for (int i = 0; i < _array.length; i++) {
58              if ((tuple._array != null) && (_array[i] != null) &&
59                  (!_array[i].equals(tuple._array[i]))) {
60  
61                  return false;
62              }
63              else if ((tuple._array[i] == null) || (_array[i] == null)) {
64                  return false;
65              }
66          }
67  
68          return true;
69      }
70  
71      public int hashCode() {
72          int hashCode = 0;
73  
74          for (int i = 0; i < _array.length; i++) {
75              hashCode = hashCode ^ _array[i].hashCode();
76          }
77  
78          return hashCode;
79      }
80  
81      private Object[] _array;
82  
83  }