/*
 * @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;
import java.util.Comparator;

/**
 * Generalization of Comparator interface.
 * Offers equality, comparison and hash methods for objects of type T.
 * Essentially it represents complete comparison strategy usable by any container.
 *
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 * @param <T>
 */
public interface HashComparator<T> extends HashFunction<T>, Comparator<T>, Serializable {

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

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

        };
    }
    
}
