package net.ranides.assira.collection;

import lombok.experimental.UtilityClass;

import java.util.Arrays;

/**
 * Default hash strategies for common types.
 */
@UtilityClass
public class HashFunctions {

    /**
     * Hash for Object[]
     */
    public static final HashFunction<Object[]> OBJECT_ARRAY = new HashFunction<Object[]>() {
        @Override
        public int hashCode(Object[] object) {
            return Arrays.hashCode(object);
        }

        @Override
        public boolean equals(Object[] a, Object[] b) {
            return Arrays.equals(a, b);
        }
    };

    /**
     * Hash for byte[]
     */
    public static final HashFunction<byte[]> BYTE_ARRAY = new HashFunction<byte[]>() {
        @Override
        public int hashCode(byte[] object) {
            return Arrays.hashCode(object);
        }

        @Override
        public boolean equals(byte[] a, byte[] b) {
            return Arrays.equals(a, b);
        }
    };

    /**
     * Hash for short[]
     */
    public static final HashFunction<short[]> SHORT_ARRAY = new HashFunction<short[]>() {
        @Override
        public int hashCode(short[] object) {
            return Arrays.hashCode(object);
        }

        @Override
        public boolean equals(short[] a, short[] b) {
            return Arrays.equals(a, b);
        }
    };

    /**
     * Hash for int[]
     */
    public static final HashFunction<int[]> INTEGER_ARRAY = new HashFunction<int[]>() {
        @Override
        public int hashCode(int[] object) {
            return Arrays.hashCode(object);
        }

        @Override
        public boolean equals(int[] a, int[] b) {
            return Arrays.equals(a, b);
        }
    };

    /**
     * Hash for long[]
     */
    public static final HashFunction<long[]> LONG_ARRAY = new HashFunction<long[]>() {
        @Override
        public int hashCode(long[] object) {
            return Arrays.hashCode(object);
        }

        @Override
        public boolean equals(long[] a, long[] b) {
            return Arrays.equals(a, b);
        }
    };

    /**
     * Hash for float[]
     */
    public static final HashFunction<float[]> FLOAT_ARRAY = new HashFunction<float[]>() {
        @Override
        public int hashCode(float[] object) {
            return Arrays.hashCode(object);
        }

        @Override
        public boolean equals(float[] a, float[] b) {
            return Arrays.equals(a, b);
        }
    };

    /**
     * Hash for double[]
     */
    public static final HashFunction<double[]> DOUBLE_ARRAY = new HashFunction<double[]>() {
        @Override
        public int hashCode(double[] object) {
            return Arrays.hashCode(object);
        }

        @Override
        public boolean equals(double[] a, double[] b) {
            return Arrays.equals(a, b);
        }
    };

    /**
     * Hash for char[]
     */
    public static final HashFunction<char[]> CHARACTER_ARRAY = new HashFunction<char[]>() {
        @Override
        public int hashCode(char[] object) {
            return Arrays.hashCode(object);
        }

        @Override
        public boolean equals(char[] a, char[] b) {
            return Arrays.equals(a, b);
        }
    };

    /**
     * Hash for boolean[]
     */
    public static final HashFunction<boolean[]> BOOLEAN_ARRAY = new HashFunction<boolean[]>() {
        @Override
        public int hashCode(boolean[] object) {
            return Arrays.hashCode(object);
        }

        @Override
        public boolean equals(boolean[] a, boolean[] b) {
            return Arrays.equals(a, b);
        }
    };

}
