/*
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License");  you may not use this file except in 
 * compliance with the License.  You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 *
 * The Original Code is Protege-2000.
 *
 * The Initial Developer of the Original Code is Stanford University. Portions
 * created by Stanford University are Copyright (C) 2007.  All Rights Reserved.
 *
 * Protege was developed by Stanford Medical Informatics
 * (http://www.smi.stanford.edu) at the Stanford University School of Medicine
 * with support from the National Library of Medicine, the National Science
 * Foundation, and the Defense Advanced Research Projects Agency.  Current
 * information about Protege can be obtained at http://protege.stanford.edu.
 *
 */

package edu.stanford.smi.protege.util;

/**
 * @author Ray Fergerson
 *
 * Description of this class
 */
public final class HashUtils {
    private static final int MULTIPLIER = 37;

    public static int getHash(Object o1, Object o2) {
        int hash = hash(o1);
        hash = combine(hash, hash(o2));
        return hash;
    }
    
    public static int getHash(int i1, int i2) {
      int hash = combine(i1, i2);
      return hash;
    }

    public static int getHash(Object o1, Object[] oArray) {
        int hash = hash(o1);
        hash = combine(hash, hash(oArray));
        return hash;
    }

    public static int getHash(Object o1, Object o2, boolean b) {
        int hash = hash(o1);
        hash = combine(hash, hash(o2));
        hash = combine(hash, hash(b));
        return hash;
    }

    public static int getHash(Object o1, Object o2, Object o3) {
        int hash = hash(o1);
        hash = combine(hash, hash(o2));
        hash = combine(hash, hash(o3));
        return hash;
    }

    public static int getHash(Object o1, Object o2, Object o3, boolean b) {
        int hash = hash(o1);
        hash = combine(hash, hash(o2));
        hash = combine(hash, hash(o3));
        hash = combine(hash, hash(b));
        return hash;
    }

    private static int combine(int hash1, int hash2) {
        return MULTIPLIER * hash1 + hash2;
    }

    private static int hash(Object o1) {
        return (o1 == null) ? 0 : o1.hashCode();
    }

    private static int hash(boolean b) {
        return b ? 1 : 104729;
    }

    private static int hash(Object[] array) {
        int hash = 0;
        for (int i = 0; i < array.length; ++i) {
            Object o = array[i];
            hash = combine(hash, hash(o));
        }
        return hash;
    }
}
