Java Hash Code Calculate combinedHashCode(Object... objects)

Here you can find the source of combinedHashCode(Object... objects)

Description

Combines hash codes from multiple objects to make a new one.

License

Open Source License

Declaration

public static int combinedHashCode(Object... objects) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 Bruno Medeiros and other Contributors.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from  w w w . ja  va 2 s  .  c  o  m*/
 *     Bruno Medeiros - initial API and implementation
 *******************************************************************************/

public class Main {
    /** Combines hash codes from multiple objects to make a new one. Each object in the array can be null. */
    public static int combinedHashCode(Object... objects) {
        final int prime = 31;
        int result = 1;
        for (Object obj : objects) {
            result = prime * result + getHashCode(obj);
        }
        return result;
    }

    /** Helper to get the hashcode for a member object. */
    public static int getHashCode(Object member) {
        return member == null ? 0 : member.hashCode();
    }
}

Related

  1. combineHashCodes(final int pHashCode_1, final int pHashCode_2)
  2. combineHashCodes(int hashCode1, int hashCode2)
  3. combineHashCodes(int hashCode1, int hashCode2)
  4. combineHashCodes(int numA, int numB, int numC)