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