/*
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.collection;

import java.io.Serializable;

/**
 * Generalization of IntComparator interface.
 * Offers equality, comparison and hash methods for int values.
 * Essentially it represents complete comparison strategy usable by any container.
 *
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 */
public interface HashIntComparator extends HashComparator<Integer>, IntComparator, Serializable {

    /**
     * Calculates hashCode for specified object
     *
     * @param object object
     * @return int
     */
    int hashCode(int object);
        
    @Override
    default int hashCode(Integer object) {
        return hashCode(object.intValue());
    }
    
    @Override
    default boolean equals(Integer a, Integer b) {
        return 0 == compare(a, b);
    }
    
    @Override
    default HashIntComparator reversed() {
        HashIntComparator that = this;
        return new HashIntComparator() {
            @Override
            public int compare(int a, int b) {
                return that.compare(b, a);
            }

            @Override
            public int hashCode(int object) {
                return that.hashCode(object);
            }

        };
    }
    
}
