Java Object Hash makeHashCode(Object... objects)

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

Description

This belongs in a utility class.

License

LGPL

Parameter

Parameter Description
objects a parameter

Declaration

public static int makeHashCode(Object... objects) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.util.*;

public class Main {
    /**//from   w  w  w .  java 2 s .  c  o  m
     * This belongs in a utility class. Takes field values of an instance to generate a hash code
     *
     * @param objects
     * @return
     */
    public static int makeHashCode(Object... objects) {
        return makeHashCode(Arrays.asList(objects));
    }

    public static int makeHashCode(Collection<?> collection) {
        String result = "";
        for (Object object : collection)
            if (object != null)
                result += (object instanceof Collection ? new HashSet<Object>((Collection<?>) object).hashCode()
                        : object.hashCode());
        return result.hashCode();
    }
}

Related

  1. hashCode(Object obj)
  2. hashCode(Object obj)
  3. hashCode(Object object)
  4. hashCode(Object... args)
  5. hashCode(Object... objects)
  6. safeHashCode(Object o)
  7. safeHashCode(Object... objects)