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

import java.io.Serializable;
import java.util.Comparator;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 * @param <Q>
 */
public interface HashComparator<Q> extends HashFunction<Q>, Comparator<Q>, Serializable {

    @Override
    default boolean equals(Q a, Q b) {
        return 0 == compare(a, b);
    }
    
    @Override
    default HashComparator<Q> reversed() {
        HashComparator<Q> that = this;
        return new HashComparator<Q>() {
            @Override
            public int compare(Q a, Q b) {
                return that.compare(b, a);
            }

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

        };
    }
    
}
