Java Array Hash Code hashCode(String[] names, Object[] values)

Here you can find the source of hashCode(String[] names, Object[] values)

Description

Computes a descriptor hashcode from its names and values.

License

Open Source License

Parameter

Parameter Description
names the sorted array of descriptor names.
values the array of descriptor values.

Return

a hash code value, as described in

Declaration

public static int hashCode(String[] names, Object[] values) 

Method Source Code

//package com.java2s;
/*/* www . j  av a 2 s. c  o m*/
 * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */

import java.util.Arrays;

public class Main {
    /**
     * Computes a descriptor hashcode from its names and values.
     * @param names  the sorted array of descriptor names.
     * @param values the array of descriptor values.
     * @return a hash code value, as described in {@link #hashCode(Descriptor)}
     */
    public static int hashCode(String[] names, Object[] values) {
        int hash = 0;
        for (int i = 0; i < names.length; i++) {
            Object v = values[i];
            int h;
            if (v == null) {
                h = 0;
            } else if (v instanceof Object[]) {
                h = Arrays.deepHashCode((Object[]) v);
            } else if (v.getClass().isArray()) {
                h = Arrays.deepHashCode(new Object[] { v }) - 31;
                // hashcode of a list containing just v is
                // v.hashCode() + 31, see List.hashCode()
            } else {
                h = v.hashCode();
            }
            hash += names[i].toLowerCase().hashCode() ^ h;
        }
        return hash;
    }
}

Related

  1. hashCode(byte[] obj)
  2. hashCode(final Object[] array1)
  3. hashCode(Map a)
  4. hashCode(Object array)
  5. hashCode(Object array)
  6. printArray(byte[] array, boolean withHash)