1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
15 package org.simantics.utils.datastructures;
\r
17 import java.util.Arrays;
\r
20 * Deep comparable array object.
\r
22 * @author Toni Kalajainen
\r
24 public final class Array<T> {
\r
26 private final T[] array;
\r
27 private final int hashCode;
\r
29 public Array(T[] array)
\r
31 this.array = array.clone();
\r
32 this.hashCode = makeHashCode(this.array);
\r
35 private static <T> int makeHashCode(T[] array) {
\r
37 for (int i=0; i<array.length; i++)
\r
39 if (array[i]==null) continue;
\r
40 hash = (31*hash) ^ array[i].hashCode();
\r
45 public T[] toArray()
\r
47 return array.clone();
\r
51 public int hashCode() {
\r
56 public boolean equals(Object obj) {
\r
57 if (obj==this) return true;
\r
58 if (!obj.getClass().equals(getClass()))
\r
60 return Arrays.equals(array, ((Array<?>)obj).array);
\r
64 return array.length;
\r