/* // $Id: //guest/julian_hyde/saffron/src/main/openjava/ptree/util/HashableArray.java#2 $ // Saffron preprocessor and data engine // Copyright (C) 2002 Julian Hyde <julian.hyde@mail.com> // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public // License as published by the Free Software Foundation; either // version 2 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Library General Public License for more details. // // You should have received a copy of the GNU Library General Public // License along with this library; if not, write to the // Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. // // See the COPYING file located in the top-level-directory of // the archive of this library for complete text of license. */ package openjava.ptree.util; /** * <code>HashableArray</code> provides a <code>Object[]</code> with a {@link * #hashCode} and an {@link #equals} function, so it can be used as a key in a * {@link java.util.Hashtable}. */ class HashableArray { Object[] a; HashableArray(Object[] a) { this.a = a; } // override Object public int hashCode() { return arrayHashCode(a); } // override Object public boolean equals(Object o) { return o instanceof HashableArray && arraysAreEqual(this.a, ((HashableArray) o).a); } static int arrayHashCode(Object[] a) { // hash algorithm borrowed from java.lang.String int h = 0; for (int i = 0; i < a.length; i++) { h = 31 * h + a[i].hashCode(); } return h; } /** Return whether two arrays are equal (shallow compare). */ static boolean arraysAreEqual(Object[] a1, Object[] a2) { if (a1.length != a2.length) { return false; } for (int i = 0; i < a1.length; i++) { // we don't need to use 'equals', cuz synthetic classes are always // made of real classes if (!a1[i].equals(a2[i])) { return false; } } return true; } }; // End HashableArray.java
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 1474 | Julian Hyde |
saffron: Aggregations are working. Renamed 'aggregator' to 'aggregation'. |
||
#1 | 1467 | Julian Hyde |
saffron: First saffron check-in; incorporate my changes to openjava. |