package com.alexrnl.commons.utils.object;

import java.util.Arrays;
import java.util.Objects;

/**
 * Utility methods for computing {@link Object}'s {@link Object#hashCode() hash code}.
 * @author Alex
 */
public final class HashCodeUtils {
	
	/** Default prime number to use for hash code computation */
	public static final int		PRIME_FOR_HASHCODE		= 31;
	
	/**
	 * Constructor #1.<br />
	 * Default private constructor.
	 */
	private HashCodeUtils () {
		super();
	}
	
	/**
	 * Compute the hash code of the list of objects provided.<br />
	 * @param attributes
	 *        the list of attributes.
	 * @param nullValue
	 *        the value to use when the attribute is <code>null</code>.
	 * @param prime
	 *        the prime value to use for the hash code.
	 * @return the hash code for the given set of attributes.
	 */
	public static int hashCode (final int nullValue, final int prime, final Iterable<Object> attributes) {
		int result = 1;
		for (final Object object : attributes) {
			result = prime * result + Objects.hashCode(object);
		}
		return result;
	}
	
	/**
	 * Compute the hash code of the list of objects provided.<br />
	 * @param attributes
	 *        the list of attributes.
	 * @param nullValue
	 *        the value to use when the attribute is <code>null</code>.
	 * @param prime
	 *        the prime value to use for the hash code.
	 * @return the hash code for the given set of attributes.
	 * @see #hashCode(int, int, Iterable)
	 */
	public static int hashCode (final int nullValue, final int prime, final Object[] attributes) {
		return hashCode(nullValue, prime, Arrays.asList(attributes));
	}
	
	/**
	 * Compute the hash code of the list of objects provided.<br />
	 * @param attributes
	 *        the list of attributes.
	 * @param nullValue
	 *        the value to use when the attribute is <code>null</code>.
	 * @return the hash code for the given set of attributes.
	 * @see #hashCode(int, int, Iterable)
	 */
	public static int hashCode (final int nullValue, final Iterable<Object> attributes) {
		return hashCode(nullValue, PRIME_FOR_HASHCODE, attributes);
	}
	
	/**
	 * Compute the hash code of the list of objects provided.<br />
	 * @param attributes
	 *        the list of attributes.
	 * @param nullValue
	 *        the value to use when the attribute is <code>null</code>.
	 * @return the hash code for the given set of attributes.
	 * @see #hashCode(int, int, Iterable)
	 */
	public static int hashCode (final int nullValue, final Object[] attributes) {
		return hashCode(nullValue, Arrays.asList(attributes));
	}
	
	/**
	 * Compute the hash code of the list of objects provided.<br />
	 * @param attributes
	 *        the list of attributes.
	 * @return the hash code for the given set of attributes.
	 * @see #hashCode(int, int, Iterable)
	 */
	public static int hashCode (final Iterable<Object> attributes) {
		return hashCode(0, attributes);
	}
	
	/**
	 * Compute the hash code of the list of objects provided.<br />
	 * @param attributes
	 *        the list of attributes.
	 * @return the hash code for the given set of attributes.
	 * @see #hashCode(int, int, Iterable)
	 */
	public static int hashCode (final Object[] attributes) {
		return hashCode(Arrays.asList(attributes));
	}
}

@@ -596,98 +596,8 @@
 es.%0A
-%09 * @param nullValue%0A%09 *        the value to use when the attribute is %3Ccode%3Enull%3C/code%3E.%0A
 %09 * 
@@ -765,37 +765,16 @@
 nal int 
-nullValue, final int 
 prime, f
@@ -827,16 +827,37 @@
 lt = 1;%0A
+%09%09int iteration = 1;%0A
 %09%09for (f
@@ -902,16 +902,30 @@
 result =
+ iteration++ *
  prime *
@@ -1117,98 +1117,8 @@
 es.%0A
-%09 * @param nullValue%0A%09 *        the value to use when the attribute is %3Ccode%3Enull%3C/code%3E.%0A
 %09 * 
@@ -1257,37 +1257,32 @@
 e #hashCode(int,
- int,
  Iterable)%0A%09 */%0A
@@ -1324,29 +1324,8 @@
 int 
-nullValue, final int 
 prim
@@ -1378,958 +1378,12 @@
 ode(
-nullValue, prime, Arrays.asList(attributes));%0A%09%7D%0A%09%0A%09/**%0A%09 * Compute the hash code of the list of objects provided.%3Cbr /%3E%0A%09 * @param attributes%0A%09 *        the list of attributes.%0A%09 * @param nullValue%0A%09 *        the value to use when the attribute is %3Ccode%3Enull%3C/code%3E.%0A%09 * @return the hash code for the given set of attributes.%0A%09 * @see #hashCode(int, int, Iterable)%0A%09 */%0A%09public static int hashCode (final int nullValue, final Iterable%3CObject%3E attributes) %7B%0A%09%09return hashCode(nullValue, PRIME_FOR_HASHCODE, attributes);%0A%09%7D%0A%09%0A%09/**%0A%09 * Compute the hash code of the list of objects provided.%3Cbr /%3E%0A%09 * @param attributes%0A%09 *        the list of attributes.%0A%09 * @param nullValue%0A%09 *        the value to use when the attribute is %3Ccode%3Enull%3C/code%3E.%0A%09 * @return the hash code for the given set of attributes.%0A%09 * @see #hashCode(int, int, Iterable)%0A%09 */%0A%09public static int hashCode (final int nullValue, final Object%5B%5D attributes) %7B%0A%09%09return hashCode(nullValu
+prim
 e, A
@@ -1615,37 +1615,32 @@
 e #hashCode(int,
- int,
  Iterable)%0A%09 */%0A
@@ -1727,9 +1727,26 @@
 ode(
-0
+PRIME_FOR_HASHCODE
 , at
@@ -1974,13 +1974,8 @@
 int,
- int,
  Ite
@@ -2093,10 +2093,12 @@
 s));%0A%09%7D%0A
+%09%0A
 %7D%0A

Remove nullValue parameter from the HashCodeUtils methods